lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add golden effects test

+142 -169
+1 -5
pkgs/test/make-binary-wrapper/add-flags.c
··· 1 - // makeCWrapper /send/me/flags \ 2 - --add-flags "-x -y -z" \ 3 - --add-flags -abc 4 - 5 1 #include <unistd.h> 6 2 #include <stdlib.h> 7 3 #include <assert.h> ··· 22 18 23 19 argv[0] = "/send/me/flags"; 24 20 return execv("/send/me/flags", argv); 25 - } 21 + }
+2
pkgs/test/make-binary-wrapper/add-flags.cmdline
··· 1 + --add-flags "-x -y -z" \ 2 + --add-flags -abc
+6
pkgs/test/make-binary-wrapper/add-flags.env
··· 1 + CWD=SUBST_CWD 2 + SUBST_ARGV0 3 + -x 4 + -y 5 + -z 6 + -abc
+1 -4
pkgs/test/make-binary-wrapper/argv0.c
··· 1 - // makeCWrapper /path/to/some/executable \ 2 - --argv0 alternative-name 3 - 4 1 #include <unistd.h> 5 2 #include <stdlib.h> 6 3 7 4 int main(int argc, char **argv) { 8 5 argv[0] = "alternative-name"; 9 - return execv("/path/to/some/executable", argv); 6 + return execv("/send/me/flags", argv); 10 7 }
+1
pkgs/test/make-binary-wrapper/argv0.cmdline
··· 1 + --argv0 alternative-name
+2
pkgs/test/make-binary-wrapper/argv0.env
··· 1 + CWD=SUBST_CWD 2 + alternative-name
+2 -4
pkgs/test/make-binary-wrapper/basic.c
··· 1 - // makeCWrapper /path/to/executable 2 - 3 1 #include <unistd.h> 4 2 #include <stdlib.h> 5 3 6 4 int main(int argc, char **argv) { 7 - argv[0] = "/path/to/executable"; 8 - return execv("/path/to/executable", argv); 5 + argv[0] = "/send/me/flags"; 6 + return execv("/send/me/flags", argv); 9 7 }
pkgs/test/make-binary-wrapper/basic.cmdline

This is a binary file and will not be displayed.

