tests.trivial-builders.references: test writeClosure

Test writeClosure instead of writeReferencesToFile.

Add multiple-path test for writeReferenceClosureToFile.

Rename variables:
- references -> closures (passthru affected)
- REFERENCES -> CLOSURES
This commit is contained in:
Yueh-Shun Li 2023-11-29 01:24:22 +08:00
parent e9fd4389d2
commit 8a8d07bc15
5 changed files with 54 additions and 40 deletions

View file

@ -26,6 +26,9 @@ recurseIntoAttrs {
then references
else {};
writeCBin = callPackage ./writeCBin.nix {};
writeClosure-union = callPackage ./writeClosure-union.nix {
inherit (references) samples;
};
writeShellApplication = callPackage ./writeShellApplication.nix {};
writeScriptBin = callPackage ./writeScriptBin.nix {};
writeShellScript = callPackage ./write-shell-script.nix {};

View file

@ -12,7 +12,7 @@
, cleanSamples ? lib.filterAttrs (n: lib.isStringLike)
# Test targets
, writeDirectReferencesToFile
, writeReferencesToFile
, writeClosure
}:
# -------------------------------------------------------------------------- #
@ -46,8 +46,9 @@ let
samplesToString = attrs:
lib.concatMapStringsSep " " (name: "[${name}]=${lib.escapeShellArg "${attrs.${name}}"}") (builtins.attrNames attrs);
references = lib.mapAttrs (n: v: writeReferencesToFile v) samples;
closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples;
directReferences = lib.mapAttrs (n: v: writeDirectReferencesToFile v) samples;
collectiveClosure = writeClosure (lib.attrValues samples);
testScriptBin = stdenvNoCC.mkDerivation (finalAttrs: {
name = "references-test";
@ -61,8 +62,9 @@ let
mkdir -p "$out/bin"
substitute "$src" "$out/bin/${finalAttrs.meta.mainProgram}" \
--replace "@SAMPLES@" ${lib.escapeShellArg (samplesToString samples)} \
--replace "@REFERENCES@" ${lib.escapeShellArg (samplesToString references)} \
--replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)}
--replace "@CLOSURES@" ${lib.escapeShellArg (samplesToString closures)} \
--replace "@DIRECT_REFS@" ${lib.escapeShellArg (samplesToString directReferences)} \
--replace "@COLLECTIVE_CLOSURE@" ${lib.escapeShellArg collectiveClosure}
runHook postInstall
chmod +x "$out/bin/${finalAttrs.meta.mainProgram}"
'';
@ -79,8 +81,9 @@ let
passthru = {
inherit
collectiveClosure
directReferences
references
closures
samples
;
};
@ -109,8 +112,9 @@ testers.nixosTest {
'';
passthru = {
inherit
collectiveClosure
directReferences
references
closures
samples
testScriptBin
;

View file

@ -33,16 +33,17 @@ set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" # nixpkgs root
# Injected by Nix (to avoid evaluating in a derivation)
# turn them into arrays
# shellcheck disable=SC2206 # deliberately unquoted
declare -A samples=( @SAMPLES@ )
# shellcheck disable=SC2206 # deliberately unquoted
declare -A directRefs=( @DIRECT_REFS@ )
# shellcheck disable=SC2206 # deliberately unquoted
declare -A references=( @REFERENCES@ )
# Inject the path to compare from the Nix expression
echo >&2 Testing direct references...
# Associative Arrays
declare -A samples=( @SAMPLES@ )
declare -A directRefs=( @DIRECT_REFS@ )
declare -A closures=( @CLOSURES@ )
# Path string
collectiveClosure=@COLLECTIVE_CLOSURE@
echo >&2 Testing direct closures...
for i in "${!samples[@]}"; do
echo >&2 Checking "$i" "${samples[$i]}" "${directRefs[$i]}"
diff -U3 \
@ -52,10 +53,16 @@ done
echo >&2 Testing closure...
for i in "${!samples[@]}"; do
echo >&2 Checking "$i" "${samples[$i]}" "${references[$i]}"
echo >&2 Checking "$i" "${samples[$i]}" "${closures[$i]}"
diff -U3 \
<(sort <"${references[$i]}") \
<(sort <"${closures[$i]}") \
<(nix-store -q --requisites "${samples[$i]}" | sort)
done
echo >&2 Testing mixed closures...
echo >&2 Checking all samples "(${samples[*]})" "$collectiveClosure"
diff -U3 \
<(sort <"$collectiveClosure") \
<(nix-store -q --requisites "${samples[@]}" | sort)
echo 'OK!'

View file

@ -0,0 +1,23 @@
{ lib
, runCommandLocal
# Test targets
, writeClosure
, samples
}:
runCommandLocal "test-trivial-builders-writeClosure-union" {
__structuredAttrs = true;
closures = lib.mapAttrs (n: v: writeClosure [ v ]) samples;
collectiveClosure = writeClosure (lib.attrValues samples);
inherit samples;
meta.maintainers = with lib.maintainers; [
ShamrockLee
];
} ''
set -eu -o pipefail
echo >&2 Testing mixed closures...
echo >&2 Checking all samples "(''${samples[*]})" "$collectiveClosure"
diff -U3 \
<(sort <"$collectiveClosure") \
<(cat "''${closures[@]}" | sort | uniq)
touch "$out"
''

View file

@ -1,23 +0,0 @@
{ lib
, runCommandLocal
# Test targets
, writeClosure
, samples
}:
runCommandLocal "test-trivial-builders-writeClosure-mixed" {
__structuredAttrs = true;
references = lib.mapAttrs (n: v: writeClosure [ v ]) samples;
allRefs = writeClosure (lib.attrValues samples);
inherit samples;
meta.maintainers = with lib.maintainers; [
ShamrockLee
];
} ''
set -eu -o pipefail
echo >&2 Testing mixed closures...
echo >&2 Checking all samples "(''${samples[*]})" "$allRefs"
diff -U3 \
<(sort <"$allRefs") \
<(cat "''${references[@]}" | sort | uniq)
touch "$out"
''