about summary refs log tree commit diff
path: root/nixpkgs/pkgs/test
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-02-22 10:43:06 +0000
committerAlyssa Ross <hi@alyssa.is>2022-03-11 16:17:56 +0000
commitca1aada113c0ebda1ab8667199f6453f8e01c4fc (patch)
tree55e402280096f62eb0bc8bcad5ce6050c5a0aec7 /nixpkgs/pkgs/test
parente4df5a52a6a6531f32626f57205356a773ac2975 (diff)
parent93883402a445ad467320925a0a5dbe43a949f25b (diff)
downloadnixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.gz
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.bz2
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.lz
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.xz
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.zst
nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.zip
Merge commit '93883402a445ad467320925a0a5dbe43a949f25b'
Conflicts:
	nixpkgs/nixos/modules/programs/ssh.nix
	nixpkgs/pkgs/applications/networking/browsers/firefox/packages.nix
	nixpkgs/pkgs/data/fonts/noto-fonts/default.nix
	nixpkgs/pkgs/development/go-modules/generic/default.nix
	nixpkgs/pkgs/development/interpreters/ruby/default.nix
	nixpkgs/pkgs/development/libraries/mesa/default.nix
Diffstat (limited to 'nixpkgs/pkgs/test')
-rw-r--r--nixpkgs/pkgs/test/default.nix3
-rw-r--r--nixpkgs/pkgs/test/make-wrapper/default.nix136
-rw-r--r--nixpkgs/pkgs/test/vim/default.nix2
3 files changed, 140 insertions, 1 deletions
diff --git a/nixpkgs/pkgs/test/default.nix b/nixpkgs/pkgs/test/default.nix
index caed950c5764..4110327946d9 100644
--- a/nixpkgs/pkgs/test/default.nix
+++ b/nixpkgs/pkgs/test/default.nix
@@ -61,9 +61,12 @@ with pkgs;
     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 {};
+    concat = callPackage ../build-support/trivial-builders/test/concat-test.nix {};
   };
 
   writers = callPackage ../build-support/writers/test.nix {};
 
   dhall = callPackage ./dhall { };
+
+  makeWrapper = callPackage ./make-wrapper {};
 }
