Mercurial > projects > dang
diff tests/run.d @ 15:59bfbaf8847f
Updates to run.d - still errors
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 17:49:34 +0200 |
parents | 2168f4cb73f1 |
children | 2a7b05d2e4f9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/run.d Fri Apr 18 17:49:34 2008 +0200 @@ -0,0 +1,148 @@ +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 buffer = new GrowBuffer(); + buffer.copy(process.stdout); +// auto result = process.wait; + + Process.Result result; + + Stdout("1").newline; +// if(result.status == 0) +// { + Stdout("2").newline; + auto llvm_process = new Process("llvm-as",target.path~target.file); + llvm_process.execute; + if(llvm_process.isRunning) + { + Stdout("3")(process.stdout)(llvm_process.stdin).newline; + // llvm_process.stdin.copy(buffer); + llvm_process.stdin.write("lalalala"); + Stdout("4").newline; + 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; + } + } + } +} +