diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2021-11-03 18:10:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-03 18:10:42 +0100 |
commit | 455e7f19d005a52a2687d2996dbc94efd8434a40 (patch) | |
tree | 4102f0b2a74f0e8ed5a707a571c071b822d355c3 /pkgs/build-support | |
parent | 0535a5b7acf63780716a4442eea2875f4ee2b94f (diff) | |
parent | 51f7c15df992de82812e3f3f3e48d677fa0ed172 (diff) |
Merge pull request #144052 from hercules-ci/improve-trivial-builders-test
test.trivial-builders: Add test cases, fix test runner, rename
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-x | pkgs/build-support/trivial-builders/test/references-test.sh (renamed from pkgs/build-support/trivial-builders/test.sh) | 16 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders/test/references.nix (renamed from pkgs/build-support/trivial-builders/test.nix) | 29 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders/test/sample.nix | 6 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders/test/writeStringReferencesToFile.nix | 18 |
4 files changed, 41 insertions, 28 deletions
diff --git a/pkgs/build-support/trivial-builders/test.sh b/pkgs/build-support/trivial-builders/test/references-test.sh index b7c4726a9be01..473ca6e107694 100755 --- a/pkgs/build-support/trivial-builders/test.sh +++ b/pkgs/build-support/trivial-builders/test/references-test.sh @@ -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 diff --git a/pkgs/build-support/trivial-builders/test.nix b/pkgs/build-support/trivial-builders/test/references.nix index 420a0fd0114d0..a2bee51b13e7f 100644 --- a/pkgs/build-support/trivial-builders/test.nix +++ b/pkgs/build-support/trivial-builders/test/references.nix @@ -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 = { diff --git a/pkgs/build-support/trivial-builders/test/sample.nix b/pkgs/build-support/trivial-builders/test/sample.nix index 807594d74bb3b..a4eedce8417eb 100644 --- a/pkgs/build-support/trivial-builders/test/sample.nix +++ b/pkgs/build-support/trivial-builders/test/sample.nix @@ -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 diff --git a/pkgs/build-support/trivial-builders/test/writeStringReferencesToFile.nix b/pkgs/build-support/trivial-builders/test/writeStringReferencesToFile.nix new file mode 100644 index 0000000000000..b93b43b74aa49 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/writeStringReferencesToFile.nix @@ -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 +'' |