Merge pull request #123597 from hercules-ci/issue-123572
tests.trivial: Avoid evaluation and ${pkgs.path} dep
This commit is contained in:
commit
5bbdc24b2a
|
@ -1,5 +1,27 @@
|
||||||
{ lib, nixosTest, path, writeText, hello, figlet, stdenvNoCC }:
|
{ lib, nixosTest, pkgs, writeText, hello, figlet, stdenvNoCC }:
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
#
|
||||||
|
# trivial-builders test
|
||||||
|
#
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
#
|
||||||
|
# This file can be run independently (quick):
|
||||||
|
#
|
||||||
|
# $ pkgs/build-support/trivial-builders/test.sh
|
||||||
|
#
|
||||||
|
# or in the build sandbox with a ~20s VM overhead
|
||||||
|
#
|
||||||
|
# $ nix-build -A tests.trivial-builders
|
||||||
|
#
|
||||||
|
# -------------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
let
|
||||||
|
invokeSamples = file:
|
||||||
|
lib.concatStringsSep " " (
|
||||||
|
lib.attrValues (import file { inherit pkgs; })
|
||||||
|
);
|
||||||
|
in
|
||||||
nixosTest {
|
nixosTest {
|
||||||
name = "nixpkgs-trivial-builders";
|
name = "nixpkgs-trivial-builders";
|
||||||
nodes.machine = { ... }: {
|
nodes.machine = { ... }: {
|
||||||
|
@ -10,11 +32,22 @@ nixosTest {
|
||||||
environment.etc."pre-built-paths".source = writeText "pre-built-paths" (
|
environment.etc."pre-built-paths".source = writeText "pre-built-paths" (
|
||||||
builtins.toJSON [hello figlet stdenvNoCC]
|
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;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
testScript = ''
|
testScript = ''
|
||||||
machine.succeed("""
|
machine.succeed("""
|
||||||
cd ${lib.cleanSource path}
|
${./test.sh} 2>/dev/console
|
||||||
./pkgs/build-support/trivial-builders/test.sh 2>/dev/console
|
|
||||||
""")
|
""")
|
||||||
'';
|
'';
|
||||||
|
meta = {
|
||||||
|
license = lib.licenses.mit; # nixpkgs license
|
||||||
|
maintainers = with lib.maintainers; [
|
||||||
|
roberth
|
||||||
|
];
|
||||||
|
description = "Run the Nixpkgs trivial builders tests";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,33 +25,32 @@ set -euo pipefail
|
||||||
|
|
||||||
cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root
|
cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root
|
||||||
|
|
||||||
testDirectReferences() {
|
if [[ -z ${SAMPLE:-} ]]; then
|
||||||
expr="$1"
|
sample=( `nix-build test/sample.nix` )
|
||||||
|
directRefs=( `nix-build test/invoke-writeDirectReferencesToFile.nix` )
|
||||||
|
references=( `nix-build test/invoke-writeReferencesToFile.nix` )
|
||||||
|
else
|
||||||
|
# Injected by Nix (to avoid evaluating in a derivation)
|
||||||
|
# turn them into arrays
|
||||||
|
sample=($SAMPLE)
|
||||||
|
directRefs=($DIRECT_REFS)
|
||||||
|
references=($REFERENCES)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo >&2 Testing direct references...
|
||||||
|
for i in "${!sample[@]}"; do
|
||||||
|
echo >&2 Checking '#'$i ${sample[$i]} ${directRefs[$i]}
|
||||||
diff -U3 \
|
diff -U3 \
|
||||||
<(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeDirectReferencesToFile ($expr)")) \
|
<(sort <${directRefs[$i]}) \
|
||||||
<(nix-store -q --references $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort)
|
<(nix-store -q --references ${sample[$i]} | sort)
|
||||||
}
|
done
|
||||||
|
|
||||||
testDirectReferences 'hello'
|
echo >&2 Testing closure...
|
||||||
testDirectReferences 'figlet'
|
for i in "${!sample[@]}"; do
|
||||||
testDirectReferences 'writeText "hi" "hello"'
|
echo >&2 Checking '#'$i ${sample[$i]} ${references[$i]}
|
||||||
testDirectReferences 'writeText "hi" "hello ${hello}"'
|
|
||||||
testDirectReferences 'writeText "hi" "hello ${hello} ${figlet}"'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
testClosure() {
|
|
||||||
expr="$1"
|
|
||||||
diff -U3 \
|
diff -U3 \
|
||||||
<(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeReferencesToFile ($expr)")) \
|
<(sort <${references[$i]}) \
|
||||||
<(nix-store -q --requisites $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort)
|
<(nix-store -q --requisites ${sample[$i]} | sort)
|
||||||
}
|
done
|
||||||
|
|
||||||
testClosure 'hello'
|
|
||||||
testClosure 'figlet'
|
|
||||||
testClosure 'writeText "hi" "hello"'
|
|
||||||
testClosure 'writeText "hi" "hello ${hello}"'
|
|
||||||
testClosure 'writeText "hi" "hello ${hello} ${figlet}"'
|
|
||||||
|
|
||||||
|
|
||||||
echo 'OK!'
|
echo 'OK!'
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{ pkgs ? import ../../../.. { config = {}; overlays = []; } }:
|
||||||
|
pkgs.lib.mapAttrs
|
||||||
|
(k: v: pkgs.writeDirectReferencesToFile v)
|
||||||
|
(import ./sample.nix { inherit pkgs; })
|
|
@ -0,0 +1,4 @@
|
||||||
|
{ pkgs ? import ../../../.. { config = {}; overlays = []; } }:
|
||||||
|
pkgs.lib.mapAttrs
|
||||||
|
(k: v: pkgs.writeReferencesToFile v)
|
||||||
|
(import ./sample.nix { inherit pkgs; })
|
|
@ -0,0 +1,15 @@
|
||||||
|
{ pkgs ? import ../../../.. { config = {}; overlays = []; } }:
|
||||||
|
let
|
||||||
|
inherit (pkgs)
|
||||||
|
figlet
|
||||||
|
hello
|
||||||
|
writeText
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
hello = hello;
|
||||||
|
figlet = figlet;
|
||||||
|
norefs = writeText "hi" "hello";
|
||||||
|
helloRef = writeText "hi" "hello ${hello}";
|
||||||
|
helloFigletRef = writeText "hi" "hello ${hello} ${figlet}";
|
||||||
|
}
|
Loading…
Reference in New Issue