bats: reformat passthru.tests

Upcoming commit will add packages that use bats to passthru.tests,
which is a little more clear when this is one attrset.

Splitting this format-only change out for easier review.
This commit is contained in:
Travis A. Everett 2024-04-13 12:51:13 -05:00
parent e0f9929a69
commit bb0331762d
1 changed files with 62 additions and 60 deletions

View File

@ -134,78 +134,80 @@ resholve.mkDerivation rec {
'';
};
passthru.tests.libraries = runCommand "${bats.name}-with-libraries-test" {
testScript = ''
setup() {
bats_load_library bats-support
bats_load_library bats-assert
bats_load_library bats-file
bats_load_library bats-detik/detik.bash
passthru.tests = {
libraries = runCommand "${bats.name}-with-libraries-test" {
testScript = ''
setup() {
bats_load_library bats-support
bats_load_library bats-assert
bats_load_library bats-file
bats_load_library bats-detik/detik.bash
bats_require_minimum_version 1.5.0
bats_require_minimum_version 1.5.0
TEST_TEMP_DIR="$(temp_make --prefix 'nixpkgs-bats-test')"
}
TEST_TEMP_DIR="$(temp_make --prefix 'nixpkgs-bats-test')"
}
teardown() {
temp_del "$TEST_TEMP_DIR"
}
teardown() {
temp_del "$TEST_TEMP_DIR"
}
@test echo_hi {
run -0 echo hi
assert_output "hi"
}
@test echo_hi {
run -0 echo hi
assert_output "hi"
}
@test cp_failure {
run ! cp
assert_line --index 0 "cp: missing file operand"
assert_line --index 1 "Try 'cp --help' for more information."
}
@test cp_failure {
run ! cp
assert_line --index 0 "cp: missing file operand"
assert_line --index 1 "Try 'cp --help' for more information."
}
@test file_exists {
echo "hi" > "$TEST_TEMP_DIR/hello.txt"
assert_file_exist "$TEST_TEMP_DIR/hello.txt"
run cat "$TEST_TEMP_DIR/hello.txt"
assert_output "hi"
}
@test file_exists {
echo "hi" > "$TEST_TEMP_DIR/hello.txt"
assert_file_exist "$TEST_TEMP_DIR/hello.txt"
run cat "$TEST_TEMP_DIR/hello.txt"
assert_output "hi"
}
'';
passAsFile = [ "testScript" ];
} ''
${bats.withLibraries (p: [ p.bats-support p.bats-assert p.bats-file p.bats-detik ])}/bin/bats "$testScriptPath"
touch "$out"
'';
passAsFile = [ "testScript" ];
} ''
${bats.withLibraries (p: [ p.bats-support p.bats-assert p.bats-file p.bats-detik ])}/bin/bats "$testScriptPath"
touch "$out"
'';
passthru.tests.upstream = bats.unresholved.overrideAttrs (old: {
name = "${bats.name}-tests";
dontInstall = true; # just need the build directory
nativeInstallCheckInputs = [
ncurses
parallel # skips some tests if it can't detect
flock # skips some tests if it can't detect
procps
] ++ lib.optionals stdenv.isDarwin [ lsof ];
inherit doInstallCheck;
installCheckPhase = ''
# TODO: cut if https://github.com/bats-core/bats-core/issues/418 allows
sed -i '/test works even if PATH is reset/a skip "disabled for nix build"' test/bats.bats
upstream = bats.unresholved.overrideAttrs (old: {
name = "${bats.name}-tests";
dontInstall = true; # just need the build directory
nativeInstallCheckInputs = [
ncurses
parallel # skips some tests if it can't detect
flock # skips some tests if it can't detect
procps
] ++ lib.optionals stdenv.isDarwin [ lsof ];
inherit doInstallCheck;
installCheckPhase = ''
# TODO: cut if https://github.com/bats-core/bats-core/issues/418 allows
sed -i '/test works even if PATH is reset/a skip "disabled for nix build"' test/bats.bats
# skip tests that assume bats `install.sh` will be in BATS_ROOT
rm test/root.bats
# skip tests that assume bats `install.sh` will be in BATS_ROOT
rm test/root.bats
'' + (lib.optionalString stdenv.hostPlatform.isDarwin ''
# skip new timeout tests which are failing on macOS for unclear reasons
# This might relate to procps not having a pkill?
rm test/timeout.bats
'') + ''
'' + (lib.optionalString stdenv.hostPlatform.isDarwin ''
# skip new timeout tests which are failing on macOS for unclear reasons
# This might relate to procps not having a pkill?
rm test/timeout.bats
'') + ''
# test generates file with absolute shebang dynamically
substituteInPlace test/install.bats --replace \
"/usr/bin/env bash" "${bash}/bin/bash"
# test generates file with absolute shebang dynamically
substituteInPlace test/install.bats --replace \
"/usr/bin/env bash" "${bash}/bin/bash"
${bats}/bin/bats test
touch $out
'';
});
${bats}/bin/bats test
touch $out
'';
});
};
meta = with lib; {
homepage = "https://github.com/bats-core/bats-core";