From 2e73886adcca9ef2bd3da36a25fbfd5adba0f6c1 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 18 Apr 2021 00:07:53 +0200 Subject: [PATCH] nix(refactor): Split memoryTest from tests.nix into memory.nix --- .circleci/config.yml | 2 +- default.nix | 6 +++++- nix/memory.nix | 30 ++++++++++++++++++++++++++++++ nix/tests.nix | 24 +----------------------- shell.nix | 4 ++-- 5 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 nix/memory.nix diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f01c2940..7bc941a49 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -172,7 +172,7 @@ jobs: cachix use postgrest - run: name: Install testing scripts - command: nix-env -f default.nix -iA tests tests.memoryTests withTools + command: nix-env -f default.nix -iA tests memory withTools - run: name: Run coverage (io tests and spec tests against PostgreSQL 13) command: postgrest-coverage diff --git a/default.nix b/default.nix index 51644d900..71e94c938 100644 --- a/default.nix +++ b/default.nix @@ -118,11 +118,15 @@ rec { # Scripts for running tests. tests = pkgs.callPackage nix/tests.nix { - inherit postgrest postgrestProfiled devCabalOptions withTools; + inherit postgrest devCabalOptions withTools; ghc = pkgs.haskell.compiler."${compiler}"; hpc-codecov = pkgs.haskell.packages."${compiler}".hpc-codecov; }; + # Script for running memory tests. + memory = + pkgs.callPackage nix/memory.nix { inherit postgrestProfiled withTools; }; + # Linting and styling scripts. style = pkgs.callPackage nix/style.nix { }; diff --git a/nix/memory.nix b/nix/memory.nix new file mode 100644 index 000000000..4a923ef40 --- /dev/null +++ b/nix/memory.nix @@ -0,0 +1,30 @@ +# The memory tests have large dependencies (a profiled build of PostgREST) +# and are run less often than the spec tests, so we don't include them in +# the default test environment. We make them available through a separate module. +{ buildEnv +, checkedShellScript +, curl +, postgrestProfiled +, withTools +}: +let + test = + checkedShellScript + { + name = "postgrest-test-memory"; + docs = "Run the memory tests."; + inRootDir = true; + } + '' + export PATH="${postgrestProfiled}/bin:${curl}/bin:$PATH" + + ${withTools.latest} test/memory-tests.sh + ''; + +in +buildEnv + { + name = "postgrest-memory"; + + paths = [ test.bin ]; + } // { bashCompletion = test.bashCompletion; } diff --git a/nix/tests.nix b/nix/tests.nix index 016442924..361465136 100644 --- a/nix/tests.nix +++ b/nix/tests.nix @@ -3,7 +3,6 @@ { buildEnv , cabal-install , checkedShellScript -, curl , devCabalOptions , ghc , glibcLocales @@ -11,7 +10,6 @@ , haskell , hpc-codecov , postgrest -, postgrestProfiled , python3 , runtimeShell , withTools @@ -69,19 +67,6 @@ let ${ioTestPython}/bin/pytest -- -v test/io-tests "''${_arg_leftovers[@]}" ''; - testMemory = - checkedShellScript - { - name = "postgrest-test-memory"; - docs = "Run the memory tests."; - inRootDir = true; - } - '' - export PATH="${postgrestProfiled}/bin:${curl}/bin:$PATH" - - ${withTools.latest} test/memory-tests.sh - ''; - dumpSchema = checkedShellScript { @@ -192,11 +177,4 @@ buildEnv "postgrest-tests"; paths = builtins.map (tool: tool.bin) tools; - } // { - inherit bashCompletion; - - # The memory tests have large dependencies (a profiled build of PostgREST) - # and are run less often than the spec tests, so we don't include them in - # the default test environment. We make them available through a separate attribute: - memoryTests = testMemory; -} + } // { inherit bashCompletion; } diff --git a/shell.nix b/shell.nix index 0016865b4..d1b4a33f2 100644 --- a/shell.nix +++ b/shell.nix @@ -41,7 +41,7 @@ lib.overrideDerivation postgrest.env ( postgrest.nixpkgsUpgrade.bin ] ++ modules - ++ lib.optional memoryTests postgrest.tests.memoryTests.bin + ++ lib.optional memoryTests postgrest.memory ++ lib.optional docker postgrest.docker; shellHook = @@ -53,7 +53,7 @@ lib.overrideDerivation postgrest.env ( builtins.map (bashCompletion: "source ${bashCompletion}") ( builtins.concatLists (builtins.map (module: module.bashCompletion) modules) ++ [ postgrest.hsie.bashCompletion postgrest.nixpkgsUpgrade.bashCompletion ] - ++ lib.optional memoryTests postgrest.tests.memoryTests.bashCompletion + ++ lib.optional memoryTests postgrest.memory.bashCompletion ++ lib.optional docker postgrest.docker.bashCompletion )