Mercurial > projects > dang
annotate tests/run.d @ 20:95e3940d91d4
Small changes to the text program.
* Sort test-cases by name
* Color output on linux
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 20:28:49 +0200 |
parents | 2a7b05d2e4f9 |
children | 1a7a308f75b2 |
rev | line source |
---|---|
1 | 1 module run.d; |
2 | |
3 import tango.io.Stdout, | |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
4 tango.core.Array, |
1 | 5 tango.io.FilePath, |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
6 tango.io.GrowBuffer, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
7 tango.io.UnicodeFile, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
8 tango.io.stream.BufferStream, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
9 tango.text.Util, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
10 tango.io.protocol.Reader, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
11 tango.io.protocol.Writer, |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
12 tango.text.Unicode, |
1 | 13 tango.sys.Process; |
14 | |
15 | |
16 char[] prog = "./Dang"; | |
17 | |
18 void main(char[][] args) | |
19 { | |
20 auto cPath = FilePath("tests"); | |
21 | |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
22 ubyte success_success, success_failure, failure_failure, failure_success; |
1 | 23 |
24 foreach( path ; cPath.toList((FilePath path, bool isFolder){return isFolder;})) | |
25 { | |
26 Stdout(path.name)(":").newline; | |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
27 auto paths = path.toList( |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
28 (FilePath path, bool isFolder) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
29 { |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
30 if(path.ext == "d" && path.name[0] != '.') |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
31 return true; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
32 return false; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
33 }); |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
34 sort(paths, (FilePath a, FilePath b) { return a.name < b.name; }); |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
35 foreach (p ; paths) |
1 | 36 { |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
37 auto test = new Test(p); |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
38 ubyte result = test.run(); |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
39 |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
40 switch(result) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
41 { |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
42 case 0: |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
43 success_success++; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
44 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
45 case 1: |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
46 success_failure++; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
47 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
48 case 2: |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
49 failure_failure++; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
50 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
51 case 3: |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
52 failure_success++; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
53 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
54 } |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
55 |
1 | 56 } |
57 } | |
58 | |
59 Stdout().newline.newline() | |
60 ("Result:").newline() | |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
61 (" - Succes/Success: ")(success_success).newline() |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
62 (" - Succes/Failure: ")(success_failure).newline() |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
63 (" - Failure/Failure: ")(failure_failure).newline() |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
64 (" - Failure/Success: ")(failure_success).newline; |
1 | 65 } |
66 | |
67 class Test | |
68 { | |
69 FilePath target; | |
70 public this(FilePath target) | |
71 { | |
72 this.target = target; | |
73 } | |
74 | |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
75 public ubyte run() |
1 | 76 { |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
77 auto process = new Process(prog,"--gen-llvm",target.path~target.file); |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
78 |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
79 auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8); |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
80 |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
81 int mode; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
82 |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
83 char[] data = file.read; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
84 if(data.length > 6 && data[0..6] == "//test") |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
85 { |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
86 char[] str = data.splitLines()[0][6..$]; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
87 |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
88 switch(toLower(trim(str))) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
89 { |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
90 case "fail": |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
91 case "failure": |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
92 mode = 1; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
93 break; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
94 default: |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
95 mode = 0; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
96 } |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
97 } |
1 | 98 |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
99 Stdout.format(" {,-25}", target.file); |
1 | 100 |
101 process.execute; | |
17
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
102 auto result = process.wait; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
103 |
17
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
104 if(result.status == 0) |
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
105 { |
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
106 auto llvm_process = new Process("llvm-as"); |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
107 llvm_process.execute; |
17
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
108 llvm_process.stdin.copy(process.stdout); |
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
109 llvm_process.stdin.close(); |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
110 result = llvm_process.wait; |
17
2a7b05d2e4f9
Fixed tests.run - now works really nice
Anders Johnsen <skabet@gmail.com>
parents:
15
diff
changeset
|
111 } |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
112 |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
113 return resultOf(result.status, mode); |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
114 } |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
115 |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
116 private int resultOf(int status, int mode) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
117 { |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
118 char[] good(char[] s) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
119 { |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
120 version (Posix) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
121 return "\033[1;32m" ~ s ~ "\033[m"; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
122 else |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
123 return s; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
124 } |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
125 |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
126 char[] bad(char[] s) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
127 { |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
128 version (Posix) |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
129 return "\033[1;31m" ~ s ~ "\033[m"; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
130 else |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
131 return s; |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
132 } |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
133 |
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
134 if(status == 0) |
1 | 135 { |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
136 if(mode == 0) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
137 { |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
138 Stdout(good("SUCCES")).newline; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
139 return 0; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
140 } |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
141 if(mode == 1) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
142 { |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
143 Stdout(bad("SUCCES - Unexpected")).newline; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
144 return 3; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
145 } |
1 | 146 } |
147 else | |
148 { | |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
149 if(mode == 1) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
150 { |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
151 Stdout(good("FAILURE")).newline; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
152 return 2; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
153 } |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
154 if(mode == 0) |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
155 { |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
156 Stdout(bad("FAILURE - Unexpected")).newline; |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
157 return 1; |
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
158 } |
1 | 159 } |
20
95e3940d91d4
Small changes to the text program.
Anders Halager <halager@gmail.com>
parents:
17
diff
changeset
|
160 } |
1 | 161 } |
15
59bfbaf8847f
Updates to run.d - still errors
Anders Johnsen <skabet@gmail.com>
parents:
1
diff
changeset
|
162 |