diff --git a/tests/functional/flakes/run.sh b/tests/functional/flakes/run.sh deleted file mode 100644 index 10595ea12..000000000 --- a/tests/functional/flakes/run.sh +++ /dev/null @@ -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 < 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 diff --git a/tests/functional/meson.build b/tests/functional/meson.build index c76731c68..14dfb494a 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -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', diff --git a/tests/functional2/flakes/assets/run/flake.nix b/tests/functional2/flakes/assets/run/flake.nix new file mode 100644 index 000000000..31089f8b8 --- /dev/null +++ b/tests/functional2/flakes/assets/run/flake.nix @@ -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"; + }; + }; +} diff --git a/tests/functional2/flakes/test_run.py b/tests/functional2/flakes/test_run.py new file mode 100644 index 000000000..554da2e16 --- /dev/null +++ b/tests/functional2/flakes/test_run.py @@ -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 + ) diff --git a/tests/functional2/testlib/global_assets/shell-hello.nix b/tests/functional2/testlib/global_assets/shell-hello.nix new file mode 100644 index 000000000..dfe66ef93 --- /dev/null +++ b/tests/functional2/testlib/global_assets/shell-hello.nix @@ -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 < $dev/bin/hello2 < $out/bin/hello <