From 312e90f4b6c8b5680117b56b4f80af85828c3cfd Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 9 Aug 2025 15:01:25 +0200 Subject: [PATCH] tests: add small testcase for output cycle detection Change-Id: I186937dfbca4d051e5ad860239720816429a0a8e --- tests/functional/check-outputs.nix | 25 +++++++++++++++++++++++++ tests/functional/meson.build | 1 + tests/functional/output-cycles.sh | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/functional/check-outputs.nix create mode 100644 tests/functional/output-cycles.sh diff --git a/tests/functional/check-outputs.nix b/tests/functional/check-outputs.nix new file mode 100644 index 000000000..ce260dd4d --- /dev/null +++ b/tests/functional/check-outputs.nix @@ -0,0 +1,25 @@ +with import ./config.nix; + +rec { + dep = import ./dependencies.nix {}; + + cycle = mkDerivation { + name = "cycle"; + inherit dep; + outputs = [ "foo" "bar" "baz" ]; + builder = builtins.toFile "builder.sh" '' + mkdir -p $foo/bin $bar/lib $baz/share + echo $bar > $foo/bin/alarm + echo $baz > $bar/lib/libfoo + echo $foo > $baz/share/lalala + ''; + }; + + as_dependency = mkDerivation { + name = "depends-on-cycle"; + inherit cycle; + builder = builtins.toFile "builder.sh" '' + touch $out + ''; + }; +} diff --git a/tests/functional/meson.build b/tests/functional/meson.build index c37a32e62..7b73ed26a 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -173,6 +173,7 @@ functional_tests_scripts = [ 'regression-reference-checks.sh', 'redirected-filter-source.sh', 'daemon-trust.sh', + 'output-cycles.sh', ] # Plugin tests require shared libraries support. diff --git a/tests/functional/output-cycles.sh b/tests/functional/output-cycles.sh new file mode 100644 index 000000000..6b2931ba2 --- /dev/null +++ b/tests/functional/output-cycles.sh @@ -0,0 +1,10 @@ +source common.sh + +clearStore + +(! nix-build check-outputs.nix -A cycle) 2>&1 | grepQuiet "cycle detected in build of '.*' in the references of output 'bar' from output 'foo'" + +error="$(! nix-build check-outputs.nix -A as_dependency 2>&1)" + +grepQuiet "cycle detected in build of '.*' in the references of output 'bar' from output 'foo'" <<<"$error" +grepQuiet "error: 1 dependencies of derivation" <<<"$error"