Mercurial > projects > dang
annotate tests/run.d @ 186:e1e170c2cd44
Fixed a error in the test program.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 12:50:09 +0200 |
parents | 0ea5d2f3e96b |
children | fda35d57847e |
rev | line source |
---|---|
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
1 // skip |
1 | 2 module run.d; |
3 | |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
4 import tango.core.Array, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
5 tango.io.FileConduit, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
6 tango.io.FileScan, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
7 tango.io.Stdout, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
8 tango.sys.Process, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
9 tango.text.Ascii, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
10 tango.text.Regex, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
11 tango.text.Util; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
12 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
13 // -- Settings -- |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
14 char[] compiler = "./Dang"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
15 char[] test_folder = "tests"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
16 char[] valid_filenames = r"^[^.].*"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
17 bool print_expected = false; |
1 | 18 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
19 // the tests can be sorted by one of the following functions |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
20 bool nameSort (FilePath a, FilePath b) { return a.name < b.name; } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
21 bool pathSort (FilePath a, FilePath b) { return a.toString < b.toString; } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
22 bool modifiedSort(FilePath a, FilePath b) { return a.modified < b.modified; } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
23 bool createdSort (FilePath a, FilePath b) { return a.created < b.created; } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
24 const sortBy = &pathSort; |
1 | 25 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
26 // -- end of settings |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
27 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
28 enum TestResult |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
39
diff
changeset
|
29 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
30 Skipped, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
31 Expected, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
32 Unexpected |
89
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
39
diff
changeset
|
33 } |
a49bb982a7b0
Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents:
39
diff
changeset
|
34 |
1 | 35 void main(char[][] args) |
36 { | |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
37 scope scan = new FileScan; |
154
0ea5d2f3e96b
Parsing "this" as constructor. Also removed regex from the test run program(seg fault - dmd???)
Anders Johnsen <skabet@gmail.com>
parents:
142
diff
changeset
|
38 // scope regex = new Regex(valid_filenames); // DMD FAILS!! ?? |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
39 // Return true for files/folders to include |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
40 bool filter(FilePath p, bool isDir) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
41 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
42 if (isDir) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
43 return p.name[0] != '.'; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
44 else |
154
0ea5d2f3e96b
Parsing "this" as constructor. Also removed regex from the test run program(seg fault - dmd???)
Anders Johnsen <skabet@gmail.com>
parents:
142
diff
changeset
|
45 return p.ext == "d" ; //&& regex.test(p.name); |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
46 } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
47 scan.sweep(test_folder, &filter, true); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
48 FilePath[] files = scan.files; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
49 int total_tests = files.length; |
1 | 50 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
51 // Sort the result by the chosen function - default is the full path |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
52 sort(files, sortBy); |
1 | 53 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
54 int[TestResult.max + 1] results = 0; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
55 foreach (i, ref test; files) |
1 | 56 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
57 begin_test(i + 1, total_tests, test.name); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
58 TestResult res = run_test(test); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
59 results[res] += 1; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
60 end_test(); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
61 } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
62 Stdout.format("\r{,80}\r", " "); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
63 Stdout.newline; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
64 int good = TestResult.Expected; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
65 int bad = TestResult.Unexpected; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
66 int tests_run = results[good] + results[bad]; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
67 Stdout.formatln("{}/{} tests failed", results[bad], tests_run); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
68 } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
69 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
70 void begin_test(int number, int total_tests, char[] name) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
71 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
72 char[60] progressbar = ' '; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
73 int progress = number*progressbar.length/total_tests; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
74 progressbar[0 .. progress] = '='; |
142
1e48315c36fc
Made the test program work with >59 tests.
Anders Johnsen <skabet@gmail.com>
parents:
134
diff
changeset
|
75 if(progress) |
1e48315c36fc
Made the test program work with >59 tests.
Anders Johnsen <skabet@gmail.com>
parents:
134
diff
changeset
|
76 progressbar[progress-1] = '>'; |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
77 Stdout.format("\r{}% - [{}]", 1e2 * number / total_tests, progressbar); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
78 Stdout.flush(); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
79 //Thread.sleep(0.05); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
80 } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
81 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
82 void end_test() { } |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
83 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
84 enum { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
85 NoFail, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
86 CompiletimeFail, |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
87 RuntimeFail |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
88 } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
89 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
90 private int min(int a, int b) { return a < b? a : b; } |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
91 TestResult run_test(ref FilePath p) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
92 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
93 auto file = new FileConduit(p.toString(), FileConduit.ReadExisting); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
94 char[256] content; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
95 int len = file.read(content); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
96 file.close(); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
97 char[] line = content[0 .. min(len, content.find('\n'))]; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
98 |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
99 bool compile = true; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
100 int fail = NoFail; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
101 if (line.length >= 2 && line[0 .. 2] == "//") |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
102 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
103 foreach (command; line[2 .. $].delimiters(",;")) |
186
e1e170c2cd44
Fixed a error in the test program.
Anders Johnsen <skabet@gmail.com>
parents:
154
diff
changeset
|
104 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
105 switch (toLower(substitute(command, " ", ""))) |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
106 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
107 case "skip", "dontcompile": |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
108 compile = false; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
109 break; |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
110 case "fail", "compilefail", |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
111 "compiletimefail", "failatcompiletime": |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
112 fail = CompiletimeFail; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
113 break; |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
114 case "runtime", "runtimefail", "failatruntime": |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
115 fail = RuntimeFail; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
116 Stderr("== Compiled tests will not be run! ==").newline; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
117 return TestResult.Skipped; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
118 default: |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
119 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
120 } |
186
e1e170c2cd44
Fixed a error in the test program.
Anders Johnsen <skabet@gmail.com>
parents:
154
diff
changeset
|
121 break; |
e1e170c2cd44
Fixed a error in the test program.
Anders Johnsen <skabet@gmail.com>
parents:
154
diff
changeset
|
122 } |
1 | 123 } |
124 | |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
125 if (compile) |
1 | 126 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
127 auto process = new Process(compiler, "--gen-llvm", p.toString()); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
128 process.execute(); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
129 auto result = process.wait(); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
130 return resultOf(p, result.status, fail); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
131 } |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
132 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
133 return TestResult.Skipped; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
134 } |
1 | 135 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
136 private TestResult resultOf(FilePath p, int result, int expected) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
137 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
138 char[] good(char[] s) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
139 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
140 version (Posix) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
141 return "\033[1;32m" ~ s ~ "\033[m"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
142 else |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
143 return s; |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
144 } |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
145 |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
146 char[] bad(char[] s) |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
147 { |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
148 s = s ~ " - Unexpected"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
149 version (Posix) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
150 return "\033[1;31m" ~ s ~ "\033[m"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
151 else |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
152 return s; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
153 } |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
154 |
186
e1e170c2cd44
Fixed a error in the test program.
Anders Johnsen <skabet@gmail.com>
parents:
154
diff
changeset
|
155 bool unexpected = expected == 0 ? result != 0 : result == 0; |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
156 auto f = unexpected? &bad : &good; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
157 char[] s = (result == 0)? "SUCCESS" : "FAILURE"; |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
158 // always print if unexpeted, otherwise check the settings |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
159 if (unexpected || print_expected) |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
160 { |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
161 Stdout.format("\r{,80}\r", " "); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
162 Stdout.format(" {,-45}", p); |
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
163 Stdout(f(s)).newline; |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
164 } |
134
570a4917413a
Changed the test-program.
Anders Halager <halager@gmail.com>
parents:
89
diff
changeset
|
165 return unexpected? TestResult.Unexpected : TestResult.Expected; |
1 | 166 } |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
167 |