buildRustCrate: name tests/<dir>/main.rs binaries as <dir> to match cargo (#502733)
This commit is contained in:
@@ -87,6 +87,12 @@ build_bin_test_file() {
|
||||
# above.
|
||||
derived_crate_name=${derived_crate_name#"tests_"}
|
||||
derived_crate_name="${derived_crate_name%.rs}"
|
||||
# Cargo names tests/<dir>/main.rs as <dir>, not <dir>_main — strip the
|
||||
# trailing _main that the `/`→`_` substitution produced. Guarded so
|
||||
# a flat-style tests/<name>_main.rs keeps its _main suffix.
|
||||
if [[ "$file" == */main.rs ]]; then
|
||||
derived_crate_name="${derived_crate_name%_main}"
|
||||
fi
|
||||
build_bin_test "$derived_crate_name" "$file"
|
||||
}
|
||||
|
||||
|
||||
@@ -91,9 +91,15 @@ let
|
||||
mkTest =
|
||||
crateArgs:
|
||||
let
|
||||
crate = mkHostCrate (removeAttrs crateArgs [ "expectedTestOutput" ]);
|
||||
crate = mkHostCrate (
|
||||
removeAttrs crateArgs [
|
||||
"expectedTestOutputs"
|
||||
"expectedTestBinaries"
|
||||
]
|
||||
);
|
||||
hasTests = crateArgs.buildTests or false;
|
||||
expectedTestOutputs = crateArgs.expectedTestOutputs or null;
|
||||
expectedTestBinaries = crateArgs.expectedTestBinaries or [ ];
|
||||
binaries = map (v: lib.escapeShellArg v.name) (crateArgs.crateBin or [ ]);
|
||||
isLib = crateArgs ? libName || crateArgs ? libPath;
|
||||
crateName = crateArgs.crateName or "nixtestcrate";
|
||||
@@ -134,6 +140,10 @@ let
|
||||
''
|
||||
else if stdenv.hostPlatform == stdenv.buildPlatform then
|
||||
''
|
||||
${lib.concatMapStringsSep "\n" (
|
||||
b:
|
||||
"test -x ${crate}/tests/${lib.escapeShellArg b} || { echo 'expected test binary \"${b}\" not found in:'; ls ${crate}/tests; exit 23; }"
|
||||
) expectedTestBinaries}
|
||||
for file in ${crate}/tests/*; do
|
||||
$file 2>&1 >> $out
|
||||
done
|
||||
@@ -419,12 +429,34 @@ rec {
|
||||
];
|
||||
};
|
||||
buildTests = true;
|
||||
# Cargo names tests/<dir>/main.rs as <dir>, not <dir>_main.
|
||||
expectedTestBinaries = [
|
||||
"foo"
|
||||
"bar"
|
||||
];
|
||||
expectedTestOutputs = [
|
||||
"test src_main ... ok"
|
||||
"test tests_foo ... ok"
|
||||
"test tests_bar ... ok"
|
||||
];
|
||||
};
|
||||
rustBinTestsFlatMainSuffix = {
|
||||
# A flat-style test whose name happens to end in _main must keep
|
||||
# its suffix — only tests/<dir>/main.rs gets the _main stripped.
|
||||
src = symlinkJoin {
|
||||
name = "rust-bin-tests-flat-main-suffix";
|
||||
paths = [
|
||||
(mkTestFileWithMain "src/main.rs" "src_main")
|
||||
(mkTestFile "tests/foo_main.rs" "flat_test")
|
||||
];
|
||||
};
|
||||
buildTests = true;
|
||||
expectedTestBinaries = [ "foo_main" ];
|
||||
expectedTestOutputs = [
|
||||
"test src_main ... ok"
|
||||
"test flat_test ... ok"
|
||||
];
|
||||
};
|
||||
linkAgainstRlibCrate = {
|
||||
crateName = "foo";
|
||||
src = mkFile "src/main.rs" ''
|
||||
|
||||
Reference in New Issue
Block a user