diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-01-03 23:55:00 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-02-19 11:03:39 +0000 |
commit | f4cf97a04cd5d0b86aa46baec9fb228a8f671c03 (patch) | |
tree | 28192415ff39a661d0001563bf81cc93fa25d16d /nixpkgs/pkgs/test | |
parent | f8422837c9bde058e8f2de37702e7e94b2226040 (diff) | |
parent | 18c84ea816348e2a098390101b92d1e39a9dbd45 (diff) | |
download | nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar.gz nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar.bz2 nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar.lz nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar.xz nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.tar.zst nixlib-f4cf97a04cd5d0b86aa46baec9fb228a8f671c03.zip |
Merge commit '18c84ea816348e2a098390101b92d1e39a9dbd45'
Conflicts: nixpkgs/nixos/modules/misc/documentation.nix nixpkgs/pkgs/applications/networking/browsers/firefox/packages.nix nixpkgs/pkgs/applications/window-managers/sway/default.nix nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix nixpkgs/pkgs/development/go-modules/generic/default.nix nixpkgs/pkgs/development/interpreters/ruby/default.nix nixpkgs/pkgs/development/interpreters/ruby/patchsets.nix nixpkgs/pkgs/development/libraries/boehm-gc/7.6.6.nix nixpkgs/pkgs/development/python-modules/django-mailman3/default.nix nixpkgs/pkgs/servers/mail/mailman/web.nix nixpkgs/pkgs/top-level/aliases.nix nixpkgs/pkgs/top-level/all-packages.nix nixpkgs/pkgs/top-level/impure.nix
Diffstat (limited to 'nixpkgs/pkgs/test')
38 files changed, 486 insertions, 6 deletions
diff --git a/nixpkgs/pkgs/test/default.nix b/nixpkgs/pkgs/test/default.nix index ebf732839cea..caed950c5764 100644 --- a/nixpkgs/pkgs/test/default.nix +++ b/nixpkgs/pkgs/test/default.nix @@ -27,6 +27,10 @@ with pkgs; cc-multilib-gcc = callPackage ./cc-wrapper/multilib.nix { stdenv = gccMultiStdenv; }; cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; }; + fetchpatch = callPackages ../build-support/fetchpatch/tests.nix { }; + fetchgit = callPackages ../build-support/fetchgit/tests.nix { }; + fetchFirefoxAddon = callPackages ../build-support/fetchfirefoxaddon/tests.nix { }; + install-shell-files = callPackage ./install-shell-files {}; kernel-config = callPackage ./kernel.nix {}; @@ -37,6 +41,8 @@ with pkgs; cross = callPackage ./cross {}; + php = recurseIntoAttrs (callPackages ./php {}); + rustCustomSysroot = callPackage ./rust-sysroot {}; buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { }; importCargoLock = callPackage ../build-support/rust/test/import-cargo-lock { }; @@ -51,8 +57,13 @@ with pkgs; cuda = callPackage ./cuda { }; - trivial = callPackage ../build-support/trivial-builders/test.nix {}; - trivial-overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {}; + trivial-builders = recurseIntoAttrs { + writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {}; + references = callPackage ../build-support/trivial-builders/test/references.nix {}; + overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {}; + }; writers = callPackage ../build-support/writers/test.nix {}; + + dhall = callPackage ./dhall { }; } diff --git a/nixpkgs/pkgs/test/dhall/buildDhallUrl/default.nix b/nixpkgs/pkgs/test/dhall/buildDhallUrl/default.nix new file mode 100644 index 000000000000..d2e214fb9770 --- /dev/null +++ b/nixpkgs/pkgs/test/dhall/buildDhallUrl/default.nix @@ -0,0 +1,14 @@ +{ dhallPackages, lib }: + +# This file tests that dhallPackages.buildDhallUrl is able to successfully +# build a Nix Dhall package for a given remote Dhall import. +# +# TODO: It would be nice to extend this test to make sure that the resulting +# Nix Dhall package is has the expected contents. + +dhallPackages.buildDhallUrl { + url = "https://raw.githubusercontent.com/cdepillabout/example-dhall-nix/e6a675c72ecd4dd23d254a02aea8181fe875747f/mydhallfile.dhall"; + hash = "sha256-434x+QjHRzuprBdw0h6wmwB1Zj6yZqQb533me8XdO4c="; + dhallHash = "sha256:e37e31f908c7473ba9ac1770d21eb09b0075663eb266a41be77de67bc5dd3b87"; + source = true; +} diff --git a/nixpkgs/pkgs/test/dhall/default.nix b/nixpkgs/pkgs/test/dhall/default.nix new file mode 100644 index 000000000000..4c7eba6c9579 --- /dev/null +++ b/nixpkgs/pkgs/test/dhall/default.nix @@ -0,0 +1,6 @@ +{ lib, callPackage }: + +lib.recurseIntoAttrs { + buildDhallUrl = callPackage ./buildDhallUrl { }; + generateDhallDirectoryPackage = callPackage ./generateDhallDirectoryPackage { }; +} diff --git a/nixpkgs/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix b/nixpkgs/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix new file mode 100644 index 000000000000..4771e1629806 --- /dev/null +++ b/nixpkgs/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix @@ -0,0 +1,17 @@ +{ dhallPackages, fetchFromGitHub }: + +# This file tests that dhallPackages.generateDhallDirectoryPackage works. +# +# TODO: It would be nice to extend this test to make sure that the resulting +# Nix file has the expected contents, but it might be tough to do that easily +# without IFD. + +dhallPackages.generateDhallDirectoryPackage { + src = fetchFromGitHub { + owner = "cdepillabout"; + repo = "example-dhall-nix"; + rev = "e6a675c72ecd4dd23d254a02aea8181fe875747f"; + sha256 = "sha256-c/EZq76s/+hmLkaeJWKqgh2KrHuJRYI6kWry0E0YQ6s="; + }; + file = "mydhallfile.dhall"; +} diff --git a/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix b/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix index e3214fb49fed..337510281012 100644 --- a/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix +++ b/nixpkgs/pkgs/test/haskell/documentationTarball/default.nix @@ -2,9 +2,9 @@ let drv = haskellPackages.vector; - docs = pkgs.haskell.lib.documentationTarball drv; + docs = pkgs.haskell.lib.compose.documentationTarball drv; -in pkgs.runCommand "test haskell.lib.documentationTarball" { +in pkgs.runCommand "test haskell.lib.compose.documentationTarball" { meta = { inherit (docs.meta) platforms; }; diff --git a/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix b/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix index 5a8391d08861..f0c78c510449 100644 --- a/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix +++ b/nixpkgs/pkgs/test/haskell/setBuildTarget/default.nix @@ -17,7 +17,7 @@ let drv = haskellPackages.callPackage pkgDef {}; test = target: excluded: - let only = pkgs.haskell.lib.setBuildTarget drv target; + let only = pkgs.haskell.lib.compose.setBuildTarget target drv; in '' if [[ ! -f "${only}/bin/${target}" ]]; then echo "${target} was not built" @@ -31,7 +31,7 @@ let ''; in -pkgs.runCommand "test haskell.lib.setBuildTarget" { +pkgs.runCommand "test haskell.lib.compose.setBuildTarget" { meta = { inherit (drv.meta) platforms; }; diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.c b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.c new file mode 100644 index 000000000000..7ce682c6be64 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.c @@ -0,0 +1,21 @@ +#include <unistd.h> +#include <stdlib.h> +#include <assert.h> + +int main(int argc, char **argv) { + char **argv_tmp = calloc(5 + argc, sizeof(*argv_tmp)); + assert(argv_tmp != NULL); + argv_tmp[0] = argv[0]; + argv_tmp[1] = "-x"; + argv_tmp[2] = "-y"; + argv_tmp[3] = "-z"; + argv_tmp[4] = "-abc"; + for (int i = 1; i < argc; ++i) { + argv_tmp[4 + i] = argv[i]; + } + argv_tmp[4 + argc] = NULL; + argv = argv_tmp; + + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.cmdline new file mode 100644 index 000000000000..f840c772e349 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.cmdline @@ -0,0 +1,2 @@ + --add-flags "-x -y -z" \ + --add-flags -abc diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.env b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.env new file mode 100644 index 000000000000..9b8d1fb9f6a5 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/add-flags.env @@ -0,0 +1,6 @@ +CWD=SUBST_CWD +SUBST_ARGV0 +-x +-y +-z +-abc diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/argv0.c b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.c new file mode 100644 index 000000000000..70c36889dc89 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.c @@ -0,0 +1,7 @@ +#include <unistd.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + argv[0] = "alternative-name"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/argv0.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.cmdline new file mode 100644 index 000000000000..1cadce8312a4 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.cmdline @@ -0,0 +1 @@ + --argv0 alternative-name diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/argv0.env b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.env new file mode 100644 index 000000000000..04c13d32ee6d --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/argv0.env @@ -0,0 +1,2 @@ +CWD=SUBST_CWD +alternative-name diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/basic.c b/nixpkgs/pkgs/test/make-binary-wrapper/basic.c new file mode 100644 index 000000000000..1c1266181377 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/basic.c @@ -0,0 +1,7 @@ +#include <unistd.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/basic.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/basic.cmdline new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/basic.cmdline diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/basic.env b/nixpkgs/pkgs/test/make-binary-wrapper/basic.env new file mode 100644 index 000000000000..b0da31959447 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/basic.env @@ -0,0 +1,2 @@ +CWD=SUBST_CWD +SUBST_ARGV0 diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/chdir.c b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.c new file mode 100644 index 000000000000..9e0b7e2c7f52 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.c @@ -0,0 +1,11 @@ +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +int main(int argc, char **argv) { + assert_success(chdir("./tmp/foo")); + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/chdir.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.cmdline new file mode 100644 index 000000000000..d6ab081e8d35 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.cmdline @@ -0,0 +1 @@ + --chdir ./tmp/foo diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/chdir.env b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.env new file mode 100644 index 000000000000..ea1c61054e50 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/chdir.env @@ -0,0 +1,2 @@ +CWD=SUBST_CWD/tmp/foo +SUBST_ARGV0 diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/combination.c b/nixpkgs/pkgs/test/make-binary-wrapper/combination.c new file mode 100644 index 000000000000..e9ce5f1d7244 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/combination.c @@ -0,0 +1,53 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <unistd.h> +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +void set_env_prefix(char *env, char *sep, char *prefix) { + char *existing = getenv(env); + if (existing) { + char *val; + assert_success(asprintf(&val, "%s%s%s", prefix, sep, existing)); + assert_success(setenv(env, val, 1)); + free(val); + } else { + assert_success(setenv(env, prefix, 1)); + } +} + +void set_env_suffix(char *env, char *sep, char *suffix) { + char *existing = getenv(env); + if (existing) { + char *val; + assert_success(asprintf(&val, "%s%s%s", existing, sep, suffix)); + assert_success(setenv(env, val, 1)); + free(val); + } else { + assert_success(setenv(env, suffix, 1)); + } +} + +int main(int argc, char **argv) { + assert_success(setenv("MESSAGE", "HELLO", 0)); + set_env_prefix("PATH", ":", "/usr/bin/"); + set_env_suffix("PATH", ":", "/usr/local/bin/"); + putenv("MESSAGE2=WORLD"); + + char **argv_tmp = calloc(4 + argc, sizeof(*argv_tmp)); + assert(argv_tmp != NULL); + argv_tmp[0] = argv[0]; + argv_tmp[1] = "-x"; + argv_tmp[2] = "-y"; + argv_tmp[3] = "-z"; + for (int i = 1; i < argc; ++i) { + argv_tmp[3 + i] = argv[i]; + } + argv_tmp[3 + argc] = NULL; + argv = argv_tmp; + + argv[0] = "my-wrapper"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/combination.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/combination.cmdline new file mode 100644 index 000000000000..fb3861235c8b --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/combination.cmdline @@ -0,0 +1,6 @@ + --argv0 my-wrapper \ + --set-default MESSAGE HELLO \ + --prefix PATH : /usr/bin/ \ + --suffix PATH : /usr/local/bin/ \ + --add-flags "-x -y -z" \ + --set MESSAGE2 WORLD diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/combination.env b/nixpkgs/pkgs/test/make-binary-wrapper/combination.env new file mode 100644 index 000000000000..886420c01d1e --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/combination.env @@ -0,0 +1,8 @@ +MESSAGE=HELLO +PATH=/usr/bin/:/usr/local/bin/ +MESSAGE2=WORLD +CWD=SUBST_CWD +my-wrapper +-x +-y +-z diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/default.nix b/nixpkgs/pkgs/test/make-binary-wrapper/default.nix new file mode 100644 index 000000000000..b5bbf994ffa3 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/default.nix @@ -0,0 +1,54 @@ +{ lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }: + +let + env = { buildInputs = [ makeBinaryWrapper ]; }; + envCheck = runCommand "envcheck" env '' + ${gcc}/bin/cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c} + ''; + makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env '' + mkdir -p ./tmp/foo + + params=$(<"${./.}/${testname}.cmdline") + eval "makeCWrapper /send/me/flags $params" > wrapper.c + + diff wrapper.c "${./.}/${testname}.c" + + if [ -f "${./.}/${testname}.env" ]; then + eval "makeWrapper ${envCheck} wrapped $params" + 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 + else + # without a golden env, we expect the wrapper compilation to fail + ! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt + fi + + 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" '' + ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: '' + "${test.name}" "${test}" + '') tests)} +'' // tests diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/env.c b/nixpkgs/pkgs/test/make-binary-wrapper/env.c new file mode 100644 index 000000000000..7e0422dee3bd --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/env.c @@ -0,0 +1,14 @@ +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +int main(int argc, char **argv) { + putenv("PART1=HELLO"); + assert_success(setenv("PART2", "WORLD", 0)); + assert_success(unsetenv("SOME_OTHER_VARIABLE")); + putenv("PART3=\"!!\n\""); + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/env.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/env.cmdline new file mode 100644 index 000000000000..3c89f33e2dce --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/env.cmdline @@ -0,0 +1,4 @@ + --set PART1 HELLO \ + --set-default PART2 WORLD \ + --unset SOME_OTHER_VARIABLE \ + --set PART3 $'"!!\n"' diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/env.env b/nixpkgs/pkgs/test/make-binary-wrapper/env.env new file mode 100644 index 000000000000..c7661e165e09 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/env.env @@ -0,0 +1,6 @@ +PART1=HELLO +PART2=WORLD +PART3="!! +" +CWD=SUBST_CWD +SUBST_ARGV0 diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/envcheck.c b/nixpkgs/pkgs/test/make-binary-wrapper/envcheck.c new file mode 100644 index 000000000000..848fbdaa80f2 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/envcheck.c @@ -0,0 +1,22 @@ +#include <limits.h> +#include <stdio.h> +#include <unistd.h> + +int main(int argc, char **argv, char **envp) { + for (char **env = envp; *env != 0; ++env) { + puts(*env); + } + + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd))) { + printf("CWD=%s\n", cwd); + } else { + perror("getcwd() error"); + return 1; + } + + for (int i=0; i < argc; ++i) { + puts(argv[i]); + } + return 0; +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.c b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.c new file mode 100644 index 000000000000..e1c2bc926aa7 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.c @@ -0,0 +1,6 @@ +#include <unistd.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.cmdline new file mode 100644 index 000000000000..088076799835 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.cmdline @@ -0,0 +1 @@ + --inherit-argv0 diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.env b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.env new file mode 100644 index 000000000000..c46ca95eefbc --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/inherit-argv0.env @@ -0,0 +1,2 @@ +CWD=SUBST_CWD +./wrapped diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.c b/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.c new file mode 100644 index 000000000000..4dfd36fb68a0 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.c @@ -0,0 +1,14 @@ +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +int main(int argc, char **argv) { + putenv("==TEST1"); + #error Illegal environment variable name `=` (cannot contain `=`) + assert_success(setenv("", "TEST2", 0)); + #error Environment variable name can't be empty. + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.cmdline new file mode 100644 index 000000000000..a03b001e754e --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/invalid-env.cmdline @@ -0,0 +1,2 @@ + --set "=" "TEST1" \ + --set-default "" "TEST2" diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/prefix.c b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.c new file mode 100644 index 000000000000..ea8fbdc64a84 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.c @@ -0,0 +1,26 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <unistd.h> +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +void set_env_prefix(char *env, char *sep, char *prefix) { + char *existing = getenv(env); + if (existing) { + char *val; + assert_success(asprintf(&val, "%s%s%s", prefix, sep, existing)); + assert_success(setenv(env, val, 1)); + free(val); + } else { + assert_success(setenv(env, prefix, 1)); + } +} + +int main(int argc, char **argv) { + set_env_prefix("PATH", ":", "/usr/bin/"); + set_env_prefix("PATH", ":", "/usr/local/bin/"); + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/prefix.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.cmdline new file mode 100644 index 000000000000..99cebf9503f4 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.cmdline @@ -0,0 +1,2 @@ + --prefix PATH : /usr/bin/ \ + --prefix PATH : /usr/local/bin/ diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/prefix.env b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.env new file mode 100644 index 000000000000..033676457c57 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/prefix.env @@ -0,0 +1,3 @@ +PATH=/usr/local/bin/:/usr/bin/ +CWD=SUBST_CWD +SUBST_ARGV0 diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/suffix.c b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.c new file mode 100644 index 000000000000..d33f86c070ca --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.c @@ -0,0 +1,26 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <unistd.h> +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0) + +void set_env_suffix(char *env, char *sep, char *suffix) { + char *existing = getenv(env); + if (existing) { + char *val; + assert_success(asprintf(&val, "%s%s%s", existing, sep, suffix)); + assert_success(setenv(env, val, 1)); + free(val); + } else { + assert_success(setenv(env, suffix, 1)); + } +} + +int main(int argc, char **argv) { + set_env_suffix("PATH", ":", "/usr/bin/"); + set_env_suffix("PATH", ":", "/usr/local/bin/"); + argv[0] = "/send/me/flags"; + return execv("/send/me/flags", argv); +} diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/suffix.cmdline b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.cmdline new file mode 100644 index 000000000000..95d291f3c169 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.cmdline @@ -0,0 +1,2 @@ + --suffix PATH : /usr/bin/ \ + --suffix PATH : /usr/local/bin/ diff --git a/nixpkgs/pkgs/test/make-binary-wrapper/suffix.env b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.env new file mode 100644 index 000000000000..3ce4cc54de41 --- /dev/null +++ b/nixpkgs/pkgs/test/make-binary-wrapper/suffix.env @@ -0,0 +1,3 @@ +PATH=/usr/bin/:/usr/local/bin/ +CWD=SUBST_CWD +SUBST_ARGV0 diff --git a/nixpkgs/pkgs/test/php/default.nix b/nixpkgs/pkgs/test/php/default.nix new file mode 100644 index 000000000000..3c6c8f61b6db --- /dev/null +++ b/nixpkgs/pkgs/test/php/default.nix @@ -0,0 +1,116 @@ +{ lib +, php +, runCommand +}: + +let + runTest = name: body: runCommand name { } '' + testFailed= + checking() { + echo -n "Checking $1... " > /dev/stderr + } + ok() { + echo ok > /dev/stderr + } + nok() { + echo fail > /dev/stderr + testFailed=1 + } + + ${body} + + if test -n "$testFailed"; then + exit 1 + fi + + touch $out + ''; + + check = cond: if cond then "ok" else "nok"; +in +{ + withExtensions-enables-previously-disabled-extensions = runTest "php-test-withExtensions-enables-previously-disabled-extensions" '' + php="${php}" + + checking "that imagick is not present by default" + $php/bin/php -r 'exit(extension_loaded("imagick") ? 1 : 0);' && ok || nok + + phpWithImagick="${php.withExtensions ({ all, ... }: [ all.imagick ])}" + checking "that imagick extension is present when enabled" + $phpWithImagick/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok + ''; + + overrideAttrs-preserves-enabled-extensions = + let + customPhp = + (php.withExtensions ({ all, ... }: [ all.imagick ])).overrideAttrs (attrs: { + postInstall = attrs.postInstall or "" + '' + touch "$out/oApee-was-here" + ''; + }); + in + runTest "php-test-overrideAttrs-preserves-enabled-extensions" '' + php="${customPhp}" + phpUnwrapped="${customPhp.unwrapped}" + + checking "if overrides took hold" + test -f "$phpUnwrapped/oApee-was-here" && ok || nok + + checking "if imagick extension is still present" + $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok + + checking "if imagick extension is linked against the overridden PHP" + echo $php + $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok + ''; + + unwrapped-overrideAttrs-stacks = + let + customPhp = + lib.pipe php.unwrapped [ + (pkg: pkg.overrideAttrs (attrs: { + postInstall = attrs.postInstall or "" + '' + touch "$out/oAs-first" + ''; + })) + + (pkg: pkg.overrideAttrs (attrs: { + postInstall = attrs.postInstall or "" + '' + touch "$out/oAs-second" + ''; + })) + ]; + in + runTest "php-test-unwrapped-overrideAttrs-stacks" '' + checking "if first override remained" + ${check (builtins.match ".*oAs-first.*" customPhp.postInstall != null)} + + checking "if second override is there" + ${check (builtins.match ".*oAs-second.*" customPhp.postInstall != null)} + ''; + + wrapped-overrideAttrs-stacks = + let + customPhp = + lib.pipe php [ + (pkg: pkg.overrideAttrs (attrs: { + postInstall = attrs.postInstall or "" + '' + touch "$out/oAs-first" + ''; + })) + + (pkg: pkg.overrideAttrs (attrs: { + postInstall = attrs.postInstall or "" + '' + touch "$out/oAs-second" + ''; + })) + ]; + in + runTest "php-test-wrapped-overrideAttrs-stacks" '' + checking "if first override remained" + ${check (builtins.match ".*oAs-first.*" customPhp.unwrapped.postInstall != null)} + + checking "if second override is there" + ${check (builtins.match ".*oAs-second.*" customPhp.unwrapped.postInstall != null)} + ''; +} |