diff options
-rw-r--r-- | pkgs/build-support/trivial-builders/test/write-text-file.nix | 34 | ||||
-rw-r--r-- | pkgs/test/default.nix | 1 |
2 files changed, 35 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 + ''; +} diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 4110327946d9b..d572c03906096 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -59,6 +59,7 @@ with pkgs; trivial-builders = recurseIntoAttrs { writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {}; + writeTextFile = callPackage ../build-support/trivial-builders/test/write-text-file.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 {}; |