summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2021-12-19 23:29:07 +0100
committerRaphael Megzari <raphael@megzari.com>2021-12-27 20:30:01 -0500
commit10ec5da56e9932501104f39c3ca351a93d734053 (patch)
tree295cd3f10dfd57a257de1d3d852fbcd3c3397041 /pkgs/build-support/trivial-builders
parentf2065d81ad9d25bbe581aef5c4c80845d7bb3041 (diff)
downloadnixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar.gz
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar.bz2
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar.lz
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar.xz
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.tar.zst
nixpkgs-10ec5da56e9932501104f39c3ca351a93d734053.zip
tests.trivial-builders.overriding: update after shellDryRun
Diffstat (limited to 'pkgs/build-support/trivial-builders')
-rw-r--r--pkgs/build-support/trivial-builders/test-overriding.nix63
1 files changed, 27 insertions, 36 deletions
diff --git a/pkgs/build-support/trivial-builders/test-overriding.nix b/pkgs/build-support/trivial-builders/test-overriding.nix
index ddd5dc05075..a16bbbee1b1 100644
--- a/pkgs/build-support/trivial-builders/test-overriding.nix
+++ b/pkgs/build-support/trivial-builders/test-overriding.nix
@@ -1,10 +1,11 @@
 # Check that overriding works for trivial-builders like
 # `writeShellScript` via `overrideAttrs`. This is useful
-# to override the `checkPhase`, e. g. when you want
-# to enable extglob in `writeShellScript`.
+# to override the `checkPhase`, e. g. if you want
+# to disable extglob in `writeShellScript`.
 #
-# Run using `nix-build -A tests.trivial-overriding`.
+# Run using `nix-build -A tests.trivial-builders.overriding`.
 { lib
+, stdenv
 , runtimeShell
 , runCommand
 , callPackage
@@ -21,33 +22,6 @@ let
     rm success
   '';
 
-  # Reuse the old `checkPhase` of `writeShellScript`, but enable extglob.
-  allowExtglob = old: {
-    checkPhase = ''
-      # make sure we don't change the settings for
-      # the rest of the derivation's build
-      (
-        export BASHOPTS
-        shopt -s extglob
-        ${old.checkPhase}
-      )
-    '';
-  };
-
-  # Run old checkPhase, but only succeed if it fails.
-  # This HACK is required because we can't introspect build failures
-  # in nix: With `assertFail` we want to make sure that the default
-  # `checkPhase` would fail if extglob was used in the script.
-  assertFail = old: {
-    # write old checkPhase into a shell script, so we can check for
-    # the phase to fail even though we have `set -e`.
-    checkPhase = ''
-      if source ${writeShellScript "old-check-phase" old.checkPhase} 2>/dev/null; then
-        exit 1
-      fi
-    '';
-  };
-
   simpleCase = case:
     writeShellScript "test-trivial-overriding-${case}" extglobScript;
 
@@ -70,16 +44,33 @@ let
     executable = true;
   };
 
-  mkCase = f: type: isBin:
+    disallowExtglob = x: x.overrideAttrs (_: {
+      checkPhase = ''
+        ${stdenv.shell} -n "$target"
+      '';
+    });
+
+    # Run old checkPhase, but only succeed if it fails.
+    # This HACK is required because we can't introspect build failures
+    # in nix: With `assertFail` we want to make sure that the default
+    # `checkPhase` would fail if extglob was used in the script.
+    assertFail = x: x.overrideAttrs (old: {
+      checkPhase = ''
+        if
+          ${old.checkPhase}
+        then exit 1; fi
+      '';
+    });
+
+  mkCase = case: outcome: isBin:
     let
-      drv = (f type).overrideAttrs
-        (if type == "succ" then allowExtglob else assertFail);
+      drv = lib.pipe outcome ([ case ] ++ lib.optionals (outcome == "fail") [ disallowExtglob assertFail ]);
     in if isBin then "${drv}/bin/${drv.name}" else drv;
 
   writeTextOverrides = {
-    # Enabling globbing in checkPhase
+    # Make sure extglob works by default
     simpleSucc = mkCase simpleCase "succ" false;
-    # Ensure it's possible to fail; in this case globbing is not enabled.
+    # Ensure it's possible to fail; in this case extglob is not enabled
     simpleFail = mkCase simpleCase "fail" false;
     # Do the same checks after wrapping with callPackage
     # to make sure callPackage doesn't mess with the override
@@ -103,7 +94,7 @@ let
       name = script.name or (builtins.baseNameOf script);
     in writeShellScript "run-${name}" ''
       if [ "$(${script})" != "success" ]; then
-        echo "Failed in ${script}"
+        echo "Failed in ${name}"
         exit 1
       fi
     '';