testing: migrate fmt.sh
Change-Id: Icc593b57a06c7fdf75762094982788f6351dcadc
This commit is contained in:
@@ -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
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user