From 287642f132d8141269bd7c23b0bc7c1ee512b171 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 20 Feb 2022 15:56:22 +0100 Subject: tests: implement test for `nix log` with `ssh-ng://` builds A few notes: * The `echo hi` is needed to make sure that a file that can be read by `nix log` is properly created (i.e. some output is needed). This is known and to be fixed in #6051. * We explicitly ignore the floating-CA case here: the `$out` of `input3` depends on `$out` of `input2`. This means that there are actually two derivations - I assume that this is because at eval time (i.e. `nix-instantiate -A`) the hash of `input2` isn't known yet and the other .drv is created as soon as `input2` was built. This is another issue on its own, so we ignore the case here explicitly. --- tests/build-hook-ca-fixed.nix | 10 ++++++---- tests/build-hook.nix | 10 ++++++---- tests/build-remote.sh | 8 ++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/build-hook-ca-fixed.nix b/tests/build-hook-ca-fixed.nix index ec7171ac9..899b610a8 100644 --- a/tests/build-hook-ca-fixed.nix +++ b/tests/build-hook-ca-fixed.nix @@ -11,13 +11,13 @@ let args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")]; outputHashMode = "recursive"; outputHashAlgo = "sha256"; - } // removeAttrs args ["builder" "meta"]) - // { meta = args.meta or {}; }; + } // removeAttrs args ["builder" "meta" "passthru"]) + // { meta = args.meta or {}; passthru = args.passthru or {}; }; input1 = mkDerivation { shell = busybox; name = "build-remote-input-1"; - buildCommand = "echo FOO > $out"; + buildCommand = "echo hi; echo FOO > $out"; requiredSystemFeatures = ["foo"]; outputHash = "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="; }; @@ -25,7 +25,7 @@ let input2 = mkDerivation { shell = busybox; name = "build-remote-input-2"; - buildCommand = "echo BAR > $out"; + buildCommand = "echo hi; echo BAR > $out"; requiredSystemFeatures = ["bar"]; outputHash = "sha256-XArauVH91AVwP9hBBQNlkX9ccuPpSYx9o0zeIHb6e+Q="; }; @@ -34,6 +34,7 @@ let shell = busybox; name = "build-remote-input-3"; buildCommand = '' + echo hi read x < ${input2} echo $x BAZ > $out ''; @@ -46,6 +47,7 @@ in mkDerivation { shell = busybox; name = "build-remote"; + passthru = { inherit input1 input2 input3; }; buildCommand = '' read x < ${input1} diff --git a/tests/build-hook.nix b/tests/build-hook.nix index eb16676f0..3c83e0475 100644 --- a/tests/build-hook.nix +++ b/tests/build-hook.nix @@ -9,20 +9,20 @@ let inherit system; builder = busybox; args = ["sh" "-e" args.builder or (builtins.toFile "builder-${args.name}.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")]; - } // removeAttrs args ["builder" "meta"]) - // { meta = args.meta or {}; }; + } // removeAttrs args ["builder" "meta" "passthru"]) + // { meta = args.meta or {}; passthru = args.passthru or {}; }; input1 = mkDerivation { shell = busybox; name = "build-remote-input-1"; - buildCommand = "echo FOO > $out"; + buildCommand = "echo hi; echo FOO > $out"; requiredSystemFeatures = ["foo"]; }; input2 = mkDerivation { shell = busybox; name = "build-remote-input-2"; - buildCommand = "echo BAR > $out"; + buildCommand = "echo hi; echo BAR > $out"; requiredSystemFeatures = ["bar"]; }; @@ -30,6 +30,7 @@ let shell = busybox; name = "build-remote-input-3"; buildCommand = '' + echo hi read x < ${input2} echo $x BAZ > $out ''; @@ -41,6 +42,7 @@ in mkDerivation { shell = busybox; name = "build-remote"; + passthru = { inherit input1 input2 input3; }; buildCommand = '' read x < ${input1} diff --git a/tests/build-remote.sh b/tests/build-remote.sh index 806c6d261..4ecc788a3 100644 --- a/tests/build-remote.sh +++ b/tests/build-remote.sh @@ -54,6 +54,14 @@ nix path-info --store $TEST_ROOT/machine3 --all \ | grep -v builder-build-remote-input-2.sh \ | grep builder-build-remote-input-3.sh + +if [[ -z "$CONTENT_ADDRESSED" ]]; then + for i in input1 input3; do + drv="$(nix-instantiate $file -A passthru.$i --store $TEST_ROOT/machine0 --arg busybox $busybox)" + nix log --store $TEST_ROOT/machine0 "$drv" + done +fi + # Behavior of keep-failed out="$(nix-build 2>&1 failing.nix \ --builders "$(join_by '; ' "${builders[@]}")" \ -- cgit v1.2.3 From 697d1dac0164001a10ab990a382ad83f2e7628d4 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 4 Mar 2022 16:58:27 +0100 Subject: tests: grep for string in nix log for remote-builds --- tests/build-hook-ca-fixed.nix | 4 ++-- tests/build-hook.nix | 4 ++-- tests/build-remote.sh | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/build-hook-ca-fixed.nix b/tests/build-hook-ca-fixed.nix index 899b610a8..4cb9e85d1 100644 --- a/tests/build-hook-ca-fixed.nix +++ b/tests/build-hook-ca-fixed.nix @@ -17,7 +17,7 @@ let input1 = mkDerivation { shell = busybox; name = "build-remote-input-1"; - buildCommand = "echo hi; echo FOO > $out"; + buildCommand = "echo hi-input1; echo FOO > $out"; requiredSystemFeatures = ["foo"]; outputHash = "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="; }; @@ -34,7 +34,7 @@ let shell = busybox; name = "build-remote-input-3"; buildCommand = '' - echo hi + echo hi-input3 read x < ${input2} echo $x BAZ > $out ''; diff --git a/tests/build-hook.nix b/tests/build-hook.nix index 3c83e0475..643334caa 100644 --- a/tests/build-hook.nix +++ b/tests/build-hook.nix @@ -15,7 +15,7 @@ let input1 = mkDerivation { shell = busybox; name = "build-remote-input-1"; - buildCommand = "echo hi; echo FOO > $out"; + buildCommand = "echo hi-input1; echo FOO > $out"; requiredSystemFeatures = ["foo"]; }; @@ -30,7 +30,7 @@ let shell = busybox; name = "build-remote-input-3"; buildCommand = '' - echo hi + echo hi-input3 read x < ${input2} echo $x BAZ > $out ''; diff --git a/tests/build-remote.sh b/tests/build-remote.sh index 4ecc788a3..a2c3b9ce7 100644 --- a/tests/build-remote.sh +++ b/tests/build-remote.sh @@ -57,8 +57,7 @@ nix path-info --store $TEST_ROOT/machine3 --all \ if [[ -z "$CONTENT_ADDRESSED" ]]; then for i in input1 input3; do - drv="$(nix-instantiate $file -A passthru.$i --store $TEST_ROOT/machine0 --arg busybox $busybox)" - nix log --store $TEST_ROOT/machine0 "$drv" + nix log --store $TEST_ROOT/machine0 --file "$file" --arg busybox $busybox passthru."$i" | grep hi-$i done fi -- cgit v1.2.3 From 860016bcbf1ea91289ebc5d495eccfe43f22ac62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= <7226587+thufschmitt@users.noreply.github.com> Date: Mon, 7 Mar 2022 09:15:34 +0100 Subject: Explain why the log tests are disabled for CA derivations --- tests/build-remote.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/build-remote.sh b/tests/build-remote.sh index a2c3b9ce7..094366872 100644 --- a/tests/build-remote.sh +++ b/tests/build-remote.sh @@ -55,6 +55,7 @@ nix path-info --store $TEST_ROOT/machine3 --all \ | grep builder-build-remote-input-3.sh +# Temporarily disabled because of https://github.com/NixOS/nix/issues/6209 if [[ -z "$CONTENT_ADDRESSED" ]]; then for i in input1 input3; do nix log --store $TEST_ROOT/machine0 --file "$file" --arg busybox $busybox passthru."$i" | grep hi-$i -- cgit v1.2.3 From 91635206c0d33f9862b788487aa8a056a791af94 Mon Sep 17 00:00:00 2001 From: regnat Date: Fri, 4 Mar 2022 10:29:48 +0100 Subject: Add some end-to-end tests for the suggestions --- tests/local.mk | 5 +++-- tests/suggestions.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/suggestions.sh (limited to 'tests') diff --git a/tests/local.mk b/tests/local.mk index c3a6aa1fc..8032fc38a 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -92,8 +92,9 @@ nix_tests = \ bash-profile.sh \ pass-as-file.sh \ describe-stores.sh \ - store-ping.sh \ - nix-profile.sh + nix-profile.sh \ + suggestions.sh \ + store-ping.sh ifeq ($(HAVE_LIBCPUID), 1) nix_tests += compute-levels.sh diff --git a/tests/suggestions.sh b/tests/suggestions.sh new file mode 100644 index 000000000..16a5a7004 --- /dev/null +++ b/tests/suggestions.sh @@ -0,0 +1,36 @@ +source common.sh + +clearStore + +cd "$TEST_HOME" + +cat < flake.nix +{ + outputs = a: { + packages.$system = { + foo = 1; + fo1 = 1; + fo2 = 1; + fooo = 1; + foooo = 1; + fooooo = 1; + fooooo1 = 1; + fooooo2 = 1; + fooooo3 = 1; + fooooo4 = 1; + fooooo5 = 1; + fooooo6 = 1; + }; + }; +} +EOF + +# Probable typo in the requested attribute path. Suggest some close possibilities +NIX_BUILD_STDERR_WITH_SUGGESTIONS=$(! nix build .\#fob 2>&1 1>/dev/null) +[[ "$NIX_BUILD_STDERR_WITH_SUGGESTIONS" =~ "Did you mean one of fo1, fo2, foo or fooo?" ]] || \ + fail "The nix build stderr should suggest the three closest possiblities" + +# None of the possible attributes is close to `bar`, so shouldn’t suggest anything +NIX_BUILD_STDERR_WITH_NO_CLOSE_SUGGESTION=$(! nix build .\#bar 2>&1 1>/dev/null) +[[ ! "$NIX_BUILD_STDERR_WITH_NO_CLOSE_SUGGESTION" =~ "Did you mean" ]] || \ + fail "The nix build stderr shouldn’t suggest anything if there’s nothing relevant to suggest" -- cgit v1.2.3