mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-10 08:39:08 +03:00
test.trivial-builders: Add test cases, fix test runner, rename
The writeStringReferencesToFile didn't handle non-unique references to the same path correctly.
This commit is contained in:
parent
e544ee88fa
commit
51f7c15df9
@ -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
|
@ -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 = {
|
@ -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
|
||||
|
@ -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
|
||||
''
|
@ -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 {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user