From 0bcdfe2c4313535816f546072923aecaa75bde9c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 24 Feb 2026 22:42:47 +0100 Subject: [PATCH] testing: migrate fmt.sh Change-Id: Icc593b57a06c7fdf75762094982788f6351dcadc --- tests/functional/fmt.sh | 36 ------------- tests/functional/meson.build | 1 - .../cli/assets}/fmt.simple.sh | 0 tests/functional2/cli/test_fmt.py | 53 +++++++++++++++++++ 4 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 tests/functional/fmt.sh rename tests/{functional => functional2/cli/assets}/fmt.simple.sh (100%) create mode 100644 tests/functional2/cli/test_fmt.py diff --git a/tests/functional/fmt.sh b/tests/functional/fmt.sh deleted file mode 100644 index 7d6add9b6..000000000 --- a/tests/functional/fmt.sh +++ /dev/null @@ -1,36 +0,0 @@ -source common.sh - -clearStore -rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local - -cp ./simple.nix ./simple.builder.sh ./fmt.simple.sh ./config.nix $TEST_HOME - -cd $TEST_HOME - -nix fmt --help | grep "Format" - -cat << EOF > flake.nix -{ - outputs = _: { - formatter.$system = - with import ./config.nix; - mkDerivation { - name = "formatter"; - buildCommand = '' - mkdir -p \$out/bin - echo "#! ${shell}" > \$out/bin/formatter - cat \${./fmt.simple.sh} >> \$out/bin/formatter - chmod +x \$out/bin/formatter - ''; - }; - }; -} -EOF -# No arguments check -[[ "$(nix fmt)" = "Formatting(0):" ]] -# Argument forwarding check -nix fmt ./file ./folder | grep 'Formatting(2): ./file ./folder' -nix flake check -nix flake show | grep -P "package 'formatter'" - -clearStore diff --git a/tests/functional/meson.build b/tests/functional/meson.build index d8041f9d2..2efb533ee 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -98,7 +98,6 @@ functional_tests_scripts = [ 'pre-hook.sh', 'post-hook.sh', 'function-trace.sh', - 'fmt.sh', 'eval-store.sh', 'derivation-json.sh', 'import-derivation.sh', diff --git a/tests/functional/fmt.simple.sh b/tests/functional2/cli/assets/fmt.simple.sh similarity index 100% rename from tests/functional/fmt.simple.sh rename to tests/functional2/cli/assets/fmt.simple.sh diff --git a/tests/functional2/cli/test_fmt.py b/tests/functional2/cli/test_fmt.py new file mode 100644 index 000000000..39687df20 --- /dev/null +++ b/tests/functional2/cli/test_fmt.py @@ -0,0 +1,53 @@ +from testlib.fixtures.nix import Nix +from testlib.fixtures.file_helper import CopyFile, File, with_files +from testlib.utils import get_global_asset_pack +from testlib.environ import environ + +import pytest + +system = environ.get("system") + + +@with_files( + get_global_asset_pack("simple-drv") + | { + "fmt.simple.sh": CopyFile("assets/fmt.simple.sh"), + "flake.nix": File(f"""{{ + outputs = _: {{ + formatter.{system} = + with import ./config.nix; + mkDerivation {{ + name = "formatter"; + buildCommand = '' + mkdir -p $out/bin + echo "#! ${{shell}}" > $out/bin/formatter + cat ${{./fmt.simple.sh}} >> $out/bin/formatter + chmod +x $out/bin/formatter + ''; + }}; + }}; + }}"""), + } +) +class TestFmt: + @pytest.fixture(autouse=True) + def init(self, nix: Nix): + nix.settings.add_xp_feature("nix-command", "flakes") + + def test_help(self, nix: Nix): + assert "Format" in nix.nix(["fmt", "--help"]).run().ok().stdout_plain + + def test_no_args(self, nix: Nix): + assert nix.nix(["fmt"]).run().ok().stdout_plain == "Formatting(0):" + + def test_forwarding(self, nix: Nix): + assert ( + nix.nix(["fmt", "./file", "./folder"]).run().ok().stdout_plain + == "Formatting(2): ./file ./folder" + ) + + def test_flake_check(self, nix: Nix): + nix.nix(["flake", "check"]).run().ok() + + def test_flake_show(self, nix: Nix): + assert "package 'formatter'" in nix.nix(["flake", "show"]).run().ok().stdout_plain