From db5b1678a3970b1eacd669b8e0f634d88386b2fa Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 21:35:09 +0000 Subject: tests: run scenarios selected by name nix-build tests -A only --argstr only REGEX runs the scenarios whose names match the regular expression REGEX in a single VM test, like the smoke test, e.g. --argstr only 'lock-hooks-.*' for lock-hooks on all three kinds of targets. --- README.md | 1 + tests/default.nix | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b0a5d0..a93c0f6 100644 --- a/README.md +++ b/README.md @@ -765,6 +765,7 @@ nix-build tests -A exhaustive # all exhaustive tests nix-build tests -A exhaustive.git # the remaining combinations of one test nix-build tests -A rsync-3-5-0 # the scenarios depending on rsync's version nix-build tests -A smoke # a few scenarios of each kind, in one VM +nix-build tests -A only --argstr only 'lock-hooks-.*' # scenarios by name ``` Populate is a program in Rust, in `pkgs/populate`, which diff --git a/tests/default.nix b/tests/default.nix index 97b64e0..0e59e26 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -7,8 +7,10 @@ # -A exhaustive, or one with, e.g., nix-build tests -A exhaustive.flake. # The smoke test runs a few scenarios covering each source type and each kind # of target in a single VM test, for checking changes quickly; build it with -# nix-build tests -A smoke. -{ pkgs ? import ../pkgs {} }: +# nix-build tests -A smoke. nix-build tests -A only --argstr only REGEX runs +# the scenarios whose names match the regular expression REGEX in a single +# VM test, e.g. --argstr only 'lock-hooks-.*'. +{ pkgs ? import ../pkgs {}, only ? null }: let # HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically, @@ -72,15 +74,27 @@ let "deploy-local-buildTarget0-etcFlake0-flakefile" "deploy-sudo-allocateTTY" ]; + allScenarios = pkgs.lib.concatLists (builtins.attrValues scenarios); smokeScenarios = let - all = pkgs.lib.concatLists (builtins.attrValues scenarios); - selected = builtins.filter (scenario: builtins.elem scenario.name smokeNames) all; + selected = builtins.filter (scenario: builtins.elem scenario.name smokeNames) allScenarios; missing = pkgs.lib.subtractLists (map (scenario: scenario.name) selected) smokeNames; in if missing != [] then throw "tests: smoke test names missing scenarios: ${toString missing}" else selected; + # The scenarios whose names match the regular expression only. + onlyScenarios = let + selected = builtins.filter + (scenario: builtins.match only scenario.name != null) + allScenarios; + in + if only == null then + throw "tests: -A only needs --argstr only REGEX" + else if selected == [] then + throw "tests: no scenario's name matches ${builtins.toJSON only}" + else + selected; in testsOf false "" # Not built by nix-build tests either, which runs these scenarios anyway. @@ -90,6 +104,11 @@ in name = "smoke"; scenarios = smokeScenarios; }; + only.only = import ./vm.nix { + inherit pkgs gitHead; + name = "only"; + scenarios = onlyScenarios; + }; } # An attribute set without recurseForDerivations, so nix-build tests # doesn't build them. -- cgit v1.3.1