about summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders/test
diff options
context:
space:
mode:
authorK900 <me@0upti.me>2022-03-03 10:26:30 +0300
committerK900 <me@0upti.me>2022-03-10 13:30:46 +0300
commit7e3c503257490763fac7ceacbd33e551a0811e37 (patch)
treebd12c2c672130db5f6bf1c67c79e6c8e7b5f5e60 /pkgs/build-support/trivial-builders/test
parent267f618da56d8ef12c3ada98d08c032549afadc2 (diff)
build-support/writeTextFile: add test for weird file names
Diffstat (limited to 'pkgs/build-support/trivial-builders/test')
-rw-r--r--pkgs/build-support/trivial-builders/test/write-text-file.nix34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders/test/write-text-file.nix b/pkgs/build-support/trivial-builders/test/write-text-file.nix
new file mode 100644
index 0000000000000..ac83a75fca4ab
--- /dev/null
+++ b/pkgs/build-support/trivial-builders/test/write-text-file.nix
@@ -0,0 +1,34 @@
+{ writeTextFile }:
+let
+  veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes'';
+in writeTextFile {
+  name = "weird-names";
+  destination = "/etc/${veryWeirdName}";
+  text = ''passed!'';
+  checkPhase = ''
+    # intentionally hardcode everything here, to make sure
+    # Nix does not mess with file paths
+
+    name="here's a name with some \"bad\" characters, like spaces and quotes"
+    fullPath="$out/etc/$name"
+
+    if [ -f "$fullPath" ]; then
+      echo "[PASS] File exists!"
+    else
+      echo "[FAIL] File was not created at expected path!"
+      exit 1
+    fi
+
+    content=$(<"$fullPath")
+    expected="passed!"
+
+    if [ "$content" = "$expected" ]; then
+      echo "[PASS] Contents match!"
+    else
+      echo "[FAIL] File contents don't match!"
+      echo "       Expected: $expected"
+      echo "       Got:      $content"
+      exit 2
+    fi
+  '';
+}