testing: migrate flakes/inputs.sh
Change-Id: I4446441cb7eea51a42f055f042cceb3e63b84b92
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
source ./common.sh
|
||||
|
||||
requireGit
|
||||
|
||||
|
||||
test_subdir_self_path() {
|
||||
baseDir=$TEST_ROOT/$RANDOM
|
||||
flakeDir=$baseDir/b-low
|
||||
mkdir -p $flakeDir
|
||||
writeSimpleFlake $baseDir
|
||||
writeSimpleFlake $flakeDir
|
||||
|
||||
echo all good > $flakeDir/message
|
||||
cat > $flakeDir/flake.nix <<EOF
|
||||
{
|
||||
outputs = inputs: rec {
|
||||
packages.$system = rec {
|
||||
default =
|
||||
assert builtins.readFile ./message == "all good\n";
|
||||
assert builtins.readFile (inputs.self + "/message") == "all good\n";
|
||||
import ./simple.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
(
|
||||
nix build $baseDir?dir=b-low --no-link
|
||||
)
|
||||
}
|
||||
test_subdir_self_path
|
||||
|
||||
|
||||
test_git_subdir_self_path() {
|
||||
repoDir=$TEST_ROOT/repo-$RANDOM
|
||||
createGitRepo $repoDir
|
||||
flakeDir=$repoDir/b-low
|
||||
mkdir -p $flakeDir
|
||||
writeSimpleFlake $repoDir
|
||||
writeSimpleFlake $flakeDir
|
||||
|
||||
echo all good > $flakeDir/message
|
||||
cat > $flakeDir/flake.nix <<EOF
|
||||
{
|
||||
outputs = inputs: rec {
|
||||
packages.$system = rec {
|
||||
default =
|
||||
assert builtins.readFile ./message == "all good\n";
|
||||
assert builtins.readFile (inputs.self + "/message") == "all good\n";
|
||||
assert inputs.self.outPath == inputs.self.sourceInfo.outPath + "/b-low";
|
||||
import ./simple.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
(
|
||||
cd $flakeDir
|
||||
git add .
|
||||
git commit -m init
|
||||
# nix build
|
||||
)
|
||||
|
||||
clientDir=$TEST_ROOT/client-$RANDOM
|
||||
mkdir -p $clientDir
|
||||
cat > $clientDir/flake.nix <<EOF
|
||||
{
|
||||
inputs.inp = {
|
||||
type = "git";
|
||||
url = "file://$repoDir";
|
||||
dir = "b-low";
|
||||
};
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages = inputs.inp.packages;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix build $clientDir --no-link
|
||||
|
||||
}
|
||||
test_git_subdir_self_path
|
||||
@@ -36,7 +36,6 @@ functional_tests_scripts = [
|
||||
'flakes/develop.sh',
|
||||
'flakes/develop-r8854.sh',
|
||||
'flakes/mercurial.sh',
|
||||
'flakes/inputs.sh',
|
||||
'flakes/follow-paths.sh',
|
||||
'flakes/build-paths.sh',
|
||||
'flakes/flake-in-submodule.sh',
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
from testlib.fixtures.nix import Nix
|
||||
from testlib.fixtures.git import Git
|
||||
from testlib.fixtures.file_helper import with_files, File
|
||||
from testlib.utils import get_global_asset_pack
|
||||
from testlib.environ import environ
|
||||
from pathlib import Path
|
||||
from .common import simple_flake
|
||||
import pytest
|
||||
|
||||
system = environ.get("system")
|
||||
files = simple_flake() | {
|
||||
"b-low": simple_flake()
|
||||
| {
|
||||
"flake.nix": File(f"""{{
|
||||
outputs = inputs: rec {{
|
||||
packages.{system} = rec {{
|
||||
default =
|
||||
assert builtins.readFile ./message == "all good\n";
|
||||
assert builtins.readFile (inputs.self + "/message") == "all good\n";
|
||||
import ./simple.nix;
|
||||
}};
|
||||
}};
|
||||
}}"""),
|
||||
"message": File("all good\n"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def common_init(nix: Nix):
|
||||
nix.settings.add_xp_feature("nix-command", "flakes")
|
||||
|
||||
|
||||
@with_files(files)
|
||||
def test_subdir_self_path(nix: Nix, files: Path):
|
||||
assert "simple> PATH=" in nix.nix(["build", f"{files}/b-low", "--no-link"]).run().ok().stderr_s
|
||||
|
||||
|
||||
@with_files({"repo": files | get_global_asset_pack(".git"), "client": {}})
|
||||
def test_git_subdir_self_path(nix: Nix, files: Path, git: Git):
|
||||
repo_dir = files / "repo"
|
||||
git(repo_dir, "add", ".")
|
||||
git(repo_dir, "commit", "-m", "init")
|
||||
|
||||
client_dir = files / "client"
|
||||
(client_dir / "flake.nix").write_text(f"""{{
|
||||
inputs.inp = {{
|
||||
type = "git";
|
||||
url = "file://{repo_dir}";
|
||||
dir = "b-low";
|
||||
}};
|
||||
|
||||
outputs = inputs: rec {{
|
||||
packages = inputs.inp.packages;
|
||||
}};
|
||||
}}""")
|
||||
|
||||
assert "simple> PATH=" in nix.nix(["build", client_dir, "--no-link"]).run().ok().stderr_s
|
||||
Reference in New Issue
Block a user