Check-in [6f0ec5b7c9]
Not logged in
Overview
SHA1 Hash:6f0ec5b7c9ba9b33c5b847ecb80a63c04eb0c5ea
Date: 2010-11-12 00:22:55
User: kinaba
Comment:Custom Test Runner
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified main.d from [abae545f4409680b] to [981f3ba98be4374d].

51 } catch(Throwable e) { 51 } catch(Throwable e) { 52 writeln(e); 52 writeln(e); 53 } 53 } 54 return true; 54 return true; 55 } 55 } 56 } 56 } 57 57 58 version(unittest) { < 59 bool success = false; < 60 static ~this(){ if(!success){writeln("(press enter to exit)"); readln(); < 61 } < 62 < 63 /// Entry point. If args.length==1, invoke REPL. 58 /// Entry point. If args.length==1, invoke REPL. 64 /// Otherwise interpret the argument as a filename. 59 /// Otherwise interpret the argument as a filename. 65 void main( string[] args ) 60 void main( string[] args ) 66 { 61 { 67 version(unittest) success=true; < 68 < 69 if( args.length <= 1 ) 62 if( args.length <= 1 ) 70 { 63 { 71 writeln("Welcome to Polemy 0.1.0"); 64 writeln("Welcome to Polemy 0.1.0"); 72 for(auto r = new REPL; r.singleInteraction();) {} 65 for(auto r = new REPL; r.singleInteraction();) {} 73 } 66 } 74 else 67 else 75 { 68 { 76 evalFile(args[1]); 69 evalFile(args[1]); 77 } 70 } 78 } 71 }

Modified polemy/parse.d from [fbe471845b86f859] to [d3a7b70fa2f3b803].

243 this(Lexer lex) { this.lex = lex; } 243 this(Lexer lex) { this.lex = lex; } 244 244 245 void eat(string kwd, lazy string msg) 245 void eat(string kwd, lazy string msg) 246 { 246 { 247 if( !tryEat(kwd) ) 247 if( !tryEat(kwd) ) 248 if( lex.empty ) 248 if( lex.empty ) 249 throw genex!UnexpectedEOF( 249 throw genex!UnexpectedEOF( 250 currentPosition(), sprintf!"%s is expect | 250 currentPosition(), sprintf!"%s is expect 251 else 251 else 252 throw genex!ParseException( 252 throw genex!ParseException( 253 currentPosition(), sprintf!"%s is expect 253 currentPosition(), sprintf!"%s is expect 254 } 254 } 255 255 256 bool tryEat(string kwd) 256 bool tryEat(string kwd) 257 { 257 {

Modified tricks/test.d from [1483c10390a22fc3] to [fc21831342965670].

1 /** 1 /** 2 * Authors: k.inaba 2 * Authors: k.inaba 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 * 4 * 5 * Unittest helpers. 5 * Unittest helpers. > 6 * TODO: use stderr instead of stdout. the problem is that std.cstream is xxxx.. > 7 * TODO: is there any way to clearnly implement "assert_compiles" and "assert_no 6 */ 8 */ 7 module tricks.test; 9 module tricks.test; 8 import std.conv : to; 10 import std.conv : to; 9 import core.exception; 11 import core.exception; > 12 > 13 version(unittest) > 14 { > 15 import std.stdio; > 16 import core.runtime; > 17 > 18 // Install custom test runner > 19 static this() > 20 { > 21 Runtime.moduleUnitTester = function() > 22 { > 23 Throwable ee = null; > 24 size_t failed=0; > 25 foreach(m; ModuleInfo) if(m) if(auto fp=m.unitTest) > 26 { > 27 writeln("[TEST] ", m.name); > 28 try { > 29 fp(); > 30 } catch( Throwable e ) { > 31 if(ee is null) > 32 ee = e; > 33 failed++; > 34 writeln(" !! ",e.file,"(",e.line,"): ", > 35 } > 36 } > 37 if(ee !is null) > 38 { > 39 writeln("[TEST] ",failed," modules failed. The f > 40 writeln(ee); > 41 write("[TEST] press enter to exit."); > 42 readln(); > 43 return false; > 44 } > 45 return true; > 46 }; > 47 } > 48 } 10 49 11 /// Unittest helper that asserts an expression must throw something 50 /// Unittest helper that asserts an expression must throw something 12 51 13 void assert_throw(ExceptionType=Throwable, < 14 T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") | 52 void assert_throw(ExcT=Throwable, T, string fn=__FILE__, size_t ln=__LINE__)(laz 15 { 53 { 16 static if( is(ExceptionType == Throwable) ) | 54 static if( is(ExcT == Throwable) ) 17 try 55 try 18 { t(); } 56 { t(); } 19 catch(ExceptionType) | 57 catch(ExcT) 20 { return; } 58 { return; } 21 else 59 else 22 try 60 try 23 { t(); } 61 { t(); } 24 catch(ExceptionType) | 62 catch(ExcT) 25 { return; } 63 { return; } 26 catch(Throwable e) 64 catch(Throwable e) 27 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep | 65 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 28 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 66 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 29 } 67 } 30 68 31 /// Unittest helper that asserts an expression must not throw anything 69 /// Unittest helper that asserts an expression must not throw anything 32 70 33 T assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg 71 T assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg 34 { 72 { 35 try 73 try 36 { return t(); } 74 { return t(); } 37 catch(Throwable e) 75 catch(Throwable e) 38 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n > | 76 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception \n 39 assert(false); 77 assert(false); 40 } 78 } 41 79 42 unittest 80 unittest 43 { 81 { 44 auto error = {throw new Error("hello");}; 82 auto error = {throw new Error("hello");}; 45 auto nothing = (){}; 83 auto nothing = (){}; ................................................................................................................................................................................ 58 template assertOp(string op) 96 template assertOp(string op) 59 { 97 { 60 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 98 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, st 61 { 99 { 62 try 100 try 63 { if( mixin("a"~op~"b") ) return; } 101 { if( mixin("a"~op~"b") ) return; } 64 catch(Throwable e) 102 catch(Throwable e) 65 { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception | 103 { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad excep 66 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 104 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op 67 } 105 } 68 } 106 } 69 107 70 alias assertOp!(`==`) assert_eq; /// asserts two operands are == 108 alias assertOp!(`==`) assert_eq; /// asserts two operands are == 71 alias assertOp!(`!=`) assert_ne; /// asserts two operands are != 109 alias assertOp!(`!=`) assert_ne; /// asserts two operands are != 72 alias assertOp!(`<`) assert_lt; /// asserts two operands are < 110 alias assertOp!(`<`) assert_lt; /// asserts two operands are < ................................................................................................................................................................................ 95 assert_throw!AssertError( assert_ge(0, 1) ); 133 assert_throw!AssertError( assert_ge(0, 1) ); 96 134 97 class Temp { bool opEquals(int x){return x/x==x;} } 135 class Temp { bool opEquals(int x){return x/x==x;} } 98 assert_throw!AssertError( assert_eq(new Temp, 0) ); 136 assert_throw!AssertError( assert_eq(new Temp, 0) ); 99 assert_nothrow ( assert_eq(new Temp, 1) ); 137 assert_nothrow ( assert_eq(new Temp, 1) ); 100 assert_throw!AssertError( assert_eq(new Temp, 2) ); 138 assert_throw!AssertError( assert_eq(new Temp, 2) ); 101 } 139 } 102 < 103 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_n <