biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / build-support / trivial-builders / test / references / references-test.sh
blob92e4467287edcd541ca8c42a93b5b02b99eb8892
1 #!/usr/bin/env bash
3 # -------------------------------------------------------------------------- #
5 # trivial-builders test
7 # -------------------------------------------------------------------------- #
9 # Execute this build script directly (quick):
11 # * Classic
12 # $ NIX_PATH="nixpkgs=$PWD" nix-shell -p tests.trivial-builders.references.testScriptBin --run references-test
14 # * Flake-based
15 # $ nix run .#tests.trivial-builders.references.testScriptBin
17 # or in the build sandbox with a ~20s VM overhead:
19 # * Classic
20 # $ nix-build --no-out-link -A tests.trivial-builders.references
22 # * Flake-based
23 # $ nix build -L --no-link .#tests.trivial-builders.references
25 # -------------------------------------------------------------------------- #
27 # strict bash
28 set -euo pipefail
30 # debug
31 # set -x
32 # PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
34 cd "$(dirname "${BASH_SOURCE[0]}")" # nixpkgs root
36 # Inject the path to compare from the Nix expression
38 # Associative Arrays
39 declare -A samples=( @SAMPLES@ )
40 declare -A directRefs=( @DIRECT_REFS@ )
41 declare -A closures=( @CLOSURES@ )
43 # Path string
44 collectiveClosure=@COLLECTIVE_CLOSURE@
46 echo >&2 Testing direct closures...
47 for i in "${!samples[@]}"; do
48 echo >&2 Checking "$i" "${samples[$i]}" "${directRefs[$i]}"
49 diff -U3 \
50 <(sort <"${directRefs[$i]}") \
51 <(nix-store -q --references "${samples[$i]}" | sort)
52 done
54 echo >&2 Testing closure...
55 for i in "${!samples[@]}"; do
56 echo >&2 Checking "$i" "${samples[$i]}" "${closures[$i]}"
57 diff -U3 \
58 <(sort <"${closures[$i]}") \
59 <(nix-store -q --requisites "${samples[$i]}" | sort)
60 done
62 echo >&2 Testing mixed closures...
63 echo >&2 Checking all samples "(${samples[*]})" "$collectiveClosure"
64 diff -U3 \
65 <(sort <"$collectiveClosure") \
66 <(nix-store -q --requisites "${samples[@]}" | sort)
68 echo 'OK!'