nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1/*
2 To run:
3
4 cd nixpkgs
5 nix-build -A tests.trivial-builders.writeTextFile
6
7 or to run an individual test case
8
9 cd nixpkgs
10 nix-build -A tests.trivial-builders.writeTextFile.foo
11*/
12{
13 lib,
14 runCommand,
15 runtimeShell,
16 writeTextFile,
17}:
18let
19 veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes'';
20in
21lib.recurseIntoAttrs {
22
23 different-exe-name =
24 let
25 pkg = writeTextFile {
26 name = "bar";
27 destination = "/bin/foo";
28 executable = true;
29 text = ''
30 #!${runtimeShell}
31 echo hi
32 '';
33 };
34 in
35 assert pkg.meta.mainProgram == "foo";
36 assert baseNameOf (lib.getExe pkg) == "foo";
37 assert pkg.name == "bar";
38 runCommand "test-writeTextFile-different-exe-name" { } ''
39 PATH="${lib.makeBinPath [ pkg ]}:$PATH"
40 x=$(foo)
41 [[ "$x" == hi ]]
42 touch $out
43 '';
44
45 weird-name = writeTextFile {
46 name = "weird-names";
47 destination = "/etc/${veryWeirdName}";
48 text = ''passed!'';
49 checkPhase = ''
50 # intentionally hardcode everything here, to make sure
51 # Nix does not mess with file paths
52
53 name="here's a name with some \"bad\" characters, like spaces and quotes"
54 fullPath="$out/etc/$name"
55
56 if [ -f "$fullPath" ]; then
57 echo "[PASS] File exists!"
58 else
59 echo "[FAIL] File was not created at expected path!"
60 exit 1
61 fi
62
63 content=$(<"$fullPath")
64 expected="passed!"
65
66 if [ "$content" = "$expected" ]; then
67 echo "[PASS] Contents match!"
68 else
69 echo "[FAIL] File contents don't match!"
70 echo " Expected: $expected"
71 echo " Got: $content"
72 exit 2
73 fi
74 '';
75 };
76}