From 74fb1d515e6879922bc65fab4c7099dde9dd92e5 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 02:36:21 +0000 Subject: tests: run populate's jq programs over lock files of both shapes Depending on the version of Nix, lock files name subdirectories as attribute dir or as query parameter dir of the URL. The VM tests run one version, so only one shape gets covered there. The jq programs for flakes move to pkgs/populate/flake-jq.nix, and a new test, jq, runs them without VMs over lock files of both shapes, with follows, removed and cyclic follows, and inputs given by relative paths. --- tests/jq.sh | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 tests/jq.sh (limited to 'tests/jq.sh') diff --git a/tests/jq.sh b/tests/jq.sh new file mode 100755 index 0000000..a62d6cb --- /dev/null +++ b/tests/jq.sh @@ -0,0 +1,122 @@ +#! /bin/sh +# Runs populate's jq programs for flakes over lock files in the shapes +# different versions of Nix write, without VMs. +# +# usage: jq.sh DIR +# +# DIR contains the programs as selected.jq, selfIsRemote.jq, and +# selfLocked.jq. +set -efu + +programs=$1 +failed=0 + +# usage: expect WHAT ACTUAL EXPECTED +expect() { + if test "$2" != "$3"; then + printf 'FAIL: %s\n expected: %s\n got: %s\n' "$1" "$3" "$2" >&2 + failed=1 + fi +} + +# usage: expect_error WHAT ACTUAL MESSAGE +expect_error() { + case $2 in + *"$3"*) ;; + *) + printf 'FAIL: %s\n expected an error: %s\n got: %s\n' "$1" "$3" "$2" >&2 + failed=1 + ;; + esac +} + +# usage: selection METADATA INPUT +selection() { + printf '%s\n' "$1" | + timeout 10 jq -c --argjson input "$2" --from-file "$programs"/selected.jq 2>&1 || + : +} + +# A flake with an input dep, which has an input inner following the flake's +# input inner, and an input sub, a flake in a subdirectory, written as +# attribute dir or as query parameter dir of the URL. +metadata() { + cat <