diff options
Diffstat (limited to 'src/tools/mkunit.cpp')
-rw-r--r-- | src/tools/mkunit.cpp | 962 |
1 files changed, 481 insertions, 481 deletions
diff --git a/src/tools/mkunit.cpp b/src/tools/mkunit.cpp index d634feb..96deb6b 100644 --- a/src/tools/mkunit.cpp +++ b/src/tools/mkunit.cpp | |||
@@ -17,236 +17,236 @@ using namespace Bu; | |||
17 | class Test | 17 | class Test |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | Test() : | 20 | Test() : |
21 | bExpectPass( true ) | 21 | bExpectPass( true ) |
22 | { | 22 | { |
23 | } | 23 | } |
24 | 24 | ||
25 | Bu::String sName; | 25 | Bu::String sName; |
26 | bool bExpectPass; | 26 | bool bExpectPass; |
27 | }; | 27 | }; |
28 | typedef Bu::List<Test> TestList; | 28 | typedef Bu::List<Test> TestList; |
29 | 29 | ||
30 | class Suite | 30 | class Suite |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | Bu::String sName; | 33 | Bu::String sName; |
34 | TestList lTest; | 34 | TestList lTest; |
35 | }; | 35 | }; |
36 | //typedef Bu::List<Suite> SuiteList; | 36 | //typedef Bu::List<Suite> SuiteList; |
37 | 37 | ||
38 | enum TokType | 38 | enum TokType |
39 | { | 39 | { |
40 | tokFluff, | 40 | tokFluff, |
41 | tokSuite, | 41 | tokSuite, |
42 | tokTest, | 42 | tokTest, |
43 | tokChar, | 43 | tokChar, |
44 | tokBlock, | 44 | tokBlock, |
45 | tokEof | 45 | tokEof |
46 | }; | 46 | }; |
47 | 47 | ||
48 | Bu::Formatter &operator<<( Bu::Formatter &f, TokType t ) | 48 | Bu::Formatter &operator<<( Bu::Formatter &f, TokType t ) |
49 | { | 49 | { |
50 | switch( t ) | 50 | switch( t ) |
51 | { | 51 | { |
52 | case tokFluff: return f << "tokFluff"; | 52 | case tokFluff: return f << "tokFluff"; |
53 | case tokSuite: return f << "tokSuite"; | 53 | case tokSuite: return f << "tokSuite"; |
54 | case tokTest: return f << "tokTest"; | 54 | case tokTest: return f << "tokTest"; |
55 | case tokChar: return f << "tokChar"; | 55 | case tokChar: return f << "tokChar"; |
56 | case tokBlock: return f << "tokBlock"; | 56 | case tokBlock: return f << "tokBlock"; |
57 | case tokEof: return f << "tokEof"; | 57 | case tokEof: return f << "tokEof"; |
58 | } | 58 | } |
59 | 59 | ||
60 | return f; | 60 | return f; |
61 | } | 61 | } |
62 | 62 | ||
63 | Bu::Formatter &operator<<( Bu::Formatter &f, const Test &t ) | 63 | Bu::Formatter &operator<<( Bu::Formatter &f, const Test &t ) |
64 | { | 64 | { |
65 | return f << "{" << t.sName << ", bExpectPass=" << t.bExpectPass << "}"; | 65 | return f << "{" << t.sName << ", bExpectPass=" << t.bExpectPass << "}"; |
66 | } | 66 | } |
67 | 67 | ||
68 | Bu::Formatter &operator<<( Bu::Formatter &f, const Suite &s ) | 68 | Bu::Formatter &operator<<( Bu::Formatter &f, const Suite &s ) |
69 | { | 69 | { |
70 | return f << "Suite[" << s.sName << "] = " << s.lTest << f.nl; | 70 | return f << "Suite[" << s.sName << "] = " << s.lTest << f.nl; |
71 | } | 71 | } |
72 | 72 | ||
73 | class Parser | 73 | class Parser |
74 | { | 74 | { |
75 | public: | 75 | public: |
76 | Parser( const Bu::String &sFile ) : | 76 | Parser( const Bu::String &sFile ) : |
77 | sIn( sFile ), | 77 | sIn( sFile ), |
78 | fIn( sFile, File::Read ), | 78 | fIn( sFile, File::Read ), |
79 | bIn( fIn ), | 79 | bIn( fIn ), |
80 | cBuf( 0 ), | 80 | cBuf( 0 ), |
81 | bAvail( false ), | 81 | bAvail( false ), |
82 | eMode( mRoot ), | 82 | eMode( mRoot ), |
83 | iLine( 1 ), | 83 | iLine( 1 ), |
84 | iChar( 0 ), | 84 | iChar( 0 ), |
85 | iDepth( 0 ) | 85 | iDepth( 0 ) |
86 | { | 86 | { |
87 | } | 87 | } |
88 | 88 | ||
89 | char nextChar() | 89 | char nextChar() |
90 | { | 90 | { |
91 | if( bAvail ) | 91 | if( bAvail ) |
92 | return cBuf; | 92 | return cBuf; |
93 | 93 | ||
94 | if( bIn.read( &cBuf, 1 ) < 1 ) | 94 | if( bIn.read( &cBuf, 1 ) < 1 ) |
95 | throw Bu::ExceptionBase("End of stream"); | 95 | throw Bu::ExceptionBase("End of stream"); |
96 | bAvail = true; | 96 | bAvail = true; |
97 | 97 | ||
98 | if( cBuf == '\n' ) | 98 | if( cBuf == '\n' ) |
99 | { | 99 | { |
100 | iLine++; | 100 | iLine++; |
101 | iChar = 0; | 101 | iChar = 0; |
102 | } | 102 | } |
103 | else | 103 | else |
104 | iChar++; | 104 | iChar++; |
105 | 105 | ||
106 | return cBuf; | 106 | return cBuf; |
107 | } | 107 | } |
108 | 108 | ||
109 | TokType nextToken( Variant &v, Bu::String &sWsOut, int &iLineStart, | 109 | TokType nextToken( Variant &v, Bu::String &sWsOut, int &iLineStart, |
110 | int &iCharStart ) | 110 | int &iCharStart ) |
111 | { | 111 | { |
112 | Bu::String sTok, sWs; | 112 | Bu::String sTok, sWs; |
113 | 113 | ||
114 | char buf; | 114 | char buf; |
115 | try | 115 | try |
116 | { | 116 | { |
117 | buf = nextChar(); | 117 | buf = nextChar(); |
118 | } | 118 | } |
119 | catch(...) | 119 | catch(...) |
120 | { | 120 | { |
121 | return tokEof; | 121 | return tokEof; |
122 | } | 122 | } |
123 | 123 | ||
124 | for(;;) | 124 | for(;;) |
125 | { | 125 | { |
126 | if( buf == ' ' || buf == '\t' || buf == '\n' || buf == '\r' ) | 126 | if( buf == ' ' || buf == '\t' || buf == '\n' || buf == '\r' ) |
127 | { | 127 | { |
128 | sWs += buf; | 128 | sWs += buf; |
129 | bAvail = false; | 129 | bAvail = false; |
130 | } | 130 | } |
131 | else | 131 | else |
132 | break; | 132 | break; |
133 | 133 | ||
134 | try | 134 | try |
135 | { | 135 | { |
136 | buf = nextChar(); | 136 | buf = nextChar(); |
137 | } | 137 | } |
138 | catch(...) | 138 | catch(...) |
139 | { | 139 | { |
140 | sWsOut = sWs; | 140 | sWsOut = sWs; |
141 | return tokEof; | 141 | return tokEof; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | sWsOut = sWs; | 145 | sWsOut = sWs; |
146 | 146 | ||
147 | iLineStart = iLine; | 147 | iLineStart = iLine; |
148 | iCharStart = iChar; | 148 | iCharStart = iChar; |
149 | bool bInStr = false; | 149 | bool bInStr = false; |
150 | bool bDblStr; | 150 | bool bDblStr; |
151 | 151 | ||
152 | for(;;) | 152 | for(;;) |
153 | { | 153 | { |
154 | switch( eMode ) | 154 | switch( eMode ) |
155 | { | 155 | { |
156 | case mRoot: | 156 | case mRoot: |
157 | if( buf == ' ' || buf == '\t' || buf == '\n' | 157 | if( buf == ' ' || buf == '\t' || buf == '\n' |
158 | || buf == '\r' ) | 158 | || buf == '\r' ) |
159 | { | 159 | { |
160 | if( sTok == "suite" ) | 160 | if( sTok == "suite" ) |
161 | return tokSuite; | 161 | return tokSuite; |
162 | else | 162 | else |
163 | { | 163 | { |
164 | v = sTok; | 164 | v = sTok; |
165 | return tokFluff; | 165 | return tokFluff; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | else if( buf == '(' || buf == ')' || buf == '{' | 168 | else if( buf == '(' || buf == ')' || buf == '{' |
169 | || buf == '}' || buf == ';' ) | 169 | || buf == '}' || buf == ';' ) |
170 | { | 170 | { |
171 | if( sTok.getSize() == 0 ) | 171 | if( sTok.getSize() == 0 ) |
172 | { | 172 | { |
173 | bAvail = false; | 173 | bAvail = false; |
174 | v = buf; | 174 | v = buf; |
175 | return tokChar; | 175 | return tokChar; |
176 | } | 176 | } |
177 | else | 177 | else |
178 | { | 178 | { |
179 | v = sTok; | 179 | v = sTok; |
180 | return tokFluff; | 180 | return tokFluff; |
181 | } | 181 | } |
182 | } | 182 | } |
183 | else | 183 | else |
184 | { | 184 | { |
185 | sTok += buf; | 185 | sTok += buf; |
186 | bAvail = false; | 186 | bAvail = false; |
187 | } | 187 | } |
188 | break; | 188 | break; |
189 | 189 | ||
190 | case mSuite: | 190 | case mSuite: |
191 | if( buf == ' ' || buf == '\t' || buf == '\n' | 191 | if( buf == ' ' || buf == '\t' || buf == '\n' |
192 | || buf == '\r' ) | 192 | || buf == '\r' ) |
193 | { | 193 | { |
194 | if( sTok == "test" ) | 194 | if( sTok == "test" ) |
195 | return tokTest; | 195 | return tokTest; |
196 | else | 196 | else |
197 | { | 197 | { |
198 | v = sTok; | 198 | v = sTok; |
199 | return tokFluff; | 199 | return tokFluff; |
200 | } | 200 | } |
201 | } | 201 | } |
202 | else if( buf == '(' || buf == ')' | 202 | else if( buf == '(' || buf == ')' |
203 | || buf == '}' || buf == ';' ) | 203 | || buf == '}' || buf == ';' ) |
204 | { | 204 | { |
205 | if( sTok.getSize() == 0 ) | 205 | if( sTok.getSize() == 0 ) |
206 | { | 206 | { |
207 | bAvail = false; | 207 | bAvail = false; |
208 | v = buf; | 208 | v = buf; |
209 | return tokChar; | 209 | return tokChar; |
210 | } | 210 | } |
211 | else | 211 | else |
212 | { | 212 | { |
213 | v = sTok; | 213 | v = sTok; |
214 | return tokFluff; | 214 | return tokFluff; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | else if( buf == '{' ) | 217 | else if( buf == '{' ) |
218 | { | 218 | { |
219 | if( sTok.getSize() > 0 ) | 219 | if( sTok.getSize() > 0 ) |
220 | { | 220 | { |
221 | v = sTok; | 221 | v = sTok; |
222 | return tokFluff; | 222 | return tokFluff; |
223 | } | 223 | } |
224 | else | 224 | else |
225 | { | 225 | { |
226 | sTok += buf; | 226 | sTok += buf; |
227 | bAvail = false; | 227 | bAvail = false; |
228 | eMode = mBlock; | 228 | eMode = mBlock; |
229 | iDepth = 1; | 229 | iDepth = 1; |
230 | } | 230 | } |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | sTok += buf; | 234 | sTok += buf; |
235 | bAvail = false; | 235 | bAvail = false; |
236 | } | 236 | } |
237 | break; | 237 | break; |
238 | 238 | ||
239 | case mBlock: | 239 | case mBlock: |
240 | if( bInStr ) | 240 | if( bInStr ) |
241 | { | 241 | { |
242 | if( buf == '\\' ) | 242 | if( buf == '\\' ) |
243 | { | 243 | { |
244 | sTok += buf; | 244 | sTok += buf; |
245 | bAvail = false; | 245 | bAvail = false; |
246 | sTok += nextChar(); | 246 | sTok += nextChar(); |
247 | bAvail = false; | 247 | bAvail = false; |
248 | } | 248 | } |
249 | else if( bDblStr == true && buf == '\"' ) | 249 | else if( bDblStr == true && buf == '\"' ) |
250 | { | 250 | { |
251 | sTok += buf; | 251 | sTok += buf; |
252 | bAvail = false; | 252 | bAvail = false; |
@@ -267,295 +267,295 @@ public: | |||
267 | else | 267 | else |
268 | { | 268 | { |
269 | if( buf == '\"' ) | 269 | if( buf == '\"' ) |
270 | { | 270 | { |
271 | bInStr = true; | 271 | bInStr = true; |
272 | bDblStr = true; | 272 | bDblStr = true; |
273 | sTok += buf; | 273 | sTok += buf; |
274 | bAvail = false; | 274 | bAvail = false; |
275 | } | 275 | } |
276 | else if( buf == '\'' ) | 276 | else if( buf == '\'' ) |
277 | { | 277 | { |
278 | bInStr = true; | 278 | bInStr = true; |
279 | bDblStr = false; | 279 | bDblStr = false; |
280 | sTok += buf; | 280 | sTok += buf; |
281 | bAvail = false; | 281 | bAvail = false; |
282 | } | 282 | } |
283 | else if( buf == '}' ) | 283 | else if( buf == '}' ) |
284 | { | 284 | { |
285 | sTok += buf; | 285 | sTok += buf; |
286 | bAvail = false; | 286 | bAvail = false; |
287 | iDepth--; | 287 | iDepth--; |
288 | if( iDepth == 0 ) | 288 | if( iDepth == 0 ) |
289 | { | 289 | { |
290 | v = sTok; | 290 | v = sTok; |
291 | eMode = mSuite; | 291 | eMode = mSuite; |
292 | return tokBlock; | 292 | return tokBlock; |
293 | } | 293 | } |
294 | } | 294 | } |
295 | else if( buf == '{' ) | 295 | else if( buf == '{' ) |
296 | { | 296 | { |
297 | sTok += buf; | 297 | sTok += buf; |
298 | bAvail = false; | 298 | bAvail = false; |
299 | iDepth++; | 299 | iDepth++; |
300 | } | 300 | } |
301 | else | 301 | else |
302 | { | 302 | { |
303 | sTok += buf; | 303 | sTok += buf; |
304 | bAvail = false; | 304 | bAvail = false; |
305 | } | 305 | } |
306 | } | 306 | } |
307 | break; | 307 | break; |
308 | } | 308 | } |
309 | 309 | ||
310 | buf = nextChar(); | 310 | buf = nextChar(); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | void firstPass() | 314 | void firstPass() |
315 | { | 315 | { |
316 | Variant v; | 316 | Variant v; |
317 | Bu::String sWs; | 317 | Bu::String sWs; |
318 | int iL, iC; | 318 | int iL, iC; |
319 | for(;;) | 319 | for(;;) |
320 | { | 320 | { |
321 | TokType t = nextToken( v, sWs, iL, iC ); | 321 | TokType t = nextToken( v, sWs, iL, iC ); |
322 | if( t == tokEof ) | 322 | if( t == tokEof ) |
323 | return; | 323 | return; |
324 | switch( eMode ) | 324 | switch( eMode ) |
325 | { | 325 | { |
326 | case mRoot: | 326 | case mRoot: |
327 | if( t == tokSuite ) | 327 | if( t == tokSuite ) |
328 | { | 328 | { |
329 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) | 329 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) |
330 | throw Bu::ExceptionBase("%d:%d: Expected string " | 330 | throw Bu::ExceptionBase("%d:%d: Expected string " |
331 | "following suite.", iL, iC ); | 331 | "following suite.", iL, iC ); |
332 | s.sName = v.get<Bu::String>(); | 332 | s.sName = v.get<Bu::String>(); |
333 | if( nextToken( v, sWs, iL, iC ) != tokChar || | 333 | if( nextToken( v, sWs, iL, iC ) != tokChar || |
334 | v.get<char>() != '{' ) | 334 | v.get<char>() != '{' ) |
335 | throw Bu::ExceptionBase("%d:%d: Expected {, got " | 335 | throw Bu::ExceptionBase("%d:%d: Expected {, got " |
336 | "'%s'", iL, iC, v.toString().getStr() ); | 336 | "'%s'", iL, iC, v.toString().getStr() ); |
337 | eMode = mSuite; | 337 | eMode = mSuite; |
338 | } | 338 | } |
339 | break; | 339 | break; |
340 | 340 | ||
341 | case mSuite: | 341 | case mSuite: |
342 | switch( t ) | 342 | switch( t ) |
343 | { | 343 | { |
344 | case tokFluff: | 344 | case tokFluff: |
345 | break; | 345 | break; |
346 | 346 | ||
347 | case tokBlock: | 347 | case tokBlock: |
348 | break; | 348 | break; |
349 | 349 | ||
350 | case tokTest: | 350 | case tokTest: |
351 | { | 351 | { |
352 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) | 352 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) |
353 | throw Bu::ExceptionBase("%d:%d: Expected " | 353 | throw Bu::ExceptionBase("%d:%d: Expected " |
354 | "string following test.", iL, iC ); | 354 | "string following test.", iL, iC ); |
355 | Test t; | 355 | Test t; |
356 | t.sName = v.get<Bu::String>(); | 356 | t.sName = v.get<Bu::String>(); |
357 | if( nextToken( v, sWs, iL, iC ) != tokBlock ) | 357 | if( nextToken( v, sWs, iL, iC ) != tokBlock ) |
358 | throw Bu::ExceptionBase("%d:%d: Expected " | 358 | throw Bu::ExceptionBase("%d:%d: Expected " |
359 | "{...} block.", | 359 | "{...} block.", |
360 | iL, iC ); | 360 | iL, iC ); |
361 | s.lTest.append( t ); | 361 | s.lTest.append( t ); |
362 | } | 362 | } |
363 | break; | 363 | break; |
364 | 364 | ||
365 | case tokChar: | 365 | case tokChar: |
366 | if( v.get<char>() == '}' ) | 366 | if( v.get<char>() == '}' ) |
367 | { | 367 | { |
368 | eMode = mRoot; | 368 | eMode = mRoot; |
369 | } | 369 | } |
370 | else | 370 | else |
371 | { | 371 | { |
372 | } | 372 | } |
373 | break; | 373 | break; |
374 | 374 | ||
375 | default: | 375 | default: |
376 | sio << iL << ":" << iC << ": Unexpected " | 376 | sio << iL << ":" << iC << ": Unexpected " |
377 | << t << " found." << sio.nl; | 377 | << t << " found." << sio.nl; |
378 | return; | 378 | return; |
379 | break; | 379 | break; |
380 | } | 380 | } |
381 | break; | 381 | break; |
382 | 382 | ||
383 | default: | 383 | default: |
384 | sio << "???" << sio.nl; | 384 | sio << "???" << sio.nl; |
385 | break; | 385 | break; |
386 | } | 386 | } |
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | void secondPass( const Bu::String &sOut ) | 390 | void secondPass( const Bu::String &sOut ) |
391 | { | 391 | { |
392 | File fOut( sOut, File::WriteNew ); | 392 | File fOut( sOut, File::WriteNew ); |
393 | Formatter f( fOut ); | 393 | Formatter f( fOut ); |
394 | fIn.setPos( 0 ); | 394 | fIn.setPos( 0 ); |
395 | bIn.stop(); | 395 | bIn.stop(); |
396 | bIn.start(); | 396 | bIn.start(); |
397 | bAvail = false; | 397 | bAvail = false; |
398 | eMode = mRoot; | 398 | eMode = mRoot; |
399 | iLine = 1; | 399 | iLine = 1; |
400 | iChar = 0; | 400 | iChar = 0; |
401 | bool bHasIncluded = false; | 401 | bool bHasIncluded = false; |
402 | 402 | ||
403 | Bu::String sWs; | 403 | Bu::String sWs; |
404 | Variant v; | 404 | Variant v; |
405 | int iL, iC; | 405 | int iL, iC; |
406 | for(;;) | 406 | for(;;) |
407 | { | 407 | { |
408 | TokType t = nextToken( v, sWs, iL, iC ); | 408 | TokType t = nextToken( v, sWs, iL, iC ); |
409 | switch( eMode ) | 409 | switch( eMode ) |
410 | { | 410 | { |
411 | case mRoot: | 411 | case mRoot: |
412 | if( t == tokSuite ) | 412 | if( t == tokSuite ) |
413 | { | 413 | { |
414 | fOut.write( sWs ); | 414 | fOut.write( sWs ); |
415 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) | 415 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) |
416 | throw Bu::ExceptionBase("%d:%d: Expected string " | 416 | throw Bu::ExceptionBase("%d:%d: Expected string " |
417 | "following suite.", iL, iC ); | 417 | "following suite.", iL, iC ); |
418 | s.sName = v.get<Bu::String>(); | 418 | s.sName = v.get<Bu::String>(); |
419 | if( nextToken( v, sWs, iL, iC ) != tokChar || | 419 | if( nextToken( v, sWs, iL, iC ) != tokChar || |
420 | v.get<char>() != '{' ) | 420 | v.get<char>() != '{' ) |
421 | throw Bu::ExceptionBase("%d:%d: Expected {", | 421 | throw Bu::ExceptionBase("%d:%d: Expected {", |
422 | iL, iC ); | 422 | iL, iC ); |
423 | eMode = mSuite; | 423 | eMode = mSuite; |
424 | 424 | ||
425 | if( bHasIncluded == false ) | 425 | if( bHasIncluded == false ) |
426 | { | 426 | { |
427 | fOut.write("#include <bu/unitsuite.h>\n"); | 427 | fOut.write("#include <bu/unitsuite.h>\n"); |
428 | bHasIncluded = true; | 428 | bHasIncluded = true; |
429 | } | 429 | } |
430 | 430 | ||
431 | Bu::String sClass = "_UnitSuite_" + s.sName; | 431 | Bu::String sClass = "_UnitSuite_" + s.sName; |
432 | f << "class " << sClass | 432 | f << "class " << sClass |
433 | << " : public Bu::UnitSuite" << f.nl | 433 | << " : public Bu::UnitSuite" << f.nl |
434 | << "{" << f.nl << "public:" << f.nl | 434 | << "{" << f.nl << "public:" << f.nl |
435 | << "\t" << sClass << "()" << f.nl | 435 | << "\t" << sClass << "()" << f.nl |
436 | << "\t{" << f.nl | 436 | << "\t{" << f.nl |
437 | << "\t\tsetName(\"" << s.sName << "\");" << f.nl; | 437 | << "\t\tsetName(\"" << s.sName << "\");" << f.nl; |
438 | for( TestList::iterator i = s.lTest.begin(); i; i++ ) | 438 | for( TestList::iterator i = s.lTest.begin(); i; i++ ) |
439 | { | 439 | { |
440 | f << "\t\tadd( static_cast<Bu::UnitSuite::Test>(" | 440 | f << "\t\tadd( static_cast<Bu::UnitSuite::Test>(" |
441 | "&" << sClass << "::" << (*i).sName << "), \"" | 441 | "&" << sClass << "::" << (*i).sName << "), \"" |
442 | << (*i).sName << "\", Bu::UnitSuite::" | 442 | << (*i).sName << "\", Bu::UnitSuite::" |
443 | "expectPass );" << f.nl; | 443 | "expectPass );" << f.nl; |
444 | } | 444 | } |
445 | f << "\t}" << f.nl << f.nl | 445 | f << "\t}" << f.nl << f.nl |
446 | << "\tvirtual ~" << sClass << "() { }" << f.nl | 446 | << "\tvirtual ~" << sClass << "() { }" << f.nl |
447 | << f.nl; | 447 | << f.nl; |
448 | } | 448 | } |
449 | else if( t == tokEof ) | 449 | else if( t == tokEof ) |
450 | { | 450 | { |
451 | Bu::String sClass = "_UnitSuite_" + s.sName; | 451 | Bu::String sClass = "_UnitSuite_" + s.sName; |
452 | f << sWs << f.nl << "int main( int argc, char *argv[] )" | 452 | f << sWs << f.nl << "int main( int argc, char *argv[] )" |
453 | << f.nl << "{" << f.nl << "\treturn " << sClass | 453 | << f.nl << "{" << f.nl << "\treturn " << sClass |
454 | << "().run( argc, argv );" << f.nl << "}" << f.nl; | 454 | << "().run( argc, argv );" << f.nl << "}" << f.nl; |
455 | } | 455 | } |
456 | else | 456 | else |
457 | { | 457 | { |
458 | fOut.write( sWs ); | 458 | fOut.write( sWs ); |
459 | f << v; | 459 | f << v; |
460 | } | 460 | } |
461 | break; | 461 | break; |
462 | 462 | ||
463 | case mSuite: | 463 | case mSuite: |
464 | switch( t ) | 464 | switch( t ) |
465 | { | 465 | { |
466 | case tokFluff: | 466 | case tokFluff: |
467 | fOut.write( sWs ); | 467 | fOut.write( sWs ); |
468 | fOut.write( v.get<Bu::String>() ); | 468 | fOut.write( v.get<Bu::String>() ); |
469 | break; | 469 | break; |
470 | 470 | ||
471 | case tokTest: | 471 | case tokTest: |
472 | { | 472 | { |
473 | fOut.write( sWs ); | 473 | fOut.write( sWs ); |
474 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) | 474 | if( nextToken( v, sWs, iL, iC ) != tokFluff ) |
475 | throw Bu::ExceptionBase("%d:%d: Expected " | 475 | throw Bu::ExceptionBase("%d:%d: Expected " |
476 | "string following test.", iL, iC ); | 476 | "string following test.", iL, iC ); |
477 | Test t; | 477 | Test t; |
478 | t.sName = v.get<Bu::String>(); | 478 | t.sName = v.get<Bu::String>(); |
479 | if( nextToken( v, sWs, iL, iC ) != tokBlock ) | 479 | if( nextToken( v, sWs, iL, iC ) != tokBlock ) |
480 | throw Bu::ExceptionBase("%d:%d: Expected " | 480 | throw Bu::ExceptionBase("%d:%d: Expected " |
481 | "{...} block.", | 481 | "{...} block.", |
482 | iL, iC ); | 482 | iL, iC ); |
483 | 483 | ||
484 | f << "\tvoid " << t.sName << "()" | 484 | f << "\tvoid " << t.sName << "()" |
485 | << f.nl << "#line " << iL | 485 | << f.nl << "#line " << iL |
486 | << " \"" << sIn << "\"" << f.nl | 486 | << " \"" << sIn << "\"" << f.nl |
487 | << v << f.nl; | 487 | << v << f.nl; |
488 | } | 488 | } |
489 | break; | 489 | break; |
490 | 490 | ||
491 | case tokChar: | 491 | case tokChar: |
492 | if( v.get<char>() == '}' ) | 492 | if( v.get<char>() == '}' ) |
493 | { | 493 | { |
494 | f << "};" << f.nl << f.nl; | 494 | f << "};" << f.nl << f.nl; |
495 | eMode = mRoot; | 495 | eMode = mRoot; |
496 | } | 496 | } |
497 | else | 497 | else |
498 | { | 498 | { |
499 | char buf = v.get<char>(); | 499 | char buf = v.get<char>(); |
500 | fOut.write( sWs ); | 500 | fOut.write( sWs ); |
501 | fOut.write( &buf, 1 ); | 501 | fOut.write( &buf, 1 ); |
502 | } | 502 | } |
503 | break; | 503 | break; |
504 | 504 | ||
505 | case tokBlock: | 505 | case tokBlock: |
506 | fOut.write( sWs ); | 506 | fOut.write( sWs ); |
507 | f << f.nl << "#line " << iL << " \"" << sIn | 507 | f << f.nl << "#line " << iL << " \"" << sIn |
508 | << "\"" << f.nl; | 508 | << "\"" << f.nl; |
509 | fOut.write( v.get<Bu::String>() ); | 509 | fOut.write( v.get<Bu::String>() ); |
510 | 510 | ||
511 | break; | 511 | break; |
512 | 512 | ||
513 | default: | 513 | default: |
514 | sio << iL << ":" << iC << ": Unexpected " | 514 | sio << iL << ":" << iC << ": Unexpected " |
515 | << t << " found." << sio.nl; | 515 | << t << " found." << sio.nl; |
516 | return; | 516 | return; |
517 | break; | 517 | break; |
518 | } | 518 | } |
519 | break; | 519 | break; |
520 | 520 | ||
521 | default: | 521 | default: |
522 | sio << "???" << sio.nl; | 522 | sio << "???" << sio.nl; |
523 | break; | 523 | break; |
524 | } | 524 | } |
525 | if( t == tokEof ) | 525 | if( t == tokEof ) |
526 | return; | 526 | return; |
527 | } | 527 | } |
528 | } | 528 | } |
529 | 529 | ||
530 | private: | 530 | private: |
531 | Bu::String sIn; | 531 | Bu::String sIn; |
532 | File fIn; | 532 | File fIn; |
533 | Buffer bIn; | 533 | Buffer bIn; |
534 | char cBuf; | 534 | char cBuf; |
535 | bool bAvail; | 535 | bool bAvail; |
536 | enum Mode | 536 | enum Mode |
537 | { | 537 | { |
538 | mRoot, | 538 | mRoot, |
539 | mSuite, | 539 | mSuite, |
540 | mBlock | 540 | mBlock |
541 | }; | 541 | }; |
542 | Mode eMode; | 542 | Mode eMode; |
543 | int iLine, iChar; | 543 | int iLine, iChar; |
544 | int iDepth; | 544 | int iDepth; |
545 | Suite s; | 545 | Suite s; |
546 | }; | 546 | }; |
547 | 547 | ||
548 | int main( int argc, char *argv[] ) | 548 | int main( int argc, char *argv[] ) |
549 | { | 549 | { |
550 | if( argc < 3 ) | 550 | if( argc < 3 ) |
551 | { | 551 | { |
552 | sio << "Too few parameters." << sio.nl; | 552 | sio << "Too few parameters." << sio.nl; |
553 | return 0; | 553 | return 0; |
554 | } | 554 | } |
555 | Parser p( argv[1] ); | 555 | Parser p( argv[1] ); |
556 | 556 | ||
557 | p.firstPass(); | 557 | p.firstPass(); |
558 | 558 | ||
559 | p.secondPass( argv[2] ); | 559 | p.secondPass( argv[2] ); |
560 | } | 560 | } |
561 | 561 | ||