tests.trivial-builders.overriding: update after shellDryRun
This commit is contained in:
parent
f2065d81ad
commit
10ec5da56e
@ -121,18 +121,18 @@ rec {
|
||||
allowSubstitutes = false;
|
||||
}
|
||||
''
|
||||
n=$out${destination}
|
||||
mkdir -p "$(dirname "$n")"
|
||||
target=$out${destination}
|
||||
mkdir -p "$(dirname "$target")"
|
||||
|
||||
if [ -e "$textPath" ]; then
|
||||
mv "$textPath" "$n"
|
||||
mv "$textPath" "$target"
|
||||
else
|
||||
echo -n "$text" > "$n"
|
||||
echo -n "$text" > "$target"
|
||||
fi
|
||||
|
||||
eval "$checkPhase"
|
||||
|
||||
(test -n "$executable" && chmod +x "$n") || true
|
||||
(test -n "$executable" && chmod +x "$target") || true
|
||||
'';
|
||||
|
||||
/*
|
||||
@ -219,7 +219,7 @@ rec {
|
||||
${text}
|
||||
'';
|
||||
checkPhase = ''
|
||||
${stdenv.shellDryRun} $out
|
||||
${stdenv.shellDryRun} "$target"
|
||||
'';
|
||||
};
|
||||
|
||||
@ -246,7 +246,7 @@ rec {
|
||||
${text}
|
||||
'';
|
||||
checkPhase = ''
|
||||
${stdenv.shellDryRun} $out/bin/${name}
|
||||
${stdenv.shellDryRun} "$target"
|
||||
'';
|
||||
};
|
||||
|
||||
@ -295,8 +295,8 @@ rec {
|
||||
checkPhase =
|
||||
if checkPhase == null then ''
|
||||
runHook preCheck
|
||||
${stdenv.shellDryRun} $out/bin/${name}
|
||||
${shellcheck}/bin/shellcheck $out/bin/${name}
|
||||
${stdenv.shellDryRun} "$target"
|
||||
${shellcheck}/bin/shellcheck "$target"
|
||||
runHook postCheck
|
||||
''
|
||||
else checkPhase;
|
||||
|
@ -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
|
||||
'';
|
||||
|
Loading…
Reference in New Issue
Block a user