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 51 } catch(Throwable e) { 52 52 writeln(e); 53 53 } 54 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 58 /// Entry point. If args.length==1, invoke REPL. 64 59 /// Otherwise interpret the argument as a filename. 65 60 void main( string[] args ) 66 61 { 67 - version(unittest) success=true; 68 - 69 62 if( args.length <= 1 ) 70 63 { 71 64 writeln("Welcome to Polemy 0.1.0"); 72 65 for(auto r = new REPL; r.singleInteraction();) {} 73 66 } 74 67 else 75 68 { 76 69 evalFile(args[1]); 77 70 } 78 71 }

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

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

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

1 1 /** 2 2 * Authors: k.inaba 3 3 * License: NYSL 0.9982 http://www.kmonos.net/nysl/ 4 4 * 5 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_not_compile"? 6 8 */ 7 9 module tricks.test; 8 10 import std.conv : to; 9 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,"): ",e.msg); 35 + } 36 + } 37 + if(ee !is null) 38 + { 39 + writeln("[TEST] ",failed," modules failed. The first error was:"); 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 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__)(lazy T t, string msg="") 15 53 { 16 - static if( is(ExceptionType == Throwable) ) 54 + static if( is(ExcT == Throwable) ) 17 55 try 18 56 { t(); } 19 - catch(ExceptionType) 57 + catch(ExcT) 20 58 { return; } 21 59 else 22 60 try 23 61 { t(); } 24 - catch(ExceptionType) 62 + catch(ExcT) 25 63 { return; } 26 64 catch(Throwable e) 27 - { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n >> "~e.toString()); } 65 + { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception \n >> "~e.toString()); } 28 66 onAssertErrorMsg(fn, ln, msg.length ? msg : "not thrown"); 29 67 } 30 68 31 69 /// Unittest helper that asserts an expression must not throw anything 32 70 33 71 T assert_nothrow(T, string fn=__FILE__, size_t ln=__LINE__)(lazy T t, string msg="") 34 72 { 35 73 try 36 74 { return t(); } 37 75 catch(Throwable e) 38 - { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception\n >> "~e.toString()); } 76 + { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception \n >> "~e.toString()); } 39 77 assert(false); 40 78 } 41 79 42 80 unittest 43 81 { 44 82 auto error = {throw new Error("hello");}; 45 83 auto nothing = (){}; ................................................................................ 58 96 template assertOp(string op) 59 97 { 60 98 void assertOp(A, B, string fn=__FILE__, size_t ln=__LINE__)(A a, B b, string msg="") 61 99 { 62 100 try 63 101 { if( mixin("a"~op~"b") ) return; } 64 102 catch(Throwable e) 65 - { onAssertErrorMsg(fn, ln, msg.length ? msg : "exception ["~e.toString()~"]"); } 103 + { onAssertErrorMsg(fn, ln, msg.length ? msg : "bad exception \n >> "~e.toString()); } 66 104 onAssertErrorMsg(fn, ln, msg.length ? msg : to!string(a)~" !"~op~" "~to!string(b)); 67 105 } 68 106 } 69 107 70 108 alias assertOp!(`==`) assert_eq; /// asserts two operands are == 71 109 alias assertOp!(`!=`) assert_ne; /// asserts two operands are != 72 110 alias assertOp!(`<`) assert_lt; /// asserts two operands are < ................................................................................ 95 133 assert_throw!AssertError( assert_ge(0, 1) ); 96 134 97 135 class Temp { bool opEquals(int x){return x/x==x;} } 98 136 assert_throw!AssertError( assert_eq(new Temp, 0) ); 99 137 assert_nothrow ( assert_eq(new Temp, 1) ); 100 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_not_compile"? */