Mercurial > projects > dang
view tests/run.d @ 17:2a7b05d2e4f9
Fixed tests.run - now works really nice
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 17:55:42 +0200 |
parents | 59bfbaf8847f |
children | 95e3940d91d4 |
line wrap: on
line source
module run.d; import tango.io.Stdout, tango.io.FilePath, tango.io.GrowBuffer, tango.io.UnicodeFile, tango.io.stream.BufferStream, tango.text.Util, tango.io.protocol.Reader, tango.io.protocol.Writer, tango.text.Unicode, tango.sys.Process; char[] prog = "./Dang"; void main(char[][] args) { auto cPath = FilePath("tests"); ubyte success_success, success_failure, failure_failure, failure_success; foreach( path ; cPath.toList((FilePath path, bool isFolder){return isFolder;})) { Stdout(path.name)(":").newline; foreach( p ; path.toList((FilePath path, bool isFolder) { if(path.ext == "d" && path.name[0] != '.') return true; return false; })) { auto test = new Test(p); ubyte result = test.run(); switch(result) { case 0: success_success++; break; case 1: success_failure++; break; case 2: failure_failure++; break; case 3: failure_success++; break; } } } Stdout().newline.newline() ("Result:").newline() (" - Succes/Success: ")(success_success).newline() (" - Succes/Failure: ")(success_failure).newline() (" - Failure/Failure: ")(failure_failure).newline() (" - Failure/Success: ")(failure_success).newline; } class Test { FilePath target; public this(FilePath target) { this.target = target; } public ubyte run() { auto process = new Process(prog,"--gen-llvm",target.path~target.file); auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8); int mode; char[] data = file.read; if(data.length > 6 && data[0..6] == "//test") { char[] str = data.splitLines()[0][6..$]; switch(toLower(trim(str))) { case "fail": case "failure": mode = 1; break; default: mode = 0; } } Stdout(" - ")(target.file)(".. "); process.execute; auto result = process.wait; if(result.status == 0) { auto llvm_process = new Process("llvm-as"); llvm_process.execute; llvm_process.stdin.copy(process.stdout); llvm_process.stdin.close(); result = llvm_process.wait; } if(result.status == 0) { if(mode == 0) { Stdout("SUCCES").newline; return 0; } if(mode == 1) { Stdout("SUCCES - Unexpected").newline; return 3; } } else { if(mode == 1) { Stdout("FAILURE").newline; return 2; } if(mode == 0) { Stdout("FAILURE - Unexpected").newline; return 1; } } } }