aboutsummaryrefslogtreecommitdiffstats
path: root/tests/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'tests/default.nix')
-rw-r--r--tests/default.nix48
1 files changed, 40 insertions, 8 deletions
diff --git a/tests/default.nix b/tests/default.nix
index 475ab5d..95f3856 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -1,10 +1,10 @@
# NixOS VM tests for krops, with the VM machinery and the scenarios of
# populate's tests, in ../pkgs/populate/tests: deploy, for writeDeploy's
-# arguments to nixos-rebuild, and populate, for pkgs.populate, running
+# arguments to nixos-rebuild, populate, for pkgs.populate, running
# populate's scenarios that expect populate to refuse its arguments, which
# pkgs.populate does during evaluation here, and the scenarios of
# populate's smoke test, with target attribute sets as mkTarget returns
-# them. Build all with nix-build tests, or one with, e.g., nix-build tests
+# them, and pure, for pure evaluation, see ./pure.nix. Build all with nix-build tests, or one with, e.g., nix-build tests
# -A deploy. The exhaustive tests add the combinations of options that no
# code path tells apart from the ones the others cover; build them with
# nix-build tests -A exhaustive. The smoke test runs a few scenarios of
@@ -18,7 +18,7 @@
let
inherit (pkgs) lib;
- krops = import ../lib;
+ krops = import ../lib/with.nix { inherit lib; };
populateTests = ../pkgs/populate/tests;
inherit (import (populateTests + "/fixtures.nix")) gitHead gitFirst;
@@ -38,8 +38,12 @@ let
};
};
+ pure = import ./pure.nix { inherit pkgs; };
+
# A phase runs pkgs.populate, or writeDeploy with a stand-in for
- # nixos-rebuild.
+ # nixos-rebuild, or, if deploy's pure is set, a pure evaluation: of
+ # krops' lib, if it's lib, or of writeDeploy, if it's deploy, running
+ # what that makes.
run = {
source, backup, force, prune, deploy, targetKind, targetPath,
}: let
@@ -47,10 +51,13 @@ let
inherit source backup force prune;
target = targets.${targetKind} targetPath;
};
+ deployArgs = args // { useNixOutputMonitor = false; } // deploy;
in
if deploy == null then pkgs.populate args
- else pkgs.krops.writeDeploy "deploy"
- (args // { useNixOutputMonitor = false; } // deploy);
+ else if deploy.pure or null == "lib" then pure.lib
+ else if deploy.pure or null == "deploy" then
+ pure.deploy (removeAttrs deployArgs [ "pure" ])
+ else pkgs.krops.writeDeploy "deploy" deployArgs;
builderArgs = {
inherit lib run;
@@ -70,12 +77,14 @@ let
# Names of the scenarios of the smoke test, besides populate's.
smokeNames = import (populateTests + "/smoke.nix") ++ [
- "deploy-local-buildTarget0-etcFlake0-flakefile"
+ "pure-lib"
+ "deploy-local-buildTarget0-etcFlake0-flakefile-targetString0"
+ "deploy-remote-buildTarget0-etcFlake0-flakenone-targetString1"
"deploy-sudo-allocateTTY"
];
scenarios = {
- inherit (kropsScenarios) deploy;
+ inherit (kropsScenarios) deploy pure;
populate = builtins.filter
(scenario: scenario.refusals || builtins.elem scenario.name smokeNames)
populateScenarios;
@@ -125,10 +134,33 @@ let
throw "tests: no scenario's name matches ${builtins.toJSON only}"
else
selected;
+ # The version of krops the README's example fetches, which is the
+ # CHANGELOG's newest, or, with unreleased changes, at least the newest
+ # released, so a release can't leave the README behind. The README can't
+ # name the release's hash, which covers the README.
+ checkReadmeVersion = let
+ lines = file: lib.splitString "\n" (builtins.readFile file);
+ matches = regex: file: lib.concatMap
+ (line: let m = builtins.match regex line; in
+ if m == null then [] else m)
+ (lines file);
+ readme = matches ''.*rev = "refs/tags/v([0-9.]+)";.*'' ../README.md;
+ headings = matches "## (.*)" ../CHANGELOG.md;
+ newest = lib.findFirst (heading: heading != "Unreleased") null headings;
+ in
+ if builtins.length readme != 1 then
+ throw "tests: README.md doesn't name one version of krops to fetch"
+ else if lib.head headings == "Unreleased" then
+ builtins.compareVersions (lib.head readme) newest >= 0 ||
+ throw "tests: README.md fetches krops ${lib.head readme}, older than the newest release in CHANGELOG.md, ${newest}"
+ else
+ lib.head readme == newest ||
+ throw "tests: README.md fetches krops ${lib.head readme}, but the newest release in CHANGELOG.md is ${newest}";
in
# The remote target must not count as local wherever this gets evaluated.
assert !(krops.isLocalTarget (targets.remote "/"));
+assert checkReadmeVersion;
testsOf false ""
# Not built by nix-build tests either, which runs these scenarios anyway.