testing: migrate flakes/mercurial.sh

hg is *so fucking slow* omfw

Change-Id: I0f4d1d2a546a75f965ff017c9451fb1d441990b1
This commit is contained in:
eldritch horrors
2026-02-22 20:46:06 +00:00
parent 7a3f352105
commit c2b61c5da3
4 changed files with 140 additions and 45 deletions
-43
View File
@@ -1,43 +0,0 @@
source ./common.sh
[[ $(type -p hg) ]] || skipTest "Mercurial not installed"
flake1Dir=$TEST_ROOT/flake-hg1
mkdir -p $flake1Dir
writeSimpleFlake $flake1Dir
hg init $flake1Dir
nix registry add --registry $registry flake1 hg+file://$flake1Dir
flake2Dir=$TEST_ROOT/flake-hg2
mkdir -p $flake2Dir
writeDependentFlake $flake2Dir
hg init $flake2Dir
hg add $flake1Dir/*
hg commit --config ui.username=foobar@example.org $flake1Dir -m 'Initial commit'
hg add $flake2Dir/flake.nix
hg commit --config ui.username=foobar@example.org $flake2Dir -m 'Initial commit'
nix build -o $TEST_ROOT/result hg+file://$flake2Dir
[[ -e $TEST_ROOT/result/hello ]]
(! nix flake metadata --json hg+file://$flake2Dir | jq -e -r .revision)
nix eval hg+file://$flake2Dir#expr
nix eval hg+file://$flake2Dir#expr
(! nix eval hg+file://$flake2Dir#expr --no-allow-dirty)
(! nix flake metadata --json hg+file://$flake2Dir | jq -e -r .revision)
hg commit --config ui.username=foobar@example.org $flake2Dir -m 'Add lock file'
nix flake metadata --json hg+file://$flake2Dir --refresh | jq -e -r .revision
nix flake metadata --json hg+file://$flake2Dir
[[ $(nix flake metadata --json hg+file://$flake2Dir | jq -e -r .revCount) = 2 ]]
nix build -o $TEST_ROOT/result hg+file://$flake2Dir --no-registries --no-allow-dirty
nix build -o $TEST_ROOT/result hg+file://$flake2Dir --no-use-registries --no-allow-dirty
-1
View File
@@ -33,7 +33,6 @@ functional_tests_scripts = [
'init.sh',
'test-infra.sh',
'flakes/flakes.sh',
'flakes/mercurial.sh',
'flakes/follow-paths.sh',
'gc.sh',
'nix-collect-garbage-d.sh',
+12 -1
View File
@@ -1,4 +1,4 @@
from testlib.utils import FileDeclaration, get_global_asset_pack, CopyTemplate
from testlib.utils import FileDeclaration, get_global_asset_pack, CopyTemplate, File
from testlib.environ import environ
@@ -6,3 +6,14 @@ def simple_flake() -> FileDeclaration:
return get_global_asset_pack("simple-drv") | {
"flake.nix": CopyTemplate("assets/simple-flake.nix", {"system": environ.get("system")})
}
def dependent_flake() -> FileDeclaration:
return {
"flake.nix": File(f"""{{
outputs = {{ self, flake1 }}: {{
packages.{environ.get("system")}.default = flake1.packages.{environ.get("system")}.default;
expr = assert builtins.pathExists ./flake.lock; 123;
}};
}}""")
}
+128
View File
@@ -0,0 +1,128 @@
from testlib.fixtures.nix import Nix
from testlib.fixtures.command import Command, CommandResult
from testlib.fixtures.file_helper import with_files
from testlib.fixtures.env import ManagedEnv
from testlib.environ import environ
from pathlib import Path
import pytest
from .common import simple_flake, dependent_flake
from collections.abc import Callable
import glob
system = environ.get("system")
files = {"flake-hg1": simple_flake(), "flake-hg2": dependent_flake()}
type Hg = Callable[..., CommandResult]
@pytest.fixture
def hg(env: ManagedEnv, command: Callable[..., Command]) -> Hg:
env.path.add_program("hg")
def wrap(*args, **kwargs) -> CommandResult:
return command(["hg", *args], **kwargs).run().ok()
return wrap
@pytest.fixture(autouse=True)
def common_init(nix: Nix, files: Path, hg: Hg):
nix.settings.add_xp_feature("nix-command", "flakes")
nix.settings.flake_registry = str(nix.env.dirs.test_root / "registry.json")
hg("init", files / "flake-hg1")
nix.nix(
[
"registry",
"add",
"--registry",
nix.settings.flake_registry,
"flake1",
f"hg+file://{files}/flake-hg1",
]
).run().ok()
hg("init", files / "flake-hg2")
hg("add", *glob.glob(str(files / "flake-hg1/*"))) # noqa PTH207: Path.glob *does the wrong thing*
hg(
"commit",
"--config",
"ui.username=foobar@example.org",
files / "flake-hg1",
"-m",
"Initial commit",
)
hg("add", files / "flake-hg2/flake.nix")
hg(
"commit",
"--config",
"ui.username=foobar@example.org",
files / "flake-hg2",
"-m",
"Initial commit",
)
@with_files(files)
class TestFlakeHg:
def test_build(self, nix: Nix, files: Path):
nix.nix(["build", f"hg+file://{files}/flake-hg2"]).run().ok()
assert (nix.env.dirs.home / "result/hello").exists()
def test_metadata_dirty(self, nix: Nix, files: Path):
metadata = (
nix.nix(["flake", "metadata", "--json", f"hg+file://{files}/flake-hg2"]).run().json()
)
assert "revision" not in metadata
def test_eval(self, nix: Nix, files: Path):
result = nix.nix(["eval", f"hg+file://{files}/flake-hg2#expr"]).run().ok()
assert result.stdout_s == "123\n"
def test_eval_no_dirty(self, nix: Nix, files: Path):
result = (
nix.nix(["eval", f"hg+file://{files}/flake-hg2#expr", "--no-allow-dirty"])
.run()
.expect(1)
)
assert "is unclean" in result.stderr_s
class TestLocked:
@pytest.fixture(autouse=True)
def init(self, nix: Nix, files: Path, hg: Hg):
nix.nix(["flake", "lock", f"hg+file://{files}/flake-hg2"]).run().ok()
hg(
"commit",
"--config",
"ui.username=foobar@example.org",
files / "flake-hg2",
"-m",
"Add lock file",
)
def test_metadata_clean(self, nix: Nix, files: Path):
metadata = (
nix.nix(["flake", "metadata", "--json", f"hg+file://{files}/flake-hg2"])
.run()
.json()
)
assert "revision" in metadata
def test_metadata_refresh(self, nix: Nix, files: Path):
metadata = (
nix.nix(
["flake", "metadata", "--json", f"hg+file://{files}/flake-hg2", "--refresh"]
)
.run()
.json()
)
assert "revision" in metadata
assert metadata["revCount"] == 2
@pytest.mark.parametrize("arg", ["--no-registries", "--no-use-registries"])
def test_build(self, nix: Nix, files: Path, arg: str):
nix.nix(["build", f"hg+file://{files}/flake-hg2", arg, "--no-allow-dirty"]).run().ok()
assert (nix.env.dirs.home / "result/hello").exists()