+2
pkgs/test/make-binary-wrapper/basic.env
··· 1 + CWD=SUBST_CWD 2 + SUBST_ARGV0
+4 -7
pkgs/test/make-binary-wrapper/chdir.c
··· 1 - // makeCWrapper /path/to/executable \ 2 - --chdir /usr/local/bin 3 - 4 1 #include <unistd.h> 5 2 #include <stdlib.h> 6 3 #include <stdio.h> ··· 8 5 #define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) 9 6 10 7 int main(int argc, char **argv) { 11 - assert_success(chdir("/usr/local/bin")); 12 - argv[0] = "/path/to/executable"; 13 - return execv("/path/to/executable", argv); 14 - } 8 + assert_success(chdir("/tmp/foo")); 9 + argv[0] = "/send/me/flags"; 10 + return execv("/send/me/flags", argv); 11 + }
+1
pkgs/test/make-binary-wrapper/chdir.cmdline
··· 1 + --chdir /tmp/foo
+2
pkgs/test/make-binary-wrapper/chdir.env
··· 1 + CWD=/tmp/foo 2 + SUBST_ARGV0
+1 -9
pkgs/test/make-binary-wrapper/combination.c
··· 1 - // makeCWrapper /path/to/executable \ 2 - --argv0 my-wrapper \ 3 - --set-default MESSAGE HELLO \ 4 - --prefix PATH : /usr/bin/ \ 5 - --suffix PATH : /usr/local/bin/ \ 6 - --add-flags "-x -y -z" \ 7 - --set MESSAGE2 WORLD 8 - 9 1 #define _GNU_SOURCE /* See feature_test_macros(7) */ 10 2 #include <unistd.h> 11 3 #include <stdlib.h> ··· 57 49 argv = argv_tmp; 58 50 59 51 argv[0] = "my-wrapper"; 60 - return execv("/path/to/executable", argv); 52 + return execv("/send/me/flags", argv); 61 53 }
+6
pkgs/test/make-binary-wrapper/combination.cmdline
··· 1 + --argv0 my-wrapper \ 2 + --set-default MESSAGE HELLO \ 3 + --prefix PATH : /usr/bin/ \ 4 + --suffix PATH : /usr/local/bin/ \ 5 + --add-flags "-x -y -z" \ 6 + --set MESSAGE2 WORLD
+8
pkgs/test/make-binary-wrapper/combination.env
··· 1 + MESSAGE=HELLO 2 + PATH=/usr/bin/:/usr/local/bin/ 3 + MESSAGE2=WORLD 4 + CWD=SUBST_CWD 5 + my-wrapper 6 + -x 7 + -y 8 + -z
+44 -63
pkgs/test/make-binary-wrapper/default.nix
··· 1 - { lib, stdenv, runCommand, makeBinaryWrapper }: 1 + { lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }: 2 2 3 3 let 4 - makeGoldenTest = { name, filename }: stdenv.mkDerivation { 5 - name = name; 6 - dontUnpack = true; 7 - strictDeps = true; 8 - nativeBuildInputs = [ makeBinaryWrapper ]; 9 - phases = [ "installPhase" ]; 10 - installPhase = '' 11 - source ${./golden-test-utils.sh} 12 - mkdir -p $out/bin 13 - command=$(getInputCommand "${filename}") 14 - eval "$command" > "$out/bin/result" 15 - ''; 16 - passthru = { 17 - assertion = '' 18 - source ${./golden-test-utils.sh} 19 - contents=$(getOutputText "${filename}") 20 - echo "$contents" | diff $out/bin/result - 21 - ''; 22 - }; 23 - }; 24 - tests = { 25 - basic = makeGoldenTest { name = "basic"; filename = ./basic.c; }; 26 - argv0 = makeGoldenTest { name = "argv0"; filename = ./argv0.c; }; 27 - inherit_argv0 = makeGoldenTest { name = "inherit-argv0"; filename = ./inherit-argv0.c; }; 28 - env = makeGoldenTest { name = "env"; filename = ./env.c; }; 29 - invalid_env = makeGoldenTest { name = "invalid-env"; filename = ./invalid-env.c; }; 30 - prefix = makeGoldenTest { name = "prefix"; filename = ./prefix.c; }; 31 - suffix = makeGoldenTest { name = "suffix"; filename = ./suffix.c; }; 32 - add_flags = makeGoldenTest { name = "add-flags"; filename = ./add-flags.c; }; 33 - chdir = makeGoldenTest { name = "chdir"; filename = ./chdir.c; }; 34 - combination = makeGoldenTest { name = "combination"; filename = ./combination.c; }; 35 - }; 36 - in runCommand "make-binary-wrapper-test" { 37 - passthru = tests; 38 - meta.platforms = lib.platforms.all; 39 - } '' 40 - validate() { 41 - local name=$1 42 - local testout=$2 43 - local assertion=$3 4 + env = { nativeBuildInputs = [ makeBinaryWrapper gcc ]; }; 5 + envCheck = runCommand "envcheck" env '' 6 + cc -o $out ${./envcheck.c} 7 + ''; 8 + makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env '' 9 + mkdir -p /tmp/foo 44 10 45 - echo -n "... $name: " >&2 11 + params=$(<"${./.}/${testname}.cmdline") 12 + eval "makeCWrapper /send/me/flags $params" > wrapper.c 46 13 47 - local rc=0 48 - (out=$testout eval "$assertion") || rc=1 14 + diff wrapper.c "${./.}/${testname}.c" 49 15 50 - if [ "$rc" -eq 0 ]; then 51 - echo "yes" >&2 16 + if [ -f "${./.}/${testname}.env" ]; then 17 + eval "makeBinaryWrapper ${envCheck} wrapped $params" 18 + env -i ./wrapped > env.txt 19 + sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \ 20 + "${./.}/${testname}.env" > golden-env.txt 21 + if ! diff env.txt golden-env.txt; then 22 + echo "env/argv should be:" 23 + cat golden-env.txt 24 + echo "env/argv output is:" 25 + cat env.txt 26 + exit 1 27 + fi 52 28 else 53 - echo "no" >&2 29 + # without a golden env, we expect the wrapper compilation to fail 30 + ! eval "makeBinaryWrapper ${envCheck} wrapped $params" &> error.txt 54 31 fi 55 32 56 - return "$rc" 57 - } 58 - 59 - echo "checking whether makeCWrapper works properly... ">&2 60 - 61 - fail= 33 + cp wrapper.c $out 34 + ''; 35 + tests = let 36 + names = [ 37 + "add-flags" 38 + "argv0" 39 + "basic" 40 + "chdir" 41 + "combination" 42 + "env" 43 + "inherit-argv0" 44 + "invalid-env" 45 + "prefix" 46 + "suffix" 47 + ]; 48 + f = name: lib.nameValuePair name (makeGoldenTest name); 49 + in builtins.listToAttrs (builtins.map f names); 50 + in writeText "make-binary-wrapper-test" '' 62 51 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: '' 63 - validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1 52 + "${test.name}" "${test}" 64 53 '') tests)} 65 - 66 - if [ "$fail" ]; then 67 - echo "failed" 68 - exit 1 69 - else 70 - echo "succeeded" 71 - touch $out 72 - fi 73 - '' 54 + '' // tests
+3 -9
pkgs/test/make-binary-wrapper/env.c
··· 1 - // makeCWrapper /hello/world \ 2 - --set PART1 HELLO \ 3 - --set-default PART2 WORLD \ 4 - --unset SOME_OTHER_VARIABLE \ 5 - --set PART3 $'"!!\n"' 6 - 7 1 #include <unistd.h> 8 2 #include <stdlib.h> 9 3 #include <stdio.h> ··· 15 9 assert_success(setenv("PART2", "WORLD", 0)); 16 10 assert_success(unsetenv("SOME_OTHER_VARIABLE")); 17 11 putenv("PART3=\"!!\n\""); 18 - argv[0] = "/hello/world"; 19 - return execv("/hello/world", argv); 20 - } 12 + argv[0] = "/send/me/flags"; 13 + return execv("/send/me/flags", argv); 14 + }
+4
pkgs/test/make-binary-wrapper/env.cmdline
··· 1 + --set PART1 HELLO \ 2 + --set-default PART2 WORLD \ 3 + --unset SOME_OTHER_VARIABLE \ 4 + --set PART3 $'"!!\n"'
+6
pkgs/test/make-binary-wrapper/env.env
··· 1 + PART1=HELLO 2 + PART2=WORLD 3 + PART3="!! 4 + " 5 + CWD=SUBST_CWD 6 + SUBST_ARGV0
+22
pkgs/test/make-binary-wrapper/envcheck.c
··· 1 + #include <limits.h> 2 + #include <stdio.h> 3 + #include <unistd.h> 4 + 5 + int main(int argc, char **argv, char **envp) { 6 + for (char **env = envp; *env != 0; ++env) { 7 + puts(*env); 8 + } 9 + 10 + char cwd[PATH_MAX]; 11 + if (getcwd(cwd, sizeof(cwd))) { 12 + printf("CWD=%s\n", cwd); 13 + } else { 14 + perror("getcwd() error"); 15 + return 1; 16 + } 17 + 18 + for (int i=0; i < argc; ++i) { 19 + puts(argv[i]); 20 + } 21 + return 0; 22 + }
-44
pkgs/test/make-binary-wrapper/golden-test-utils.sh
··· 1 - #!/usr/bin/env bash 2 - # Split a generated C-file into the command used to generate it, 3 - # and the outputted code itself. 4 - 5 - # This is useful because it allows input and output to be inside the same file 6 - 7 - # How it works: 8 - # - The first line needs to start with '//' (and becomes the command). 9 - # - Whitespace/padding between the comment and the generated code is ignored 10 - # - To write a command using multiple lines, end each line with backslash (\) 11 - 12 - # Count the number of lines before the output text starts 13 - # commandLineCount FILE 14 - commandLineCount() { 15 - local n state 16 - n=0 17 - state="init" 18 - while IFS="" read -r p || [ -n "$p" ]; do 19 - case $state in 20 - init) 21 - if [[ $p =~ ^//.*\\$ ]]; then state="comment" 22 - elif [[ $p =~ ^//.* ]]; then state="padding" 23 - else break 24 - fi 25 - ;; 26 - comment) [[ ! $p =~ ^.*\\$ ]] && state="padding";; 27 - padding) [ -n "${p// }" ] && break;; 28 - esac 29 - n=$((n+1)) 30 - done < "$1" 31 - printf '%s' "$n" 32 - } 33 - 34 - # getInputCommand FILE 35 - getInputCommand() { 36 - n=$(commandLineCount "$1") 37 - head -n "$n" "$1" | awk '{ if (NR == 1) print substr($0, 3); else print $0 }' 38 - } 39 - 40 - # getOutputText FILE 41 - getOutputText() { 42 - n=$(commandLineCount "$1") 43 - sed "1,${n}d" "$1" 44 - }
+2 -5
pkgs/test/make-binary-wrapper/inherit-argv0.c
··· 1 - // makeCWrapper /path/to/executable \ 2 - --inherit-argv0 3 - 4 1 #include <unistd.h> 5 2 #include <stdlib.h> 6 3 7 4 int main(int argc, char **argv) { 8 - return execv("/path/to/executable", argv); 9 - } 5 + return execv("/send/me/flags", argv); 6 + }
+1
pkgs/test/make-binary-wrapper/inherit-argv0.cmdline
··· 1 + --inherit-argv0
+2
pkgs/test/make-binary-wrapper/inherit-argv0.env
··· 1 + CWD=SUBST_CWD 2 + ./wrapped
+3 -7
pkgs/test/make-binary-wrapper/invalid-env.c
··· 1 - // makeCWrapper /bad/env/example \ 2 - --set "=" "TEST1" \ 3 - --set-default "" "TEST2" 4 - 5 1 #include <unistd.h> 6 2 #include <stdlib.h> 7 3 #include <stdio.h> ··· 13 9 #error Illegal environment variable name `=` (cannot contain `=`) 14 10 assert_success(setenv("", "TEST2", 0)); 15 11 #error Environment variable name can't be empty. 16 - argv[0] = "/bad/env/example"; 17 - return execv("/bad/env/example", argv); 18 - } 12 + argv[0] = "/send/me/flags"; 13 + return execv("/send/me/flags", argv); 14 + }
+2
pkgs/test/make-binary-wrapper/invalid-env.cmdline
··· 1 + --set "=" "TEST1" \ 2 + --set-default "" "TEST2"
+2 -6
pkgs/test/make-binary-wrapper/prefix.c
··· 1 - // makeCWrapper /path/to/executable \ 2 - --prefix PATH : /usr/bin/ \ 3 - --prefix PATH : /usr/local/bin/ 4 - 5 1 #define _GNU_SOURCE /* See feature_test_macros(7) */ 6 2 #include <unistd.h> 7 3 #include <stdlib.h> ··· 25 21 int main(int argc, char **argv) { 26 22 set_env_prefix("PATH", ":", "/usr/bin/"); 27 23 set_env_prefix("PATH", ":", "/usr/local/bin/"); 28 - argv[0] = "/path/to/executable"; 29 - return execv("/path/to/executable", argv); 24 + argv[0] = "/send/me/flags"; 25 + return execv("/send/me/flags", argv); 30 26 }
+2
pkgs/test/make-binary-wrapper/prefix.cmdline
··· 1 + --prefix PATH : /usr/bin/ \ 2 + --prefix PATH : /usr/local/bin/
+3
pkgs/test/make-binary-wrapper/prefix.env
··· 1 + PATH=/usr/local/bin/:/usr/bin/ 2 + CWD=SUBST_CWD 3 + SUBST_ARGV0
+2 -6
pkgs/test/make-binary-wrapper/suffix.c
··· 1 - // makeCWrapper /path/to/executable \ 2 - --suffix PATH : /usr/bin/ \ 3 - --suffix PATH : /usr/local/bin/ 4 - 5 1 #define _GNU_SOURCE /* See feature_test_macros(7) */ 6 2 #include <unistd.h> 7 3 #include <stdlib.h> ··· 25 21 int main(int argc, char **argv) { 26 22 set_env_suffix("PATH", ":", "/usr/bin/"); 27 23 set_env_suffix("PATH", ":", "/usr/local/bin/"); 28 - argv[0] = "/path/to/executable"; 29 - return execv("/path/to/executable", argv); 24 + argv[0] = "/send/me/flags"; 25 + return execv("/send/me/flags", argv); 30 26 }
+2
pkgs/test/make-binary-wrapper/suffix.cmdline
··· 1 + --suffix PATH : /usr/bin/ \ 2 + --suffix PATH : /usr/local/bin/
+3
pkgs/test/make-binary-wrapper/suffix.env
··· 1 + PATH=/usr/bin/:/usr/local/bin/ 2 + CWD=SUBST_CWD 3 + SUBST_ARGV0