tests/functional/output-cycles: move to functional2

Change-Id: I682f62a695ba7722e2b3063bf831fc50a19eb153
This commit is contained in:
Maximilian Bosch
2025-12-07 21:47:10 +01:00
parent 0a5f474a25
commit be3e4bf78e
4 changed files with 78 additions and 30 deletions
-1
View File
@@ -160,7 +160,6 @@ functional_tests_scripts = [
'regression-reference-checks.sh',
'redirected-filter-source.sh',
'daemon-trust.sh',
'output-cycles.sh',
]
# Plugin tests require shared libraries support.
-29
View File
@@ -1,29 +0,0 @@
source common.sh
clearStore
error="$(! 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"
if [[ "$(uname -s)" = Linux ]]; then
<<<"$error" grepQuiet "/store/.*-cycle-bar"
<<<"$error" grepQuiet "└───lib/libfoo: ….*cycle-baz.*"
<<<"$error" grepQuiet " →.*/store/.*-cycle-baz"
<<<"$error" grepQuiet " └───share/lalala:.*-cycle-foo.*"
fi
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"
error="$(! nix-build check-outputs.nix -A cycle-with-deps 2>&1)"
grepQuiet "cycle detected in build of '.*' in the references of output 'bar' from output 'foo'" <<<"$error"
if [[ "$(uname -s)" = Linux ]]; then
echo "$error"
<<<"$error" grepQuiet "/store/.*-cycle-with-deps-bar"
<<<"$error" grepQuiet "└───txt: ….*cycle-with-deps-foo.*"
<<<"$error" grepQuiet " →.*/store/.*-cycle-with-deps-foo"
<<<"$error" grepQuiet " └───txt:.*-cycle-with-deps-bar.*"
fi
@@ -0,0 +1,78 @@
import re
import sys
from functional2.testlib.fixtures.file_helper import with_files, CopyFile
from functional2.testlib.fixtures.nix import Nix
from functional2.testlib.utils import get_global_asset_pack
_files = {
"output-cycles.nix": CopyFile("assets/test_build/output-cycles.nix"),
**get_global_asset_pack("dependencies"),
}
def _assert_cycle_tree(output: str, regexes: list[str]):
lines = output.splitlines()
start = next((k for k, v in enumerate(lines) if "Shown below are the files inside" in v), None)
assert start is not None
for line, regex in enumerate(regexes, start=start + 1):
assert re.search(regex, lines[line])
def _assert_cycle_message(err: str):
assert (
len(
re.findall(
r"cycle detected in build of '.*' in the references of output 'bar' from output 'foo'",
err,
)
)
== 1
)
@with_files(_files)
def test_cycle(nix: Nix):
res = nix.nix_build(["output-cycles.nix", "-A", "cycle"]).run().expect(1)
err = res.stderr_plain
_assert_cycle_message(err)
if sys.platform == "linux":
_assert_cycle_tree(
err,
[
r"/store/.*-cycle-bar",
r"└───lib/libfoo: ….*cycle-baz.*",
r" →.*/store/.*-cycle-baz",
r" └───share/lalala:.*-cycle-foo.*",
],
)
@with_files(_files)
def test_cycle_in_dependency(nix: Nix):
res = nix.nix_build(["output-cycles.nix", "-A", "as_dependency"]).run().expect(1)
err = res.stderr_plain
_assert_cycle_message(err)
assert "error: 1 dependencies of derivation" in err
@with_files(_files)
def test_cycle_with_deps(nix: Nix):
res = nix.nix_build(["output-cycles.nix", "-A", "cycle-with-deps"]).run().expect(1)
err = res.stderr_plain
_assert_cycle_message(err)
if sys.platform == "linux":
_assert_cycle_tree(
err,
[
r"/store/.*-cycle-with-deps-bar",
r"└───txt: ….*cycle-with-deps-foo.*",
r" →.*/store/.*-cycle-with-deps-foo",
r" └───txt:.*-cycle-with-deps-bar.*",
],
)