From a99b6f18c8ce7fdb9a7f0128a22a51521634e3e7 Mon Sep 17 00:00:00 2001 From: rootile Date: Mon, 9 Feb 2026 15:37:41 +0100 Subject: [PATCH] f2: migrate toString-path.sh Change-Id: I862f532e94e385aa0f14c03e38e7e003c7bc83c3 --- tests/functional/meson.build | 1 - tests/functional/toString-path.sh | 8 ----- tests/functional2/eval/test_to_string.py | 40 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) delete mode 100644 tests/functional/toString-path.sh create mode 100644 tests/functional2/eval/test_to_string.py diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 860ed8f27..c8d04736f 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -141,7 +141,6 @@ functional_tests_scripts = [ 'store-ping.sh', 'flakes/show.sh', 'path-from-hash-part.sh', - 'toString-path.sh', 'read-only-store.sh', 'nested-sandboxing.sh', 'test-libstoreconsumer.sh', diff --git a/tests/functional/toString-path.sh b/tests/functional/toString-path.sh deleted file mode 100644 index 07eb87465..000000000 --- a/tests/functional/toString-path.sh +++ /dev/null @@ -1,8 +0,0 @@ -source common.sh - -mkdir -p $TEST_ROOT/foo -echo bla > $TEST_ROOT/foo/bar - -[[ $(nix eval --raw --impure --expr "builtins.readFile (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; } + \"/bar\"))") = bla ]] - -[[ $(nix eval --json --impure --expr "builtins.readDir (builtins.toString (builtins.fetchTree { type = \"path\"; path = \"$TEST_ROOT/foo\"; }))") = '{"bar":"regular"}' ]] diff --git a/tests/functional2/eval/test_to_string.py b/tests/functional2/eval/test_to_string.py new file mode 100644 index 000000000..096add1e0 --- /dev/null +++ b/tests/functional2/eval/test_to_string.py @@ -0,0 +1,40 @@ +from testlib.fixtures.file_helper import with_files, File +from testlib.fixtures.nix import Nix + + +@with_files({"foo": {"bar": File("bla")}}) +def test_path_read_file(nix: Nix): + nix.settings.add_xp_feature("nix-command", "flakes") + res = ( + nix.nix( + [ + "eval", + "--raw", + "--impure", + "--expr", + f'builtins.readFile (builtins.toString (builtins.fetchTree {{ type = "path"; path = "{nix.env.dirs.home / "foo"}"; }} + "/bar"))', + ] + ) + .run() + .ok() + ) + assert res.stdout_plain == "bla" + + +@with_files({"foo": {"bar": File("bla")}}) +def test_path_read_dir(nix: Nix): + nix.settings.add_xp_feature("nix-command", "flakes") + res = ( + nix.nix( + [ + "eval", + "--json", + "--impure", + "--expr", + f'builtins.readDir (builtins.toString (builtins.fetchTree {{ type = "path"; path = "{nix.env.dirs.home / "foo"}"; }}))', + ] + ) + .run() + .ok() + ) + assert res.stdout_plain == '{"bar":"regular"}'