From 0cd296f580f95291521750798553e76cba00d91f Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Wed, 7 Aug 2019 11:56:34 -0400 Subject: [PATCH] A test runner --- nixos/tests.nix | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 nixos/tests.nix diff --git a/nixos/tests.nix b/nixos/tests.nix new file mode 100644 index 00000000..f424434d --- /dev/null +++ b/nixos/tests.nix @@ -0,0 +1,35 @@ +# The overall test suite for PrivateStorageio NixOS configuration. +let + pkgs = import <nixpkgs> { }; + + # A helper for loading tests. + loadTest = moduleUnderTest: testModule: + (import testModule (pkgs.callPackage moduleUnderTest { })); + + # A list of tests to run. Manually updated for now, alas. Only tests in + # this list will be run! + testModules = + [ (loadTest ./lib/ini.nix ./lib/tests/test_ini.nix) + ]; + + # Run the tests and collect the failures. + failures = map pkgs.lib.runTests testModules; + + # Count the number of failures in each module. + numFailures = builtins.foldl' (a: b: a + b) 0 (map builtins.length failures); + + # Convert the total into a string for easy interpolation into the shell script. + numFailuresStr = builtins.toString (numFailures); + + # Convert the failure information to a string for reporting. + failuresStr = builtins.toJSON failures; +in +pkgs.runCommand "test-results" {} '' +if [ ${numFailuresStr} -gt 0 ]; then + echo "Failed ${numFailuresStr} tests" + echo '${failuresStr}' + exit 1 +else + echo 'OK' > $out +fi +'' -- GitLab