From 39d4646a4c41d5f74c1a8ffb3c196aab4708ff5e Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 17 Apr 2021 13:08:55 +0200 Subject: [PATCH] nix(refactor): Add withEnv to checked-shell-script --- .../checked-shell-script.nix | 12 +++++++++++- nix/tests.nix | 19 +++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/nix/overlays/checked-shell-script/checked-shell-script.nix b/nix/overlays/checked-shell-script/checked-shell-script.nix index 907555983..fc46b8c89 100644 --- a/nix/overlays/checked-shell-script/checked-shell-script.nix +++ b/nix/overlays/checked-shell-script/checked-shell-script.nix @@ -9,8 +9,14 @@ , stdenv , writeTextFile }: -{ name, docs, inRootDir ? false, redirectTixFiles ? true, withTmpDir ? false }: text: # TODO: do something sensible with docs, e.g. provide automated --help +{ name +, docs +, inRootDir ? false +, redirectTixFiles ? true +, withEnv ? null +, withTmpDir ? false +}: text: let bin = writeTextFile { @@ -46,6 +52,10 @@ let # remove the tmpdir when cancelled (postgrest-watch) trap 'rm -rf "$tmpdir"' SIGINT SIGTERM '' + + lib.optionalString (withEnv != null) '' + env="$(cat ${withEnv})" + export PATH="$env/bin:$PATH" + '' + "(${text})" + lib.optionalString withTmpDir '' diff --git a/nix/tests.nix b/nix/tests.nix index caf44b01b..6db7e6268 100644 --- a/nix/tests.nix +++ b/nix/tests.nix @@ -24,11 +24,9 @@ let name = "postgrest-test-spec"; docs = "Run the Haskell test suite"; inRootDir = true; + withEnv = postgrest.env; } '' - env="$(cat ${postgrest.env})" - export PATH="$env/bin:$PATH" - ${withTools.latest} ${cabal-install}/bin/cabal v2-test ${devCabalOptions} ''; @@ -38,11 +36,9 @@ let name = "postgrest-test-spec-idempotence"; docs = "Check that the Haskell tests can be run multiple times against the same db."; inRootDir = true; + withEnv = postgrest.env; } '' - env="$(cat ${postgrest.env})" - export PATH="$env/bin:$PATH" - ${withTools.latest} ${runtimeShell} -c " \ ${cabal-install}/bin/cabal v2-test ${devCabalOptions} && \ ${cabal-install}/bin/cabal v2-test ${devCabalOptions}" @@ -64,11 +60,9 @@ let name = "postgrest-test-io"; docs = "Run the pytest-based IO tests."; inRootDir = true; + withEnv = postgrest.env; } '' - env="$(cat ${postgrest.env})" - export PATH="$env/bin:$PATH" - ${cabal-install}/bin/cabal v2-build ${devCabalOptions} ${cabal-install}/bin/cabal v2-exec ${withTools.latest} \ ${ioTestPython}/bin/pytest -- -v test/io-tests "$@" @@ -93,11 +87,9 @@ let name = "postgrest-dump-schema"; docs = "Dump the loaded schema's DbStructure as a yaml file."; inRootDir = true; + withEnv = postgrest.env; } '' - env="$(cat ${postgrest.env})" - export PATH="$env/bin:$PATH" - ${withTools.latest} \ ${cabal-install}/bin/cabal v2-run ${devCabalOptions} --verbose=0 -- \ postgrest --dump-schema \ @@ -111,11 +103,10 @@ let docs = "Run spec and io tests while collecting hpc coverage data."; inRootDir = true; redirectTixFiles = false; + withEnv = postgrest.env; withTmpDir = true; } '' - env="$(cat ${postgrest.env})" - export PATH="$env/bin:$PATH" export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" # clean up previous coverage reports