testing: migrate flakes/run.sh
Change-Id: Id953cd257c3831d67531ffa4a131607519361227
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
source ../common.sh
|
||||
|
||||
clearStore
|
||||
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
||||
cp ../shell-hello.nix ../config.nix $TEST_HOME
|
||||
cd $TEST_HOME
|
||||
|
||||
cat <<EOF > flake.nix
|
||||
{
|
||||
outputs = {self}: {
|
||||
packages.$system.pkgAsPkg = (import ./shell-hello.nix).hello;
|
||||
packages.$system.appAsApp = self.packages.$system.appAsApp;
|
||||
|
||||
apps.$system.pkgAsApp = self.packages.$system.pkgAsPkg;
|
||||
apps.$system.appAsApp = {
|
||||
type = "app";
|
||||
program = "\${(import ./shell-hello.nix).hello}/bin/hello";
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix run --no-write-lock-file .#appAsApp
|
||||
nix run --no-write-lock-file .#pkgAsPkg
|
||||
|
||||
! nix run --no-write-lock-file .#pkgAsApp || fail "'nix run' shouldn’t accept an 'app' defined under 'packages'"
|
||||
! nix run --no-write-lock-file .#appAsPkg || fail "elements of 'apps' should be of type 'app'"
|
||||
|
||||
clearStore
|
||||
@@ -35,7 +35,6 @@ functional_tests_scripts = [
|
||||
'flakes/flakes.sh',
|
||||
'flakes/develop.sh',
|
||||
'flakes/develop-r8854.sh',
|
||||
'flakes/run.sh',
|
||||
'flakes/mercurial.sh',
|
||||
'flakes/circular.sh',
|
||||
'flakes/init.sh',
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
outputs = {self}: {
|
||||
packages.@system@.pkgAsPkg = (import ./shell-hello.nix).hello;
|
||||
packages.@system@.pkgAsApp = self.apps.@system@.appAsApp;
|
||||
|
||||
apps.@system@.appAsPkg = self.packages.@system@.pkgAsPkg;
|
||||
apps.@system@.appAsApp = {
|
||||
type = "app";
|
||||
program = "${(import ./shell-hello.nix).hello}/bin/hello";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
from testlib.fixtures.nix import Nix
|
||||
from testlib.fixtures.file_helper import with_files
|
||||
from testlib.utils import get_global_asset, CopyTemplate
|
||||
from testlib.environ import environ
|
||||
import pytest
|
||||
|
||||
|
||||
@with_files(
|
||||
{
|
||||
"shell-hello.nix": get_global_asset("shell-hello.nix"),
|
||||
"config.nix": get_global_asset("config.nix"),
|
||||
"flake.nix": CopyTemplate("assets/run/flake.nix", {"system": environ.get("system")}),
|
||||
}
|
||||
)
|
||||
class TestFlakeRun:
|
||||
@pytest.mark.parametrize("attr", ["appAsApp", "pkgAsPkg"])
|
||||
def test_run_succeeds(self, nix: Nix, attr: str):
|
||||
assert (
|
||||
"Hello World"
|
||||
in nix.nix(["run", "--no-write-lock-file", f".#{attr}"], flake=True).run().ok().stdout_s
|
||||
)
|
||||
|
||||
def test_run_pkg_as_app(self, nix: Nix):
|
||||
assert (
|
||||
"should have type 'derivation'"
|
||||
in nix.nix(["run", "--no-write-lock-file", ".#pkgAsApp"], flake=True)
|
||||
.run()
|
||||
.expect(1)
|
||||
.stderr_s
|
||||
)
|
||||
|
||||
def test_run_app_as_pkg(self, nix: Nix):
|
||||
assert (
|
||||
"should have type 'app'"
|
||||
in nix.nix(["run", "--no-write-lock-file", ".#appAsPkg"], flake=True)
|
||||
.run()
|
||||
.expect(1)
|
||||
.stderr_s
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
with import ./config.nix;
|
||||
|
||||
{
|
||||
hello = mkDerivation {
|
||||
name = "hello";
|
||||
outputs = [ "out" "dev" ];
|
||||
meta.outputsToInstall = [ "out" ];
|
||||
buildCommand =
|
||||
''
|
||||
mkdir -p $out/bin $dev/bin
|
||||
|
||||
cat > $out/bin/hello <<EOF
|
||||
#! ${shell}
|
||||
who=\$1
|
||||
echo "Hello \''${who:-World} from $out/bin/hello"
|
||||
EOF
|
||||
chmod +x $out/bin/hello
|
||||
|
||||
cat > $dev/bin/hello2 <<EOF
|
||||
#! ${shell}
|
||||
echo "Hello2"
|
||||
EOF
|
||||
chmod +x $dev/bin/hello2
|
||||
'';
|
||||
};
|
||||
|
||||
salve-mundi = mkDerivation {
|
||||
name = "salve-mundi";
|
||||
outputs = [ "out" ];
|
||||
meta.outputsToInstall = [ "out" ];
|
||||
buildCommand =
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
|
||||
cat > $out/bin/hello <<EOF
|
||||
#! ${shell}
|
||||
echo "Salve Mundi from $out/bin/hello"
|
||||
EOF
|
||||
chmod +x $out/bin/hello
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user