Mercurial > projects > dang
comparison tests/run.d @ 206:d3c148ca429b
Major moving of files. all src now goes into src, all docs in docs.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 18:14:56 +0200 |
parents | |
children | 41ccd50e7cbc |
comparison
equal
deleted
inserted
replaced
205:8387cbaa85ab | 206:d3c148ca429b |
---|---|
1 module run.d; | |
2 | |
3 import tango.io.Stdout, | |
4 tango.core.Array, | |
5 tango.io.FilePath, | |
6 tango.io.GrowBuffer, | |
7 tango.io.UnicodeFile, | |
8 tango.io.stream.BufferStream, | |
9 tango.text.Util, | |
10 tango.io.protocol.Reader, | |
11 tango.io.protocol.Writer, | |
12 tango.text.Unicode, | |
13 tango.sys.Process; | |
14 | |
15 | |
16 enum | |
17 { | |
18 SuccessSuccess, | |
19 SuccessFailure, | |
20 FailureSuccess, | |
21 FailureFailure, | |
22 } | |
23 | |
24 char[] prog = "./Dang"; | |
25 | |
26 void main(char[][] args) | |
27 { | |
28 auto cPath = FilePath("tests"); | |
29 | |
30 ubyte success_success, success_failure, failure_failure, failure_success; | |
31 | |
32 foreach( path ; cPath.toList((FilePath path, bool isFolder){return isFolder;})) | |
33 { | |
34 Stdout(path.name)(":").newline; | |
35 auto paths = path.toList( | |
36 (FilePath path, bool isFolder) | |
37 { | |
38 if(path.ext == "d" && path.name[0] != '.') | |
39 return true; | |
40 return false; | |
41 }); | |
42 sort(paths, (FilePath a, FilePath b) { return a.name < b.name; }); | |
43 foreach (p ; paths) | |
44 { | |
45 auto test = new Test(p); | |
46 ubyte result = test.run(); | |
47 | |
48 switch(result) | |
49 { | |
50 case SuccessSuccess: | |
51 success_success++; | |
52 break; | |
53 case SuccessFailure: | |
54 success_failure++; | |
55 break; | |
56 case FailureFailure: | |
57 failure_failure++; | |
58 break; | |
59 case FailureSuccess: | |
60 failure_success++; | |
61 break; | |
62 } | |
63 | |
64 } | |
65 } | |
66 | |
67 Stdout().newline.newline() | |
68 ("Result:").newline() | |
69 (" - Success/Success: ")(success_success).newline() | |
70 (" - Success/Failure: ")(success_failure).newline() | |
71 (" - Failure/Failure: ")(failure_failure).newline() | |
72 (" - Failure/Success: ")(failure_success).newline; | |
73 } | |
74 | |
75 class Test | |
76 { | |
77 enum TestValue | |
78 { | |
79 Success = 0, | |
80 Lexer = 2, | |
81 Parser = 3, | |
82 Gen = 4, | |
83 | |
84 Fail = 100 | |
85 } | |
86 | |
87 FilePath target; | |
88 | |
89 TestValue[int] testValues; | |
90 | |
91 public this(FilePath target) | |
92 { | |
93 this.target = target; | |
94 } | |
95 | |
96 public ubyte run() | |
97 { | |
98 auto process = new Process(prog,"--gen-llvm",target.path~target.file); | |
99 | |
100 auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8); | |
101 | |
102 TestValue mode; | |
103 | |
104 char[] data = file.read; | |
105 char[][] commands = split(splitLines(data)[0], " "); | |
106 if(commands[0] == "//fail") | |
107 { | |
108 mode = TestValue.Fail; | |
109 if(commands.length > 1) | |
110 { | |
111 try | |
112 { | |
113 int i = Integer.toInt(commands[1]); | |
114 if(i in testValues) | |
115 mode = testValues[i]; | |
116 } | |
117 catch{} | |
118 } | |
119 } | |
120 /* if(data.length > 6 && data[0..6] == "//fail") | |
121 { | |
122 char[] str = data.splitLines()[0][6..$]; | |
123 | |
124 switch(toLower(trim(str))) | |
125 { | |
126 case "fail": | |
127 case "failure": | |
128 mode = 1; | |
129 break; | |
130 default: | |
131 mode = 0; | |
132 } | |
133 } | |
134 */ | |
135 Stdout.format(" {,-25}", target.file); | |
136 | |
137 process.execute; | |
138 auto result = process.wait; | |
139 | |
140 /* | |
141 if(result.status == 0) | |
142 { | |
143 auto llvm_process = new Process("llvm-as"); | |
144 llvm_process.execute; | |
145 llvm_process.stdin.copy(process.stdout); | |
146 llvm_process.stdin.close(); | |
147 result = llvm_process.wait; | |
148 } | |
149 */ | |
150 | |
151 return resultOf(result.status, mode); | |
152 } | |
153 | |
154 private int resultOf(int status, TestValue mode) | |
155 { | |
156 char[] good(char[] s) | |
157 { | |
158 version (Posix) | |
159 return "\033[1;32m" ~ s ~ "\033[m"; | |
160 else | |
161 return s; | |
162 } | |
163 | |
164 char[] bad(char[] s) | |
165 { | |
166 version (Posix) | |
167 return "\033[1;31m" ~ s ~ "\033[m"; | |
168 else | |
169 return s; | |
170 } | |
171 | |
172 if(status == 0) | |
173 { | |
174 if(mode == TestValue.Success) | |
175 { | |
176 Stdout(good("SUCCESS")).newline; | |
177 return SuccessSuccess; | |
178 } | |
179 if(mode == TestValue.Fail) | |
180 { | |
181 Stdout(bad("SUCCESS - Unexpected")).newline; | |
182 return FailureSuccess; | |
183 } | |
184 } | |
185 else | |
186 { | |
187 if(mode == TestValue.Fail) | |
188 { | |
189 Stdout(good("FAILURE")).newline; | |
190 return FailureFailure; | |
191 } | |
192 if(mode == TestValue.Success) | |
193 { | |
194 Stdout(bad("FAILURE - Unexpected")).newline; | |
195 return SuccessFailure; | |
196 } | |
197 } | |
198 } | |
199 } | |
200 |