From 98419a0f6453a99e9f57da7edcc53d662561a4f2 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 14 Feb 2019 16:55:16 -0500 Subject: [PATCH] nixos/tests/switch-test: Ensures the test fails on failure (#55744) The `| tee` invocation always masked the return value of the switch-to-configuration test. ``` ~ $ false | tee && echo "oh no" oh no ``` The added wrapper script will still output everything to stderr, while passing failures to the test harness. --- nixos/tests/switch-test.nix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index 32010838e67b..0dba3697980f 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -18,8 +18,17 @@ import ./make-test.nix ({ pkgs, ...} : { testScript = {nodes, ...}: let originalSystem = nodes.machine.config.system.build.toplevel; otherSystem = nodes.other.config.system.build.toplevel; + + # Ensures failures pass through using pipefail, otherwise failing to + # switch-to-configuration is hidden by the success of `tee`. + stderrRunner = pkgs.writeScript "stderr-runner" '' + #! ${pkgs.stdenv.shell} + set -e + set -o pipefail + exec env -i "$@" | tee /dev/stderr + ''; in '' - $machine->succeed("env -i ${originalSystem}/bin/switch-to-configuration test | tee /dev/stderr"); - $machine->succeed("env -i ${otherSystem}/bin/switch-to-configuration test | tee /dev/stderr"); + $machine->succeed("${stderrRunner} ${originalSystem}/bin/switch-to-configuration test"); + $machine->succeed("${stderrRunner} ${otherSystem}/bin/switch-to-configuration test"); ''; })