tests.patch-shebangs: add case for ignoring store paths
This commit is contained in:
parent
ca156a66b7
commit
93a7e96c87
@ -1,6 +1,7 @@
|
|||||||
{ lib, stdenv, runCommand }:
|
{ lib, stdenv, runCommand }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
tests = {
|
||||||
bad-shebang = stdenv.mkDerivation {
|
bad-shebang = stdenv.mkDerivation {
|
||||||
name = "bad-shebang";
|
name = "bad-shebang";
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
@ -10,17 +11,60 @@ let
|
|||||||
echo "echo -n hello" >> $out/bin/test
|
echo "echo -n hello" >> $out/bin/test
|
||||||
chmod +x $out/bin/test
|
chmod +x $out/bin/test
|
||||||
'';
|
'';
|
||||||
|
passthru = {
|
||||||
|
assertion = "grep -v '^#!/bin/sh' $out/bin/test > /dev/null";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ignores-nix-store = stdenv.mkDerivation {
|
||||||
|
name = "ignores-nix-store";
|
||||||
|
dontUnpack = true;
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
echo "#!$NIX_STORE/path/to/sh" > $out/bin/test
|
||||||
|
echo "echo -n hello" >> $out/bin/test
|
||||||
|
chmod +x $out/bin/test
|
||||||
|
'';
|
||||||
|
passthru = {
|
||||||
|
assertion = "grep \"^#!$NIX_STORE/path/to/sh\" $out/bin/test > /dev/null";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in runCommand "patch-shebangs-test" {
|
in runCommand "patch-shebangs-test" {
|
||||||
passthru = { inherit bad-shebang; };
|
passthru = { inherit (tests) bad-shebang ignores-nix-store; };
|
||||||
meta.platforms = lib.platforms.all;
|
meta.platforms = lib.platforms.all;
|
||||||
} ''
|
} ''
|
||||||
printf "checking whether patchShebangs works properly... ">&2
|
validate() {
|
||||||
if ! grep -q '^#!/bin/sh' ${bad-shebang}/bin/test; then
|
local name=$1
|
||||||
|
local testout=$2
|
||||||
|
local assertion=$3
|
||||||
|
|
||||||
|
echo -n "... $name: " >&2
|
||||||
|
|
||||||
|
local rc=0
|
||||||
|
(out=$testout eval "$assertion") || rc=1
|
||||||
|
|
||||||
|
if [ "$rc" -eq 0 ]; then
|
||||||
echo "yes" >&2
|
echo "yes" >&2
|
||||||
touch $out
|
|
||||||
else
|
else
|
||||||
echo "no" >&2
|
echo "no" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
return "$rc"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "checking whether patchShebangs works properly... ">&2
|
||||||
|
|
||||||
|
fail=
|
||||||
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
|
||||||
|
validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1
|
||||||
|
'') tests)}
|
||||||
|
|
||||||
|
if [ "$fail" ]; then
|
||||||
|
echo "failed"
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
echo "succeeded"
|
||||||
|
touch $out
|
||||||
fi
|
fi
|
||||||
''
|
''
|
||||||
|
Loading…
Reference in New Issue
Block a user