testing: migrate impure-eval.sh
Change-Id: Ifd2b6c117511461ce08fa3f9e63635857cb5b015
This commit is contained in:
@@ -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 '<foo/eval.nix>' attr.foo)" = '"bar"' ]
|
||||
@@ -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',
|
||||
|
||||
@@ -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",
|
||||
"<foo/eval.nix>",
|
||||
"attr.foo",
|
||||
]
|
||||
)
|
||||
.run()
|
||||
.ok()
|
||||
)
|
||||
assert result.stdout_plain == '"bar"'
|
||||
Reference in New Issue
Block a user