diff --git a/nixpkgs/pkgs/test/make-wrapper/default.nix b/nixpkgs/pkgs/test/make-wrapper/default.nix
new file mode 100644
index 000000000000..6e70945ee194
--- /dev/null
+++ b/nixpkgs/pkgs/test/make-wrapper/default.nix
@@ -0,0 +1,136 @@
+{ lib
+, writeText
+, writeCBin
+, writeShellScript
+, makeWrapper
+, runCommand
+, which
+, ...
+}:
+
+let
+  # Testfiles
+  foofile = writeText "foofile" "foo";
+  barfile = writeText "barfile" "bar";
+
+  # Wrapped binaries
+  wrappedArgv0 = writeCBin "wrapped-argv0" ''
+    #include <stdio.h>
+    #include <stdlib.h>
+
+    void main(int argc, char** argv) {
+      printf("argv0=%s", argv[0]);
+      exit(0);
+    }
+  '';
+  wrappedBinaryVar = writeShellScript "wrapped-var" ''
+    echo "VAR=$VAR"
+  '';
+  wrappedBinaryArgs = writeShellScript "wrapped-args" ''
+    echo "$@"
+  '';
+
+  mkWrapperBinary = { name, args, wrapped ? wrappedBinaryVar }: runCommand name
+    {
+      nativeBuildInputs = [ makeWrapper ];
+    } ''
+    mkdir -p $out/bin
+    makeWrapper "${wrapped}" "$out/bin/${name}" ${lib.escapeShellArgs args}
+  '';
+
+  mkTest = cmd: toExpect: ''
+    output="$(${cmd})"
+    if [[ "$output" != '${toExpect}' ]]; then
+      echo "test failed: the output of ${cmd} was '$output', expected '${toExpect}'"
+      echo "the wrapper contents:"
+      for i in ${cmd}; do
+        if [[ $i =~ ^test- ]]; then
+          cat $(which $i)
+        fi
+      done
+      exit 1
+    fi
+  '';
+in
+runCommand "make-wrapper-test"
+{
+  nativeBuildInputs = [
+    which
+    (mkWrapperBinary { name = "test-argv0"; args = [ "--argv0" "foo" ]; wrapped = "${wrappedArgv0}/bin/wrapped-argv0"; })
+    (mkWrapperBinary { name = "test-set"; args = [ "--set" "VAR" "abc" ]; })
+    (mkWrapperBinary { name = "test-set-default"; args = [ "--set-default" "VAR" "abc" ]; })
+    (mkWrapperBinary { name = "test-unset"; args = [ "--unset" "VAR" ]; })
+    (mkWrapperBinary { name = "test-run"; args = [ "--run" "echo bar" ]; })
+    (mkWrapperBinary { name = "test-run-and-set"; args = [ "--run" "export VAR=foo" "--set" "VAR" "bar" ]; })
+    (mkWrapperBinary { name = "test-args"; args = [ "--add-flags" "abc" ]; wrapped = wrappedBinaryArgs; })
+    (mkWrapperBinary { name = "test-prefix"; args = [ "--prefix" "VAR" ":" "abc" ]; })
+    (mkWrapperBinary { name = "test-suffix"; args = [ "--suffix" "VAR" ":" "abc" ]; })
+    (mkWrapperBinary { name = "test-prefix-and-suffix"; args = [ "--prefix" "VAR" ":" "foo" "--suffix" "VAR" ":" "bar" ]; })
+    (mkWrapperBinary { name = "test-prefix-multi"; args = [ "--prefix" "VAR" ":" "abc:foo:foo" ]; })
+    (mkWrapperBinary { name = "test-suffix-each"; args = [ "--suffix-each" "VAR" ":" "foo bar:def" ]; })
+    (mkWrapperBinary { name = "test-prefix-each"; args = [ "--prefix-each" "VAR" ":" "foo bar:def" ]; })
+    (mkWrapperBinary { name = "test-suffix-contents"; args = [ "--suffix-contents" "VAR" ":" "${foofile} ${barfile}" ]; })
+    (mkWrapperBinary { name = "test-prefix-contents"; args = [ "--prefix-contents" "VAR" ":" "${foofile} ${barfile}" ]; })
+  ];
+}
+  (
+    # --argv0 works
+    mkTest "test-argv0" "argv0=foo"
+
+    # --set works
+    + mkTest "test-set" "VAR=abc"
+    # --set overwrites the variable
+    + mkTest "VAR=foo test-set" "VAR=abc"
+    # --set-default works
+    + mkTest "test-set-default" "VAR=abc"
+    # --set-default doesn"t overwrite the variable
+    + mkTest "VAR=foo test-set-default" "VAR=foo"
+    # --unset works
+    + mkTest "VAR=foo test-unset" "VAR="
+
+    # --add-flags works
+    + mkTest "test-args" "abc"
+    # given flags are appended
+    + mkTest "test-args foo" "abc foo"
+
+    # --run works
+    + mkTest "test-run" "bar\nVAR="
+    # --run & --set works
+    + mkTest "test-run-and-set" "VAR=bar"
+
+    # --prefix works
+    + mkTest "VAR=foo test-prefix" "VAR=abc:foo"
+    # sets variable if not set yet
+    + mkTest "test-prefix" "VAR=abc"
+    # prepends value only once
+    + mkTest "VAR=abc test-prefix" "VAR=abc"
+    # Moves value to the front if it already existed
+    + mkTest "VAR=foo:abc test-prefix" "VAR=abc:foo"
+    + mkTest "VAR=abc:foo:bar test-prefix-multi" "VAR=abc:foo:bar"
+    # Doesn't overwrite parts of the string
+    + mkTest "VAR=test:abcde:test test-prefix" "VAR=abc:test:abcde:test"
+    # Only append the value once when given multiple times in a parameter
+    # to makeWrapper
+    + mkTest "test-prefix" "VAR=abc"
+
+
+    # --suffix works
+    + mkTest "VAR=foo test-suffix" "VAR=foo:abc"
+    # sets variable if not set yet
+    + mkTest "test-suffix" "VAR=abc"
+    # adds the same value only once
+    + mkTest "VAR=abc test-suffix" "VAR=abc"
+    + mkTest "VAR=abc:foo test-suffix" "VAR=abc:foo"
+    # --prefix in combination with --suffix
+    + mkTest "VAR=abc test-prefix-and-suffix" "VAR=foo:abc:bar"
+
+    # --suffix-each works
+    + mkTest "VAR=abc test-suffix-each" "VAR=abc:foo:bar:def"
+    # --prefix-each works
+    + mkTest "VAR=abc test-prefix-each" "VAR=bar:def:foo:abc"
+    # --suffix-contents works
+    + mkTest "VAR=abc test-suffix-contents" "VAR=abc:foo:bar"
+    # --prefix-contents works
+    + mkTest "VAR=abc test-prefix-contents" "VAR=bar:foo:abc"
+    + "touch $out"
+  )
diff --git a/nixpkgs/pkgs/test/vim/default.nix b/nixpkgs/pkgs/test/vim/default.nix
index cb3953a63f52..2beb75391ead 100644
--- a/nixpkgs/pkgs/test/vim/default.nix
+++ b/nixpkgs/pkgs/test/vim/default.nix
@@ -14,7 +14,7 @@ in
   ### vim tests
   ##################
   vim_with_vim2nix = vim_configurable.customize {
-    name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ];
+    name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim2nix" ];
   };
 
   # test cases: