From 523df65fba9439ff57c331f020c658c622beb290 Mon Sep 17 00:00:00 2001 From: rootile Date: Mon, 6 Jul 2026 14:39:19 +0200 Subject: [PATCH] tests: migrate misc.sh note: only two of the tests actually needed migrating, as the others were already covered (e.g. by lang) Change-Id: I30abb2bd728ae2b144ad76566096a216aed3b8f8 --- tests/functional/meson.build | 1 - tests/functional/misc.sh | 34 ------------------- tests/functional2/cli/test_env.py | 15 ++++++++ tests/functional2/cli/test_nix_instantiate.py | 22 ++++++++++++ 4 files changed, 37 insertions(+), 35 deletions(-) delete mode 100644 tests/functional/misc.sh create mode 100644 tests/functional2/cli/test_env.py create mode 100644 tests/functional2/cli/test_nix_instantiate.py diff --git a/tests/functional/meson.build b/tests/functional/meson.build index d8fcb3311..14ca375fc 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -77,7 +77,6 @@ functional_tests_scripts = [ 'logging.sh', 'config.sh', 'filter-source.sh', - 'misc.sh', 'linux-sandbox.sh', 'supplementary-groups.sh', 'build-dry.sh', diff --git a/tests/functional/misc.sh b/tests/functional/misc.sh deleted file mode 100644 index b142fdc93..000000000 --- a/tests/functional/misc.sh +++ /dev/null @@ -1,34 +0,0 @@ -source common.sh - -# Tests miscellaneous commands. - -# Do all commands have help? -#nix-env --help | grepQuiet install -#nix-store --help | grepQuiet realise -#nix-instantiate --help | grepQuiet eval -#nix-hash --help | grepQuiet base32 - -# Can we ask for the version number? -nix-env --version | grep "$version" - -# Usage errors. -expect 1 nix-env --foo 2>&1 | grep "no operation" -expect 1 nix-env -q --foo 2>&1 | grep "unknown flag" - -# Eval Errors. -eval_arg_res=$(nix-instantiate --eval -E 'let a = {} // a; in a.foo' 2>&1 || true) -echo $eval_arg_res | grep "at «string»:1:15:" -echo $eval_arg_res | grep "infinite recursion encountered" - -eval_stdin_res=$(echo 'let a = {} // a; in a.foo' | nix-instantiate --eval -E - 2>&1 || true) -echo $eval_stdin_res | grep "at «stdin»:1:15:" -echo $eval_stdin_res | grep "infinite recursion encountered" - -# Unknown setting warning -# NOTE(cole-h): behavior is different depending on the order, which is why we test an unknown option -# before and after the `'{}'`! -out="$(expectStderr 0 nix-instantiate --option foobar baz --expr '{}')" -[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]] - -out="$(expectStderr 0 nix-instantiate '{}' --option foobar baz --expr )" -[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]] diff --git a/tests/functional2/cli/test_env.py b/tests/functional2/cli/test_env.py new file mode 100644 index 000000000..272cfab0b --- /dev/null +++ b/tests/functional2/cli/test_env.py @@ -0,0 +1,15 @@ +from testlib.fixtures.nix import Nix +import pytest + + +pytestmark = pytest.mark.no_daemon + + +def test_no_op(nix: Nix): + res = nix.nix_env(["--foo"]).run().expect(1) + assert "no operation" in res.stderr_plain + + +def test_unknown_flag(nix: Nix): + res = nix.nix_env(["-q", "--foo"]).run().expect(1) + assert "unknown flag" in res.stderr_plain diff --git a/tests/functional2/cli/test_nix_instantiate.py b/tests/functional2/cli/test_nix_instantiate.py new file mode 100644 index 000000000..6cfb1656f --- /dev/null +++ b/tests/functional2/cli/test_nix_instantiate.py @@ -0,0 +1,22 @@ +from testlib.fixtures.nix import Nix +import pytest + + +pytestmark = pytest.mark.no_daemon + + +""" +Unknown setting warning +NOTE(cole-h): behavior is different depending on the order, which is why we test an unknown option +before and after the `'{}'`! +""" + + +def test_unknown_option_first(nix: Nix): + res = nix.nix_instantiate(["--option", "foobar", "baz", "--expr", "{}"]).run().ok() + assert "warning: unknown setting 'foobar'" in res.stderr_plain + + +def test_unknown_option_later(nix: Nix): + res = nix.nix_instantiate(["--expr", "{}", "--option", "foobar", "baz"]).run().ok() + assert "warning: unknown setting 'foobar'" in res.stderr_plain