tests.trivial-builders.overriding: update after shellDryRun
This commit is contained in:
parent
f2065d81ad
commit
10ec5da56e
|
@ -121,18 +121,18 @@ rec {
|
||||||
allowSubstitutes = false;
|
allowSubstitutes = false;
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
n=$out${destination}
|
target=$out${destination}
|
||||||
mkdir -p "$(dirname "$n")"
|
mkdir -p "$(dirname "$target")"
|
||||||
|
|
||||||
if [ -e "$textPath" ]; then
|
if [ -e "$textPath" ]; then
|
||||||
mv "$textPath" "$n"
|
mv "$textPath" "$target"
|
||||||
else
|
else
|
||||||
echo -n "$text" > "$n"
|
echo -n "$text" > "$target"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval "$checkPhase"
|
eval "$checkPhase"
|
||||||
|
|
||||||
(test -n "$executable" && chmod +x "$n") || true
|
(test -n "$executable" && chmod +x "$target") || true
|
||||||
'';
|
'';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -219,7 +219,7 @@ rec {
|
||||||
${text}
|
${text}
|
||||||
'';
|
'';
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
${stdenv.shellDryRun} $out
|
${stdenv.shellDryRun} "$target"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ rec {
|
||||||
${text}
|
${text}
|
||||||
'';
|
'';
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
${stdenv.shellDryRun} $out/bin/${name}
|
${stdenv.shellDryRun} "$target"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -295,8 +295,8 @@ rec {
|
||||||
checkPhase =
|
checkPhase =
|
||||||
if checkPhase == null then ''
|
if checkPhase == null then ''
|
||||||
runHook preCheck
|
runHook preCheck
|
||||||
${stdenv.shellDryRun} $out/bin/${name}
|
${stdenv.shellDryRun} "$target"
|
||||||
${shellcheck}/bin/shellcheck $out/bin/${name}
|
${shellcheck}/bin/shellcheck "$target"
|
||||||
runHook postCheck
|
runHook postCheck
|
||||||
''
|
''
|
||||||
else checkPhase;
|
else checkPhase;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
# Check that overriding works for trivial-builders like
|
# Check that overriding works for trivial-builders like
|
||||||
# `writeShellScript` via `overrideAttrs`. This is useful
|
# `writeShellScript` via `overrideAttrs`. This is useful
|
||||||
# to override the `checkPhase`, e. g. when you want
|
# to override the `checkPhase`, e. g. if you want
|
||||||
# to enable extglob in `writeShellScript`.
|
# to disable extglob in `writeShellScript`.
|
||||||
#
|
#
|
||||||
# Run using `nix-build -A tests.trivial-overriding`.
|
# Run using `nix-build -A tests.trivial-builders.overriding`.
|
||||||
{ lib
|
{ lib
|
||||||
|
, stdenv
|
||||||
, runtimeShell
|
, runtimeShell
|
||||||
, runCommand
|
, runCommand
|
||||||
, callPackage
|
, callPackage
|
||||||
|
@ -21,33 +22,6 @@ let
|
||||||
rm success
|
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:
|
simpleCase = case:
|
||||||
writeShellScript "test-trivial-overriding-${case}" extglobScript;
|
writeShellScript "test-trivial-overriding-${case}" extglobScript;
|
||||||
|
|
||||||
|
@ -70,16 +44,33 @@ let
|
||||||
executable = true;
|
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
|
let
|
||||||
drv = (f type).overrideAttrs
|
drv = lib.pipe outcome ([ case ] ++ lib.optionals (outcome == "fail") [ disallowExtglob assertFail ]);
|
||||||
(if type == "succ" then allowExtglob else assertFail);
|
|
||||||
in if isBin then "${drv}/bin/${drv.name}" else drv;
|
in if isBin then "${drv}/bin/${drv.name}" else drv;
|
||||||
|
|
||||||
writeTextOverrides = {
|
writeTextOverrides = {
|
||||||
# Enabling globbing in checkPhase
|
# Make sure extglob works by default
|
||||||
simpleSucc = mkCase simpleCase "succ" false;
|
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;
|
simpleFail = mkCase simpleCase "fail" false;
|
||||||
# Do the same checks after wrapping with callPackage
|
# Do the same checks after wrapping with callPackage
|
||||||
# to make sure callPackage doesn't mess with the override
|
# to make sure callPackage doesn't mess with the override
|
||||||
|
@ -103,7 +94,7 @@ let
|
||||||
name = script.name or (builtins.baseNameOf script);
|
name = script.name or (builtins.baseNameOf script);
|
||||||
in writeShellScript "run-${name}" ''
|
in writeShellScript "run-${name}" ''
|
||||||
if [ "$(${script})" != "success" ]; then
|
if [ "$(${script})" != "success" ]; then
|
||||||
echo "Failed in ${script}"
|
echo "Failed in ${name}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Reference in a new issue