1 module app;
2 
3 import tested;
4 
5 
6 void main()
7 {
8 	version (unittest) {} else {
9 		import std.stdio;
10 		writeln(`This application does nothing. Run with "dub --build=unittest"`);
11 	}
12 }
13 
14 shared static this()
15 {
16 	version (unittest) {
17 		import core.runtime;
18 		Runtime.moduleUnitTester = () => true;
19 		runUnitTests!app(new JsonTestResultWriter("results.json"));
20 		assert(runUnitTests!app(new ConsoleTestResultWriter), "Unit tests failed.");
21 	}
22 }
23 
24 
25 @name("arithmetic")
26 unittest {
27 	int i = 3;
28 	assert(i == 3);
29 	i *= 2;
30 	assert(i == 6);
31 	i += 5;
32 	assert(i == 11);
33 }
34 
35 @name("arithmetic2")
36 unittest {
37 	int i = 3;
38 	i += 10;
39 	assert(i == 11); // fail
40 }
41 
42 @name("int array")
43 unittest {
44 	import core.thread;
45 
46 	int[] ints;
47 	foreach (i; 0 .. 1000) {
48 		ints ~= i;
49 		Thread.sleep(1.msecs);
50 		assert(ints.length == i+1);
51 	}
52 	assert(ints.length == 1000);
53 }
54 
55 @name("limited int array")
56 unittest {
57 	import core.thread;
58 
59 	int[] ints;
60 	foreach (i; 0 .. 1000) {
61 		ints ~= i;
62 		Thread.sleep(1.msecs);
63 		assert(ints.length == i+1);
64 		assert(ints.length < 900, "Too many items");
65 	}
66 }