1 module unit_threaded.ut.integration;
2 
3 import unit_threaded.integration;
4 
5 @safe unittest {
6     auto sb = Sandbox();
7     assert(sb.testPath != "");
8 }
9 
10 @safe unittest {
11     import std.file: exists, rmdirRecurse;
12     import std.path: buildPath;
13     import unit_threaded.should;
14 
15     Sandbox.sandboxesPath.shouldEqual(Sandbox.defaultSandboxesPath);
16 
17     immutable newPath = buildPath("foo", "bar", "baz");
18     assert(!newPath.exists);
19     Sandbox.setPath(newPath);
20     assert(newPath.exists);
21     scope(exit) () @trusted { rmdirRecurse("foo"); }();
22     Sandbox.sandboxesPath.shouldEqual(newPath);
23 
24     with(immutable Sandbox()) {
25         writeFile("newPath.txt");
26         assert(buildPath(newPath, testPath, "newPath.txt").exists);
27     }
28 
29     Sandbox.resetPath;
30     Sandbox.sandboxesPath.shouldEqual(Sandbox.defaultSandboxesPath);
31 }
32 
33 
34 @safe unittest {
35     import std.file: exists;
36     import std.path: buildPath;
37 
38     with(immutable Sandbox()) {
39         assert(!buildPath(testPath, "foo.txt").exists);
40         writeFile("foo.txt");
41         assert(buildPath(testPath, "foo.txt").exists);
42     }
43 }
44 
45 @safe unittest {
46     import std.file: exists;
47     import std.path: buildPath;
48 
49     with(immutable Sandbox()) {
50         writeFile("foo/bar.txt");
51         assert(buildPath(testPath, "foo", "bar.txt").exists);
52     }
53 }
54 
55 @safe unittest {
56     with(immutable Sandbox()) {
57         import unit_threaded.should;
58 
59         shouldExist("bar.txt").shouldThrow;
60         writeFile("bar.txt");
61         shouldExist("bar.txt");
62     }
63 }
64 
65 @safe unittest {
66     with(immutable Sandbox()) {
67         import unit_threaded.should;
68 
69         shouldNotExist("baz.txt");
70         writeFile("baz.txt");
71         shouldNotExist("baz.txt").shouldThrow;
72     }
73 }
74 
75 
76 @safe unittest {
77     with(immutable Sandbox()) {
78         import unit_threaded.should;
79 
80         writeFile("lines.txt", ["foo", "toto"]);
81         shouldEqualLines("lines.txt", ["foo", "bar"]).shouldThrow;
82         shouldEqualLines("lines.txt", ["foo", "toto"]);
83     }
84 }
85 
86 version(Windows) {
87     @safe unittest {
88         with(immutable Sandbox()) {
89             writeFile("newline.txt", "\r\n");
90             shouldEqualContent("newline.txt", "\r\n\n");
91         }
92     }
93 }
94 
95 @safe unittest {
96     with(immutable Sandbox()) {
97         import unit_threaded.should;
98 
99         shouldSucceed("definitely_not_an_existing_command_or_executable").shouldThrow;
100         shouldFail("definitely_not_an_existing_command_or_executable");
101 
102         writeFile("hello.d", q{import std; void main() {writeln("hello");}});
103 
104         version(LDC) {
105             shouldExecuteOk(["ldc2", inSandboxPath("hello.d")]);
106         } else {
107             shouldExecuteOk(["dmd", inSandboxPath("hello.d")]);
108         }
109         
110         version (Windows)
111             immutable exe = "hello.exe";
112         else
113             immutable exe = "hello";
114         shouldSucceed(inSandboxPath(exe));
115         shouldFail(inSandboxPath(exe)).shouldThrow;
116     }
117 }