2021-12-07 17:39:38 +00:00
|
|
|
{ lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }:
|
2021-10-04 21:35:09 +01:00
|
|
|
|
|
|
|
let
|
2021-12-16 20:29:21 +00:00
|
|
|
env = { buildInputs = [ makeBinaryWrapper ]; };
|
2021-12-07 17:39:38 +00:00
|
|
|
envCheck = runCommand "envcheck" env ''
|
2021-12-09 15:45:35 +00:00
|
|
|
${gcc}/bin/cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
|
2021-12-07 17:39:38 +00:00
|
|
|
'';
|
|
|
|
makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env ''
|
2021-12-10 20:21:14 +00:00
|
|
|
mkdir -p ./tmp/foo
|
2021-12-07 17:39:38 +00:00
|
|
|
|
|
|
|
params=$(<"${./.}/${testname}.cmdline")
|
|
|
|
eval "makeCWrapper /send/me/flags $params" > wrapper.c
|
|
|
|
|
|
|
|
diff wrapper.c "${./.}/${testname}.c"
|
|
|
|
|
|
|
|
if [ -f "${./.}/${testname}.env" ]; then
|
2021-12-09 11:31:35 +00:00
|
|
|
eval "makeWrapper ${envCheck} wrapped $params"
|
2021-12-07 17:39:38 +00:00
|
|
|
env -i ./wrapped > env.txt
|
|
|
|
sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
|
|
|
|
"${./.}/${testname}.env" > golden-env.txt
|
|
|
|
if ! diff env.txt golden-env.txt; then
|
|
|
|
echo "env/argv should be:"
|
|
|
|
cat golden-env.txt
|
|
|
|
echo "env/argv output is:"
|
|
|
|
cat env.txt
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-04 21:35:09 +01:00
|
|
|
else
|
2021-12-07 17:39:38 +00:00
|
|
|
# without a golden env, we expect the wrapper compilation to fail
|
2021-12-09 11:31:35 +00:00
|
|
|
! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt
|
2021-10-04 21:35:09 +01:00
|
|
|
fi
|
|
|
|
|
2021-12-07 17:39:38 +00:00
|
|
|
cp wrapper.c $out
|
|
|
|
'';
|
|
|
|
tests = let
|
|
|
|
names = [
|
|
|
|
"add-flags"
|
|
|
|
"argv0"
|
|
|
|
"basic"
|
|
|
|
"chdir"
|
|
|
|
"combination"
|
|
|
|
"env"
|
|
|
|
"inherit-argv0"
|
|
|
|
"invalid-env"
|
|
|
|
"prefix"
|
|
|
|
"suffix"
|
|
|
|
];
|
|
|
|
f = name: lib.nameValuePair name (makeGoldenTest name);
|
|
|
|
in builtins.listToAttrs (builtins.map f names);
|
|
|
|
in writeText "make-binary-wrapper-test" ''
|
2021-10-04 21:35:09 +01:00
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
|
2021-12-07 17:39:38 +00:00
|
|
|
"${test.name}" "${test}"
|
2021-10-04 21:35:09 +01:00
|
|
|
'') tests)}
|
2021-12-07 17:39:38 +00:00
|
|
|
'' // tests
|