comparison tests/run.d @ 89:a49bb982a7b0 new_gen

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.
author Anders Johnsen <skabet@gmail.com>
date Sun, 04 May 2008 20:27:01 +0200
parents 1a7a308f75b2
children 570a4917413a
comparison
equal deleted inserted replaced
88:eb5b2c719a39 89:a49bb982a7b0
11 tango.io.protocol.Writer, 11 tango.io.protocol.Writer,
12 tango.text.Unicode, 12 tango.text.Unicode,
13 tango.sys.Process; 13 tango.sys.Process;
14 14
15 15
16 enum
17 {
18 SuccessSuccess,
19 SuccessFailure,
20 FailureSuccess,
21 FailureFailure,
22 }
23
16 char[] prog = "./Dang"; 24 char[] prog = "./Dang";
17 25
18 void main(char[][] args) 26 void main(char[][] args)
19 { 27 {
20 auto cPath = FilePath("tests"); 28 auto cPath = FilePath("tests");
37 auto test = new Test(p); 45 auto test = new Test(p);
38 ubyte result = test.run(); 46 ubyte result = test.run();
39 47
40 switch(result) 48 switch(result)
41 { 49 {
42 case 0: 50 case SuccessSuccess:
43 success_success++; 51 success_success++;
44 break; 52 break;
45 case 1: 53 case SuccessFailure:
46 success_failure++; 54 success_failure++;
47 break; 55 break;
48 case 2: 56 case FailureFailure:
49 failure_failure++; 57 failure_failure++;
50 break; 58 break;
51 case 3: 59 case FailureSuccess:
52 failure_success++; 60 failure_success++;
53 break; 61 break;
54 } 62 }
55 63
56 } 64 }
57 } 65 }
58 66
59 Stdout().newline.newline() 67 Stdout().newline.newline()
60 ("Result:").newline() 68 ("Result:").newline()
61 (" - Succes/Success: ")(success_success).newline() 69 (" - Success/Success: ")(success_success).newline()
62 (" - Succes/Failure: ")(success_failure).newline() 70 (" - Success/Failure: ")(success_failure).newline()
63 (" - Failure/Failure: ")(failure_failure).newline() 71 (" - Failure/Failure: ")(failure_failure).newline()
64 (" - Failure/Success: ")(failure_success).newline; 72 (" - Failure/Success: ")(failure_success).newline;
65 } 73 }
66 74
67 class Test 75 class Test
68 { 76 {
77 enum TestValue
78 {
79 Success = 0,
80 Lexer = 2,
81 Parser = 3,
82 Gen = 4,
83
84 Fail = 100
85 }
86
69 FilePath target; 87 FilePath target;
88
89 TestValue[int] testValues;
90
70 public this(FilePath target) 91 public this(FilePath target)
71 { 92 {
72 this.target = target; 93 this.target = target;
73 } 94 }
74 95
76 { 97 {
77 auto process = new Process(prog,"--gen-llvm",target.path~target.file); 98 auto process = new Process(prog,"--gen-llvm",target.path~target.file);
78 99
79 auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8); 100 auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8);
80 101
81 int mode; 102 TestValue mode;
82 103
83 char[] data = file.read; 104 char[] data = file.read;
84 if(data.length > 6 && data[0..6] == "//test") 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")
85 { 121 {
86 char[] str = data.splitLines()[0][6..$]; 122 char[] str = data.splitLines()[0][6..$];
87 123
88 switch(toLower(trim(str))) 124 switch(toLower(trim(str)))
89 { 125 {
93 break; 129 break;
94 default: 130 default:
95 mode = 0; 131 mode = 0;
96 } 132 }
97 } 133 }
98 134 */
99 Stdout.format(" {,-25}", target.file); 135 Stdout.format(" {,-25}", target.file);
100 136
101 process.execute; 137 process.execute;
102 auto result = process.wait; 138 auto result = process.wait;
103 139
113 */ 149 */
114 150
115 return resultOf(result.status, mode); 151 return resultOf(result.status, mode);
116 } 152 }
117 153
118 private int resultOf(int status, int mode) 154 private int resultOf(int status, TestValue mode)
119 { 155 {
120 char[] good(char[] s) 156 char[] good(char[] s)
121 { 157 {
122 version (Posix) 158 version (Posix)
123 return "\033[1;32m" ~ s ~ "\033[m"; 159 return "\033[1;32m" ~ s ~ "\033[m";
133 return s; 169 return s;
134 } 170 }
135 171
136 if(status == 0) 172 if(status == 0)
137 { 173 {
138 if(mode == 0) 174 if(mode == TestValue.Success)
139 { 175 {
140 Stdout(good("SUCCES")).newline; 176 Stdout(good("SUCCESS")).newline;
141 return 0; 177 return SuccessSuccess;
142 } 178 }
143 if(mode == 1) 179 if(mode == TestValue.Fail)
144 { 180 {
145 Stdout(bad("SUCCES - Unexpected")).newline; 181 Stdout(bad("SUCCESS - Unexpected")).newline;
146 return 3; 182 return FailureSuccess;
147 } 183 }
148 } 184 }
149 else 185 else
150 { 186 {
151 if(mode == 1) 187 if(mode == TestValue.Fail)
152 { 188 {
153 Stdout(good("FAILURE")).newline; 189 Stdout(good("FAILURE")).newline;
154 return 2; 190 return FailureFailure;
155 } 191 }
156 if(mode == 0) 192 if(mode == TestValue.Success)
157 { 193 {
158 Stdout(bad("FAILURE - Unexpected")).newline; 194 Stdout(bad("FAILURE - Unexpected")).newline;
159 return 1; 195 return SuccessFailure;
160 } 196 }
161 } 197 }
162 } 198 }
163 } 199 }
164 200