From 4f6a6cb5be24a83603e07d0d09b257a9f115dcf0 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Tue, 7 Jun 2022 09:45:53 +0200 Subject: [PATCH 1/4] nix: pass through hspec arguments to postgrest-test-spec This allows e.g. running postgrest-test-spec --match "some failing test" --- nix/tools/tests.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index 0dc1dfc2df..e8c66bfe72 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -20,11 +20,13 @@ let { name = "postgrest-test-spec"; docs = "Run the Haskell test suite"; + args = [ "ARG_LEFTOVERS([hspec arguments])" ]; inRootDir = true; withEnv = postgrest.env; } '' - ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:spec + ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} \ + test:spec -- "''${_arg_leftovers[@]}" ''; testQuerycost = From 9e0be1eb9030a4c5b40a0d623058f65d6e4892cd Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 3 Jun 2022 15:38:56 +0200 Subject: [PATCH 2/4] nix: use the matching weeder weeder needs to be compiled with the same GHC that we build postgrest with. Before this change, we were relying on the fact that we happened to set ${compiler} to the same ghc8107 as used by nixpkgs for haskellPackages, now we explicitly take it from the correct haskell package set. --- default.nix | 1 + nix/tools/tests.nix | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index a484819a67..52c9ea7055 100644 --- a/default.nix +++ b/default.nix @@ -149,6 +149,7 @@ rec { inherit postgrest devCabalOptions withTools; ghc = pkgs.haskell.compiler."${compiler}"; inherit (pkgs.haskell.packages."${compiler}") hpc-codecov; + inherit (pkgs.haskell.packages."${compiler}") weeder; }; withTools = diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index e8c66bfe72..e04df8a547 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -5,12 +5,12 @@ , ghc , glibcLocales , gnugrep -, haskellPackages , hpc-codecov , jq , postgrest , python3 , runtimeShell +, weeder , withTools , yq }: @@ -137,7 +137,7 @@ let ( trap 'echo Found dead code: Check file list above.' ERR ; - ${haskellPackages.weeder}/bin/weeder --config=./test/weeder.dhall + ${weeder}/bin/weeder --config=./test/weeder.dhall ) # collect all tests From e5caa986e274181a4a572f1b5b150340f33959f3 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Fri, 3 Jun 2022 16:02:11 +0200 Subject: [PATCH 3/4] nix: test script without glibc locales glibcLocales is not available e.g. on darwin. This change allows running various dev tools on darwin, and other theoretical non-glibc systems. --- nix/tools/tests.nix | 130 +++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index e04df8a547..bf534617c7 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -3,13 +3,16 @@ , checkedShellScript , devCabalOptions , ghc -, glibcLocales +, glibcLocales ? null , gnugrep , hpc-codecov +, hostPlatform , jq +, lib , postgrest , python3 , runtimeShell +, stdenv , weeder , withTools , yq @@ -125,67 +128,72 @@ let withEnv = postgrest.env; withTmpDir = true; } - '' - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" - - # clean up previous coverage reports - mkdir -p coverage - rm -rf coverage/* - - # build once before running all the tests - ${cabal-install}/bin/cabal v2-build ${devCabalOptions} exe:postgrest lib:postgrest test:spec test:querycost - - ( - trap 'echo Found dead code: Check file list above.' ERR ; - ${weeder}/bin/weeder --config=./test/weeder.dhall - ) - - # collect all tests - HPCTIXFILE="$tmpdir"/io.tix \ - ${withTools.withPg} -f test/io/fixtures.sql ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- \ - ${ioTestPython}/bin/pytest -v test/io + ( + # required for `hpc markup` in CI; glibcLocales is not available e.g. on Darwin + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' + export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" + '' + + + '' + # clean up previous coverage reports + mkdir -p coverage + rm -rf coverage/* + + # build once before running all the tests + ${cabal-install}/bin/cabal v2-build ${devCabalOptions} exe:postgrest lib:postgrest test:spec test:querycost + + ( + trap 'echo Found dead code: Check file list above.' ERR ; + ${weeder}/bin/weeder --config=./test/weeder.dhall + ) + + # collect all tests + HPCTIXFILE="$tmpdir"/io.tix \ + ${withTools.withPg} -f test/io/fixtures.sql ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- \ + ${ioTestPython}/bin/pytest -v test/io - HPCTIXFILE="$tmpdir"/spec.tix \ - ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:spec - - HPCTIXFILE="$tmpdir"/querycost.tix \ - ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:querycost - - # Note: No coverage for doctests, as doctests leverage GHCi and GHCi does not support hpc - - # collect all the tix files - ${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix \ - "$tmpdir"/io*.tix "$tmpdir"/spec.tix "$tmpdir"/querycost.tix - - # prepare the overlay - ${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay - ${ghc}/bin/hpc sum --union --output="$tmpdir"/tests-overlay.tix "$tmpdir"/tests.tix "$tmpdir"/overlay.tix - - # check nothing in the overlay is actually tested - ${ghc}/bin/hpc map --function=inv --output="$tmpdir"/inverted.tix "$tmpdir"/tests.tix - ${ghc}/bin/hpc combine --function=sub \ - --output="$tmpdir"/check.tix "$tmpdir"/overlay.tix "$tmpdir"/inverted.tix - # returns zero exit code if any count="" lines are found, i.e. - # something is covered by both the overlay and the tests - if ${ghc}/bin/hpc report --xml "$tmpdir"/check.tix | ${gnugrep}/bin/grep -qP 'count="[^0]' - then - ${ghc}/bin/hpc markup --highlight-covered --destdir=coverage/overlay "$tmpdir"/overlay.tix || true - ${ghc}/bin/hpc markup --highlight-covered --destdir=coverage/check "$tmpdir"/check.tix || true - echo "ERROR: Something is covered by both the tests and the overlay:" - echo "file://$(pwd)/coverage/check/hpc_index.html" - exit 1 - else - # copy the result .tix file to the coverage/ dir to make it available to postgrest-coverage-draft-overlay, too - cp "$tmpdir"/tests-overlay.tix coverage/postgrest.tix - # prepare codecov json report - ${hpc-codecov}/bin/hpc-codecov --mix=.hpc --out=coverage/codecov.json coverage/postgrest.tix - - # create html and stdout reports - ${ghc}/bin/hpc markup --destdir=coverage coverage/postgrest.tix - echo "file://$(pwd)/coverage/hpc_index.html" - ${ghc}/bin/hpc report coverage/postgrest.tix "''${_arg_leftovers[@]}" - fi - ''; + HPCTIXFILE="$tmpdir"/spec.tix \ + ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:spec + + HPCTIXFILE="$tmpdir"/querycost.tix \ + ${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:querycost + + # Note: No coverage for doctests, as doctests leverage GHCi and GHCi does not support hpc + + # collect all the tix files + ${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix \ + "$tmpdir"/io*.tix "$tmpdir"/spec.tix "$tmpdir"/querycost.tix + + # prepare the overlay + ${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay + ${ghc}/bin/hpc sum --union --output="$tmpdir"/tests-overlay.tix "$tmpdir"/tests.tix "$tmpdir"/overlay.tix + + # check nothing in the overlay is actually tested + ${ghc}/bin/hpc map --function=inv --output="$tmpdir"/inverted.tix "$tmpdir"/tests.tix + ${ghc}/bin/hpc combine --function=sub \ + --output="$tmpdir"/check.tix "$tmpdir"/overlay.tix "$tmpdir"/inverted.tix + # returns zero exit code if any count="" lines are found, i.e. + # something is covered by both the overlay and the tests + if ${ghc}/bin/hpc report --xml "$tmpdir"/check.tix | ${gnugrep}/bin/grep -qP 'count="[^0]' + then + ${ghc}/bin/hpc markup --highlight-covered --destdir=coverage/overlay "$tmpdir"/overlay.tix || true + ${ghc}/bin/hpc markup --highlight-covered --destdir=coverage/check "$tmpdir"/check.tix || true + echo "ERROR: Something is covered by both the tests and the overlay:" + echo "file://$(pwd)/coverage/check/hpc_index.html" + exit 1 + else + # copy the result .tix file to the coverage/ dir to make it available to postgrest-coverage-draft-overlay, too + cp "$tmpdir"/tests-overlay.tix coverage/postgrest.tix + # prepare codecov json report + ${hpc-codecov}/bin/hpc-codecov --mix=.hpc --out=coverage/codecov.json coverage/postgrest.tix + + # create html and stdout reports + ${ghc}/bin/hpc markup --destdir=coverage coverage/postgrest.tix + echo "file://$(pwd)/coverage/hpc_index.html" + ${ghc}/bin/hpc report coverage/postgrest.tix "''${_arg_leftovers[@]}" + fi + '' + ); coverageDraftOverlay = checkedShellScript From b00fa3925e24927c7efebef2e80f344acb43dce7 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Tue, 7 Jun 2022 10:23:39 +0200 Subject: [PATCH 4/4] nix: don't write to /nix/store from hsie build (fixes #2304) This is a kind of hacky fix to the kind of hacky hsie derivation. --- nix/hsie/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nix/hsie/default.nix b/nix/hsie/default.nix index cb627dcaea..f0809c99ae 100644 --- a/nix/hsie/default.nix +++ b/nix/hsie/default.nix @@ -16,7 +16,12 @@ let ghc = ghcWithPackages modules; hsie = runCommand "haskellimports" { inherit name src; } - "${ghc}/bin/ghc -O -Werror -Wall -package ghc $src -o $out"; + '' + cd $TMP + cp $src $TMP/Main.hs + ${ghc}/bin/ghc -O -Werror -Wall -package ghc Main.hs -o Main + cp Main $out + ''; bin = runCommand name { inherit hsie name; } ''