diff --git a/flake.nix b/flake.nix index f7d64c38..eb807273 100644 --- a/flake.nix +++ b/flake.nix @@ -35,6 +35,24 @@ overrideInputs."haskell-parsers" = ./nix/haskell-parsers; }; + test-simple = { + dir = "test/simple"; + overrideInputs = { + "haskell-flake" = ./.; + "flake-parts" = "github:hercules-ci/flake-parts/7c7a8bce3dffe71203dcd4276504d1cb49dfe05f"; + "nixpkgs" = "github:nixos/nixpkgs/bb31220cca6d044baa6dc2715b07497a2a7c4bc7"; + }; + }; + + test-project-module = { + dir = "test/project-module"; + overrideInputs = { + "haskell-flake" = ./.; + "flake-parts" = "github:hercules-ci/flake-parts/7c7a8bce3dffe71203dcd4276504d1cb49dfe05f"; + "nixpkgs" = "github:nixos/nixpkgs/bb31220cca6d044baa6dc2715b07497a2a7c4bc7"; + }; + }; + # Legacy shell script test test = { dir = "test"; diff --git a/runtest.sh b/runtest.sh index 42680a3b..ff7352bd 100755 --- a/runtest.sh +++ b/runtest.sh @@ -10,9 +10,8 @@ nix --version # TODO: Supplant these scripts with Nix. See https://github.com/srid/haskell-flake/issues/241 TESTS=( ./example - ./test/simple + # TODO: Move these to flake check, just like ./test/{simple, project-module} ./test/with-subdir - ./test/project-module # We run this separately, because it's a bit slow. # ./doc ) diff --git a/test/common.sh b/test/common.sh index 0617f2fc..1f4ee732 100644 --- a/test/common.sh +++ b/test/common.sh @@ -7,7 +7,7 @@ function logHeader { nix --version -SYSTEM=$(nix show-config | grep 'system =' | awk '{print $3}') +SYSTEM=$(nix eval --impure --expr builtins.currentSystem) DIR_OF_COMMON_SH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HASKELL_FLAKE=${DIR_OF_COMMON_SH}/.. diff --git a/test/project-module/test.sh b/test/project-module/test.sh deleted file mode 100755 index 383725fa..00000000 --- a/test/project-module/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -source ../common.sh -set -euxo pipefail - -# First, build the flake -logHeader "Testing nix build" -nix build ${OVERRIDE_ALL} - -logHeader "Testing nix devshell" -nix develop ${OVERRIDE_ALL} -c echo diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 5d337666..5d81e557 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -7,8 +7,6 @@ flake-parts = { }; haskell-flake = { }; - check-flake.url = "github:srid/check-flake/48a17393ed4fcd523399d6602c283775b5127295"; - haskell-multi-nix.url = "github:srid/haskell-multi-nix/7aed736571714ec12105ec110358998d70d59e34"; haskell-multi-nix.flake = false; }; @@ -17,7 +15,6 @@ systems = nixpkgs.lib.systems.flakeExposed; imports = [ inputs.haskell-flake.flakeModule - inputs.check-flake.flakeModule ]; flake.haskellFlakeProjectModules.default = { pkgs, lib, ... }: { packages = { @@ -38,7 +35,6 @@ # Setting to null should remove this tool from defaults. ghcid = null; }; - hlsCheck.enable = true; }; }; perSystem = { self', pkgs, lib, ... }: { @@ -74,6 +70,52 @@ # An explicit app to test `nix run .#test` (*without* falling back to # using self.packages.test) apps.app1 = self'.apps.haskell-flake-test; + + # Our test + checks.test = + pkgs.runCommandNoCC "simple-test" + { + nativeBuildInputs = with pkgs; [ + which + ] ++ self'.devShells.default.nativeBuildInputs; + + # Test defaults.settings module behaviour, viz: haddock + NO_HADDOCK = + lib.assertMsg (!lib.hasAttr "doc" self'.packages.default) + "doc output should not be present"; + } + '' + ( + set -x + echo "Testing test/simple ..." + + # Run the cabal executable as flake app + ${self'.apps.app1.program} | grep fooFunc + + # Setting buildTools.ghcid to null should disable that default + # buildTool (ghcid) + which ghcid && \ + (echo "ghcid should not be in devshell"; exit 2) + + # Adding a buildTool (fzf, here) should put it in devshell. + which fzf || \ + (echo "fzf should be in devshell"; exit 2) + + # mkShellArgs works + ${self'.devShells.default.shellHook} + if [[ "$FOO" == "bar" ]]; then + echo "$FOO" + else + echo "FOO is not bar" + exit 2 + fi + + # extraLibraries works + runghc ${./script} | grep -F 'TOML-flavored boolean: Bool True' + + touch $out + ) + ''; }; }; } diff --git a/test/simple/test-in-devshell.sh b/test/simple/test-in-devshell.sh deleted file mode 100755 index 460add35..00000000 --- a/test/simple/test-in-devshell.sh +++ /dev/null @@ -1,29 +0,0 @@ -# This script is run in a `nix develop` shell by Github Actions. -# -# You can also run it locally using: -# -# nix develop --override-input haskell-flake ../ -c ./test-in-devshell.sh -# -# Or, just run `runtest.sh` from project root. - -set -xe - -# Test haskell devshell (via HLS check) -haskell-language-server - -# Setting buildTools.ghcid to null should disable that default buildTool -which ghcid && exit 2 || echo - -# Adding a buildTool (fzf, here) should put it in devshell. -which fzf - -# mkShellArgs works -if [[ "$FOO" == "bar" ]]; then - echo "$FOO" -else - echo "FOO is not bar" - exit 2 -fi - -# extraLibraries works -runghc ./script | grep -F 'TOML-flavored boolean: Bool True' diff --git a/test/simple/test.sh b/test/simple/test.sh deleted file mode 100755 index 5ff9a596..00000000 --- a/test/simple/test.sh +++ /dev/null @@ -1,27 +0,0 @@ -source ../common.sh -set -euxo pipefail - -rm -f result result-bin - -# First, build the flake -logHeader "Testing nix build" -nix build ${OVERRIDE_ALL} - -# Test defaults.settings module behaviour, viz: haddock -nix build ${OVERRIDE_ALL} .#default^doc && { - echo "ERROR: dontHaddock (from defaults.settings) not in effect" - exit 1 -} - -# Run the devshell test script in a nix develop shell. -logHeader "Testing nix devshell" -nix develop ${OVERRIDE_ALL} -c ./test-in-devshell.sh -# Run the cabal executable as flake app -logHeader "Testing nix flake app (cabal exe)" -nix run ${OVERRIDE_ALL} .#app1 -# Test non-devshell features: -# Checks -logHeader "Testing nix flake checks" -nix --option sandbox false build \ - --no-link --print-out-paths \ - ${OVERRIDE_ALL} -L .#check