Merge pull request #144052 from hercules-ci/improve-trivial-builders-test

test.trivial-builders: Add test cases, fix test runner, rename
This commit is contained in:
Robert Hensing 2021-11-03 18:10:42 +01:00 committed by GitHub
commit 455e7f19d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 30 deletions

View file

@ -8,11 +8,11 @@
#
# This file can be run independently (quick):
#
# $ pkgs/build-support/trivial-builders/test.sh
# $ pkgs/build-support/trivial-builders/references-test.sh
#
# or in the build sandbox with a ~20s VM overhead
#
# $ nix-build -A tests.trivial-builders
# $ nix-build -A tests.trivial-builders.references
#
# -------------------------------------------------------------------------- #
@ -26,9 +26,15 @@ set -euo pipefail
cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root
if [[ -z ${SAMPLE:-} ]]; then
sample=( `nix-build test/sample.nix` )
directRefs=( `nix-build test/invoke-writeDirectReferencesToFile.nix` )
references=( `nix-build test/invoke-writeReferencesToFile.nix` )
echo "Running the script directly is currently not supported."
echo "If you need to iterate, remove the raw path, which is not returned by nix-build."
exit 1
# sample=( `nix-build --no-out-link sample.nix` )
# directRefs=( `nix-build --no-out-link invoke-writeDirectReferencesToFile.nix` )
# references=( `nix-build --no-out-link invoke-writeReferencesToFile.nix` )
# echo "sample: ${#sample[@]}"
# echo "direct: ${#directRefs[@]}"
# echo "indirect: ${#references[@]}"
else
# Injected by Nix (to avoid evaluating in a derivation)
# turn them into arrays

View file

@ -8,11 +8,11 @@
#
# This file can be run independently (quick):
#
# $ pkgs/build-support/trivial-builders/test.sh
# $ pkgs/build-support/trivial-builders/references-test.sh
#
# or in the build sandbox with a ~20s VM overhead
#
# $ nix-build -A tests.trivial-builders
# $ nix-build -A tests.trivial-builders.references
#
# -------------------------------------------------------------------------- #
@ -33,30 +33,15 @@ nixosTest {
builtins.toJSON [hello figlet stdenvNoCC]
);
environment.variables = {
SAMPLE = invokeSamples ./test/sample.nix;
REFERENCES = invokeSamples ./test/invoke-writeReferencesToFile.nix;
DIRECT_REFS = invokeSamples ./test/invoke-writeDirectReferencesToFile.nix;
SAMPLE = invokeSamples ./sample.nix;
REFERENCES = invokeSamples ./invoke-writeReferencesToFile.nix;
DIRECT_REFS = invokeSamples ./invoke-writeDirectReferencesToFile.nix;
};
};
testScript =
let
sample = import ./test/sample.nix { inherit pkgs; };
samplePaths = lib.unique (lib.attrValues sample);
sampleText = pkgs.writeText "sample-text" (lib.concatStringsSep "\n" samplePaths);
stringReferencesText =
pkgs.writeStringReferencesToFile
((lib.concatMapStringsSep "fillertext"
(d: "${d}")
(lib.attrValues sample)) + ''
STORE=${builtins.storeDir};\nsystemctl start bar-foo.service
'');
in ''
''
machine.succeed("""
${./test.sh} 2>/dev/console
""")
machine.succeed("""
echo >&2 Testing string references...
diff -U3 <(sort ${stringReferencesText}) <(sort ${sampleText})
${./references-test.sh} 2>/dev/console
""")
'';
meta = {

View file

@ -1,10 +1,11 @@
{ pkgs ? import ../../../.. { config = {}; overlays = []; } }:
{ pkgs ? import ../../../.. { config = { }; overlays = [ ]; } }:
let
inherit (pkgs)
figlet
zlib
hello
writeText
runCommand
;
in
{
@ -17,7 +18,10 @@ in
helloRef = writeText "hi" "hello ${hello}";
helloRefDup = writeText "hi" "hello ${hello}";
path = ./invoke-writeReferencesToFile.nix;
pathLike.outPath = ./invoke-writeReferencesToFile.nix;
helloFigletRef = writeText "hi" "hello ${hello} ${figlet}";
selfRef = runCommand "self-ref-1" {} "echo $out >$out";
selfRef2 = runCommand "self-ref-2" {} ''echo "${figlet}, $out" >$out'';
inherit (pkgs)
emptyFile
emptyDirectory

View file

@ -0,0 +1,18 @@
{ callPackage, lib, pkgs, runCommand, writeText, writeStringReferencesToFile }:
let
sample = import ./sample.nix { inherit pkgs; };
samplePaths = lib.unique (lib.attrValues sample);
stri = x: "${x}";
sampleText = writeText "sample-text" (lib.concatStringsSep "\n" (lib.unique (map stri samplePaths)));
stringReferencesText =
writeStringReferencesToFile
((lib.concatMapStringsSep "fillertext"
stri
(lib.attrValues sample)) + ''
STORE=${builtins.storeDir};\nsystemctl start bar-foo.service
'');
in
runCommand "test-writeStringReferencesToFile" { } ''
diff -U3 <(sort ${stringReferencesText}) <(sort ${sampleText})
touch $out
''

View file

@ -51,8 +51,11 @@ with pkgs;
cuda = callPackage ./cuda { };
trivial = callPackage ../build-support/trivial-builders/test.nix {};
trivial-overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
trivial-builders = recurseIntoAttrs {
writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {};
references = callPackage ../build-support/trivial-builders/test/references.nix {};
overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
};
writers = callPackage ../build-support/writers/test.nix {};
}