|
|
|
@ -1,13 +1,14 @@ |
|
|
|
|
{ lib |
|
|
|
|
, stdenv |
|
|
|
|
, buildRustCrate |
|
|
|
|
, callPackage |
|
|
|
|
, releaseTools |
|
|
|
|
, runCommand |
|
|
|
|
, runCommandCC |
|
|
|
|
, writeTextFile |
|
|
|
|
, stdenv |
|
|
|
|
, symlinkJoin |
|
|
|
|
, callPackage |
|
|
|
|
, releaseTools |
|
|
|
|
, writeTextFile |
|
|
|
|
}: |
|
|
|
|
|
|
|
|
|
let |
|
|
|
|
mkCrate = args: let |
|
|
|
|
p = { |
|
|
|
@ -103,6 +104,58 @@ let |
|
|
|
|
'' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/* Returns a derivation that asserts that the crate specified by `crateArgs` |
|
|
|
|
has the specified files as output. |
|
|
|
|
|
|
|
|
|
`name` is used as part of the derivation name that performs the checking. |
|
|
|
|
|
|
|
|
|
`crateArgs` is passed to `mkCrate` to build the crate with `buildRustCrate`. |
|
|
|
|
|
|
|
|
|
`expectedFiles` contains a list of expected file paths in the output. E.g. |
|
|
|
|
`[ "./bin/my_binary" ]`. |
|
|
|
|
|
|
|
|
|
`output` specifies the name of the output to use. By default, the default |
|
|
|
|
output is used but e.g. `output = "lib";` will cause the lib output |
|
|
|
|
to be checked instead. You do not need to specify any directories. |
|
|
|
|
*/ |
|
|
|
|
assertOutputs = { name, crateArgs, expectedFiles, output? null }: |
|
|
|
|
assert (builtins.isString name); |
|
|
|
|
assert (builtins.isAttrs crateArgs); |
|
|
|
|
assert (builtins.isList expectedFiles); |
|
|
|
|
|
|
|
|
|
let |
|
|
|
|
crate = mkCrate (builtins.removeAttrs crateArgs ["expectedTestOutput"]); |
|
|
|
|
crateOutput = if output == null then crate else crate."${output}"; |
|
|
|
|
expectedFilesFile = writeTextFile { |
|
|
|
|
name = "expected-files-${name}"; |
|
|
|
|
text = |
|
|
|
|
let sorted = builtins.sort (a: b: a<b) expectedFiles; |
|
|
|
|
concatenated = builtins.concatStringsSep "\n" sorted; |
|
|
|
|
in "${concatenated}\n"; |
|
|
|
|
}; |
|
|
|
|
in |
|
|
|
|
runCommand "assert-outputs-${name}" { |
|
|
|
|
} '' |
|
|
|
|
local actualFiles=$(mktemp) |
|
|
|
|
|
|
|
|
|
cd "${crateOutput}" |
|
|
|
|
find . -type f | sort >$actualFiles |
|
|
|
|
diff -q ${expectedFilesFile} $actualFiles >/dev/null || { |
|
|
|
|
echo -e "\033[0;1;31mERROR: Difference in expected output files in ${crateOutput} \033[0m" >&2 |
|
|
|
|
echo === Got: |
|
|
|
|
sed -e 's/^/ /' $actualFiles |
|
|
|
|
echo === Expected: |
|
|
|
|
sed -e 's/^/ /' ${expectedFilesFile} |
|
|
|
|
echo === Diff: |
|
|
|
|
diff -u ${expectedFilesFile} $actualFiles |\ |
|
|
|
|
tail -n +3 |\ |
|
|
|
|
sed -e 's/^/ /' |
|
|
|
|
exit 1 |
|
|
|
|
} |
|
|
|
|
touch $out |
|
|
|
|
'' |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
in rec { |
|
|
|
|
|
|
|
|
|
tests = let |
|
|
|
@ -361,7 +414,80 @@ let |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
brotliCrates = (callPackage ./brotli-crates.nix {}); |
|
|
|
|
in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // { |
|
|
|
|
tests = lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases; |
|
|
|
|
in tests // rec { |
|
|
|
|
|
|
|
|
|
crateBinWithPathOutputs = assertOutputs { |
|
|
|
|
name="crateBinWithPath"; |
|
|
|
|
crateArgs = { |
|
|
|
|
crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; |
|
|
|
|
src = mkBin "src/foobar.rs"; |
|
|
|
|
}; |
|
|
|
|
expectedFiles = [ |
|
|
|
|
"./bin/test_binary1" |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
crateBinWithPathOutputsDebug = assertOutputs { |
|
|
|
|
name="crateBinWithPath"; |
|
|
|
|
crateArgs = { |
|
|
|
|
release = false; |
|
|
|
|
crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; |
|
|
|
|
src = mkBin "src/foobar.rs"; |
|
|
|
|
}; |
|
|
|
|
expectedFiles = [ |
|
|
|
|
"./bin/test_binary1" |
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [ |
|
|
|
|
# On Darwin, the debug symbols are in a seperate directory. |
|
|
|
|
"./bin/test_binary1.dSYM/Contents/Info.plist" |
|
|
|
|
"./bin/test_binary1.dSYM/Contents/Resources/DWARF/test_binary1" |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
crateBinNoPath1Outputs = assertOutputs { |
|
|
|
|
name="crateBinNoPath1"; |
|
|
|
|
crateArgs = { |
|
|
|
|
crateBin = [{ name = "my-binary2"; }]; |
|
|
|
|
src = mkBin "src/my_binary2.rs"; |
|
|
|
|
}; |
|
|
|
|
expectedFiles = [ |
|
|
|
|
"./bin/my-binary2" |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
crateLibOutputs = assertOutputs { |
|
|
|
|
name="crateLib"; |
|
|
|
|
output="lib"; |
|
|
|
|
crateArgs = { |
|
|
|
|
libName = "test_lib"; |
|
|
|
|
type = [ "rlib" ]; |
|
|
|
|
libPath = "src/lib.rs"; |
|
|
|
|
src = mkLib "src/lib.rs"; |
|
|
|
|
}; |
|
|
|
|
expectedFiles = [ |
|
|
|
|
"./nix-support/propagated-build-inputs" |
|
|
|
|
"./lib/libtest_lib-042a1fdbef.rlib" |
|
|
|
|
"./lib/link" |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
crateLibOutputsDebug = assertOutputs { |
|
|
|
|
name="crateLib"; |
|
|
|
|
output="lib"; |
|
|
|
|
crateArgs = { |
|
|
|
|
release = false; |
|
|
|
|
libName = "test_lib"; |
|
|
|
|
type = [ "rlib" ]; |
|
|
|
|
libPath = "src/lib.rs"; |
|
|
|
|
src = mkLib "src/lib.rs"; |
|
|
|
|
}; |
|
|
|
|
expectedFiles = [ |
|
|
|
|
"./nix-support/propagated-build-inputs" |
|
|
|
|
"./lib/libtest_lib-042a1fdbef.rlib" |
|
|
|
|
"./lib/link" |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
brotliTest = let |
|
|
|
|
pkg = brotliCrates.brotli_2_5_0 {}; |
|
|
|
|
in runCommand "run-brotli-test-cmd" { |
|
|
|
|