# HG changeset patch # User Anders Halager # Date 1215601197 -7200 # Node ID 570a4917413a920b5cbe79d660d63c2d989d6073 # Parent 9c48871eb816455b358c355cbdfdfe8585064053 Changed the test-program. Most important difference is that a single count is printed at the end now (easier to remember/compare). Also noticed that our tests give different results in debug and release mode, I will have to look into that. diff -r 9c48871eb816 -r 570a4917413a dsss.conf --- a/dsss.conf Mon Jun 30 16:43:40 2008 +0200 +++ b/dsss.conf Wed Jul 09 12:59:57 2008 +0200 @@ -13,8 +13,4 @@ [tests/run.d] Target = tests/run -buildflags = -llllvm-c-ext -llstdc++ \ - -llLLVMCore -llLLVMBitWriter -llLLVMBitReader -llLLVMAnalysis -llLLVMTarget \ - -llLLVMTransformUtils -llLLVMScalarOpts -llLLVMipa -llLLVMipo \ - -llLLVMInstrumentation -llLLVMSystem -llLLVMSupport diff -r 9c48871eb816 -r 570a4917413a tests/run.d --- a/tests/run.d Mon Jun 30 16:43:40 2008 +0200 +++ b/tests/run.d Wed Jul 09 12:59:57 2008 +0200 @@ -1,200 +1,163 @@ +// skip module run.d; -import tango.io.Stdout, - tango.core.Array, - 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; +import tango.core.Array, + tango.io.FileConduit, + tango.io.FileScan, + tango.io.Stdout, + tango.sys.Process, + tango.text.Ascii, + tango.text.Regex, + tango.text.Util; + +// -- Settings -- +char[] compiler = "./Dang"; +char[] test_folder = "tests"; +char[] valid_filenames = r"^[^.].*"; +bool print_expected = false; +// the tests can be sorted by one of the following functions +bool nameSort (FilePath a, FilePath b) { return a.name < b.name; } +bool pathSort (FilePath a, FilePath b) { return a.toString < b.toString; } +bool modifiedSort(FilePath a, FilePath b) { return a.modified < b.modified; } +bool createdSort (FilePath a, FilePath b) { return a.created < b.created; } +const sortBy = &pathSort; -enum +// -- end of settings + +enum TestResult { - SuccessSuccess, - SuccessFailure, - FailureSuccess, - FailureFailure, + Skipped, + Expected, + Unexpected } -char[] prog = "./Dang"; - void main(char[][] args) { - auto cPath = FilePath("tests"); + scope scan = new FileScan; + scope regex = new Regex(valid_filenames); + // Return true for files/folders to include + bool filter(FilePath p, bool isDir) + { + if (isDir) + return p.name[0] != '.'; + else + return p.ext == "d" && regex.test(p.name); + } + scan.sweep(test_folder, &filter, true); + FilePath[] files = scan.files; + int total_tests = files.length; - ubyte success_success, success_failure, failure_failure, failure_success; + // Sort the result by the chosen function - default is the full path + sort(files, sortBy); - foreach( path ; cPath.toList((FilePath path, bool isFolder){return isFolder;})) + int[TestResult.max + 1] results = 0; + foreach (i, ref test; files) { - Stdout(path.name)(":").newline; - auto paths = path.toList( - (FilePath path, bool isFolder) - { - if(path.ext == "d" && path.name[0] != '.') - return true; - return false; - }); - sort(paths, (FilePath a, FilePath b) { return a.name < b.name; }); - foreach (p ; paths) - { - auto test = new Test(p); - ubyte result = test.run(); + begin_test(i + 1, total_tests, test.name); + TestResult res = run_test(test); + results[res] += 1; + end_test(); + } + Stdout.format("\r{,80}\r", " "); + Stdout.newline; + int good = TestResult.Expected; + int bad = TestResult.Unexpected; + int tests_run = results[good] + results[bad]; + Stdout.formatln("{}/{} tests failed", results[bad], tests_run); +} + +void begin_test(int number, int total_tests, char[] name) +{ + char[60] progressbar = ' '; + int progress = number*progressbar.length/total_tests; + progressbar[0 .. progress] = '='; + progressbar[progress-1] = '>'; + Stdout.format("\r{}% - [{}]", 1e2 * number / total_tests, progressbar); + Stdout.flush(); + //Thread.sleep(0.05); +} + +void end_test() { } - switch(result) +enum { + NoFail, + CompiletimeFail, + RuntimeFail +} + +private int min(int a, int b) { return a < b? a : b; } +TestResult run_test(ref FilePath p) +{ + auto file = new FileConduit(p.toString(), FileConduit.ReadExisting); + char[256] content; + int len = file.read(content); + file.close(); + char[] line = content[0 .. min(len, content.find('\n'))]; + + bool compile = true; + int fail = NoFail; + if (line.length >= 2 && line[0 .. 2] == "//") + { + foreach (command; line[2 .. $].delimiters(",;")) + switch (toLower(substitute(command, " ", ""))) { - case SuccessSuccess: - success_success++; + case "skip", "dontcompile": + compile = false; break; - case SuccessFailure: - success_failure++; + case "fail", "compilefail", + "compiletimefail", "failatcompiletime": + fail = CompiletimeFail; break; - case FailureFailure: - failure_failure++; - break; - case FailureSuccess: - failure_success++; + case "runtime", "runtimefail", "failatruntime": + fail = RuntimeFail; + Stderr("== Compiled tests will not be run! ==").newline; + return TestResult.Skipped; + default: break; } - - } - } - - Stdout().newline.newline() - ("Result:").newline() - (" - Success/Success: ")(success_success).newline() - (" - Success/Failure: ")(success_failure).newline() - (" - Failure/Failure: ")(failure_failure).newline() - (" - Failure/Success: ")(failure_success).newline; -} - -class Test -{ - enum TestValue - { - Success = 0, - Lexer = 2, - Parser = 3, - Gen = 4, - - Fail = 100 - } - - FilePath target; - - TestValue[int] testValues; - - public this(FilePath target) - { - this.target = target; } - public ubyte run() + if (compile) { - auto process = new Process(prog,"--gen-llvm",target.path~target.file); - - auto file = new UnicodeFile!(char)(target.path~target.file, Encoding.UTF_8); - - TestValue mode; - - char[] data = file.read; - char[][] commands = split(splitLines(data)[0], " "); - if(commands[0] == "//fail") - { - mode = TestValue.Fail; - if(commands.length > 1) - { - try - { - int i = Integer.toInt(commands[1]); - if(i in testValues) - mode = testValues[i]; - } - catch{} - } - } -/* if(data.length > 6 && data[0..6] == "//fail") - { - char[] str = data.splitLines()[0][6..$]; + auto process = new Process(compiler, "--gen-llvm", p.toString()); + process.execute(); + auto result = process.wait(); + return resultOf(p, result.status, fail); + } - switch(toLower(trim(str))) - { - case "fail": - case "failure": - mode = 1; - break; - default: - mode = 0; - } - } -*/ - Stdout.format(" {,-25}", target.file); + return TestResult.Skipped; +} - 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; - } - */ - - return resultOf(result.status, mode); +private TestResult resultOf(FilePath p, int result, int expected) +{ + char[] good(char[] s) + { + version (Posix) + return "\033[1;32m" ~ s ~ "\033[m"; + else + return s; } - private int resultOf(int status, TestValue mode) + char[] bad(char[] s) { - char[] good(char[] s) - { - version (Posix) - return "\033[1;32m" ~ s ~ "\033[m"; - else - return s; - } - - char[] bad(char[] s) - { - version (Posix) - return "\033[1;31m" ~ s ~ "\033[m"; - else - return s; - } + s = s ~ " - Unexpected"; + version (Posix) + return "\033[1;31m" ~ s ~ "\033[m"; + else + return s; + } - if(status == 0) - { - if(mode == TestValue.Success) - { - Stdout(good("SUCCESS")).newline; - return SuccessSuccess; - } - if(mode == TestValue.Fail) - { - Stdout(bad("SUCCESS - Unexpected")).newline; - return FailureSuccess; - } - } - else - { - if(mode == TestValue.Fail) - { - Stdout(good("FAILURE")).newline; - return FailureFailure; - } - if(mode == TestValue.Success) - { - Stdout(bad("FAILURE - Unexpected")).newline; - return SuccessFailure; - } - } + bool unexpected = (result != expected); + auto f = unexpected? &bad : &good; + char[] s = (result == 0)? "SUCCESS" : "FAILURE"; + // always print if unexpeted, otherwise check the settings + if (unexpected || print_expected) + { + Stdout.format("\r{,80}\r", " "); + Stdout.format(" {,-45}", p); + Stdout(f(s)).newline; } + return unexpected? TestResult.Unexpected : TestResult.Expected; }