about summary refs log tree commit diff
path: root/pkgs/test/substitute
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2024-02-09 04:30:09 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2024-02-29 00:35:27 +0100
commitcd5dc76d8340c38487d1b48a3ba090683fa35493 (patch)
treecc863ca7b4dfb80e3df0f31142af877b723707e2 /pkgs/test/substitute
parent0151be1b329b9b8eeed6e035a415f571b49ae356 (diff)
downloadnixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar.gz
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar.bz2
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar.lz
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar.xz
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.tar.zst
nixlib-cd5dc76d8340c38487d1b48a3ba090683fa35493.zip
substitute: Deprecate `replacements`, introduce `replacementsList`
Also:
- Add tests
- Treewide update
- Improve docs
Diffstat (limited to 'pkgs/test/substitute')
-rw-r--r--pkgs/test/substitute/default.nix96
1 files changed, 96 insertions, 0 deletions
diff --git a/pkgs/test/substitute/default.nix b/pkgs/test/substitute/default.nix
new file mode 100644
index 000000000000..3ff346b14658
--- /dev/null
+++ b/pkgs/test/substitute/default.nix
@@ -0,0 +1,96 @@
+{ substitute, testers, runCommand }:
+let
+  # Ofborg doesn't allow any traces on stderr,
+  # so mock `lib` to not trace warnings,
+  # because substitute gives a deprecation warning
+  substituteSilent = substitute.override (prevArgs: {
+    lib = prevArgs.lib.extend (finalLib: prevLib: {
+      trivial = prevLib.trivial // {
+        warn = msg: value: value;
+      };
+    });
+  });
+in {
+
+  substitutions = testers.testEqualContents {
+    assertion = "substitutions-spaces";
+    actual = substitute {
+      src = builtins.toFile "source" ''
+        Hello world!
+      '';
+      substitutions = [
+        "--replace-fail"
+        "Hello world!"
+        "Yo peter!"
+      ];
+    };
+    expected = builtins.toFile "expected" ''
+      Yo peter!
+    '';
+  };
+
+  legacySingleReplace = testers.testEqualContents {
+    assertion = "substitute-single-replace";
+    actual = substituteSilent {
+      src = builtins.toFile "source" ''
+        Hello world!
+      '';
+      replacements = [
+        "--replace-fail" "world" "paul"
+      ];
+    };
+    expected = builtins.toFile "expected" ''
+      Hello paul!
+    '';
+  };
+
+  legacyString = testers.testEqualContents {
+    assertion = "substitute-string";
+    actual = substituteSilent {
+      src = builtins.toFile "source" ''
+        Hello world!
+      '';
+      # Not great that this works at all, but is supported
+      replacements = "--replace-fail world string";
+    };
+    expected = builtins.toFile "expected" ''
+      Hello string!
+    '';
+  };
+
+  legacySingleArg = testers.testEqualContents {
+    assertion = "substitute-single-arg";
+    actual = substituteSilent {
+      src = builtins.toFile "source" ''
+        Hello world!
+      '';
+      # Not great that this works at all, but is supported
+      replacements = [
+        "--replace-fail world list"
+      ];
+    };
+    expected = builtins.toFile "expected" ''
+      Hello list!
+    '';
+  };
+
+  legacyVar = testers.testEqualContents {
+    assertion = "substitute-var";
+    actual = substituteSilent {
+      src = builtins.toFile "source" ''
+        @greeting@ @name@!
+      '';
+      # Not great that this works at all, but is supported
+      replacements = [
+        "--subst-var name"
+        "--subst-var-by greeting Yo"
+      ];
+      name = "peter";
+    };
+    expected = builtins.toFile "expected" ''
+      Yo peter!
+    '';
+  };
+
+
+}