From 298373615ed546e11892feeb7eb5d3306a77482c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 26 Feb 2026 20:30:45 +0100 Subject: [PATCH] testing: migrate impure-eval.sh Change-Id: Ifd2b6c117511461ce08fa3f9e63635857cb5b015 --- tests/functional/impure-eval.sh | 38 ------------- tests/functional/meson.build | 1 - tests/functional2/eval/test_impure_eval.py | 62 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 39 deletions(-) delete mode 100644 tests/functional/impure-eval.sh create mode 100644 tests/functional2/eval/test_impure_eval.py diff --git a/tests/functional/impure-eval.sh b/tests/functional/impure-eval.sh deleted file mode 100644 index c06a8361c..000000000 --- a/tests/functional/impure-eval.sh +++ /dev/null @@ -1,38 +0,0 @@ -source common.sh - -export REMOTE_STORE="dummy://" - -simpleTest () { - local expr=$1; shift - local result=$1; shift - # rest, extra args - - [[ "$(nix eval --impure --raw "$@" --expr "$expr")" == "$result" ]] -} - -# `builtins.storeDir` - -## Store dir follows `store` store setting -simpleTest 'builtins.storeDir' '/foo' --store "$REMOTE_STORE?store=/foo" -simpleTest 'builtins.storeDir' '/bar' --store "$REMOTE_STORE?store=/bar" - -# `builtins.currentSystem` - -## `system` alone affects by default -simpleTest 'builtins.currentSystem' 'foo' --system 'foo' -simpleTest 'builtins.currentSystem' 'bar' --system 'bar' - -## `system` affects if `eval-system` is an empty string -simpleTest 'builtins.currentSystem' 'foo' --system 'foo' --eval-system '' -simpleTest 'builtins.currentSystem' 'bar' --system 'bar' --eval-system '' - -## `eval-system` alone affects -simpleTest 'builtins.currentSystem' 'foo' --eval-system 'foo' -simpleTest 'builtins.currentSystem' 'bar' --eval-system 'bar' - -## `eval-system` overrides `system` -simpleTest 'builtins.currentSystem' 'bar' --system 'foo' --eval-system 'bar' -simpleTest 'builtins.currentSystem' 'baz' --system 'foo' --eval-system 'baz' - -## `-f` honors nix-path -[ "$(nix eval --option nix-path "foo=$PWD" -f '' attr.foo)" = '"bar"' ] diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 930163628..dbec7690b 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -77,7 +77,6 @@ functional_tests_scripts = [ 'build-remote-content-addressed-fixed.sh', 'build-jobless.sh', 'nar-access.sh', - 'impure-eval.sh', 'repl.sh', 'binary-cache-build-remote.sh', 'logging.sh', diff --git a/tests/functional2/eval/test_impure_eval.py b/tests/functional2/eval/test_impure_eval.py new file mode 100644 index 000000000..5400dfeba --- /dev/null +++ b/tests/functional2/eval/test_impure_eval.py @@ -0,0 +1,62 @@ +import pytest +from testlib.fixtures.nix import Nix +from testlib.fixtures.file_helper import File, with_files + + +class TestImpureEval: + @pytest.fixture(autouse=True) + def setup(self, nix: Nix): + nix.settings.add_xp_feature("nix-command") + self.nix = nix + + def eval(self, expr: str, *args: str) -> str: + return ( + self.nix.nix(["eval", "--impure", "--raw", *args, "--expr", expr]) + .run() + .ok() + .stdout_plain + ) + + @pytest.mark.parametrize("path", ["/foo", "/bar"]) + def test_store_dir(self, path: str): + result = self.eval("builtins.storeDir", "--store", f"dummy://?store={path}") + assert result == path + + @pytest.mark.parametrize("system", ["foo", "bar"]) + def test_current_system_system_only(self, system: str): + result = self.eval("builtins.currentSystem", "--system", system) + assert result == system + + @pytest.mark.parametrize("system", ["foo", "bar"]) + def test_current_system_both(self, system: str): + result = self.eval("builtins.currentSystem", "--system", system, "--eval-system", system) + assert result == system + + @pytest.mark.parametrize("system", ["foo", "bar"]) + def test_current_system_eval_system_only(self, system: str): + result = self.eval("builtins.currentSystem", "--eval-system", system) + assert result == system + + @pytest.mark.parametrize("system", ["foo", "bar"]) + def test_current_system_both_override(self, system: str): + result = self.eval("builtins.currentSystem", "--system", system, "--eval-system", "baz") + assert result == "baz" + + @with_files({"eval.nix": File('{ attr.foo = "bar"; }')}) + def test_nix_path_search(self, nix: Nix): + result = ( + nix.nix( + [ + "eval", + "--option", + "nix-path", + f"foo={nix.env.dirs.home}", + "-f", + "", + "attr.foo", + ] + ) + .run() + .ok() + ) + assert result.stdout_plain == '"bar"'