-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Refactor SsaBlockOrderTest to use lib/test and remove OldUnitTest
- Loading branch information
Showing
2 changed files
with
87 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,9 @@ | ||
class UnitTest(name: string, run: void -> void) { | ||
var output = StringBuilder.new(); | ||
new() { | ||
OldUnitTests.register(this); | ||
} | ||
def print(msg: string) { | ||
output.puts(msg); | ||
output.ln(); | ||
} | ||
def eq<T>(expected: T, result: T) { | ||
var fail = expected != result; | ||
if (fail && string.?(expected)) { | ||
fail = !Strings.equal(string.!(expected), string.!(result)); | ||
} | ||
if (fail) { | ||
var buf = StringBuilder.new().puts("expected "); | ||
put1(buf, expected); | ||
buf.puts(", result = "); | ||
put1(buf, result); | ||
error(buf.toString()); | ||
} | ||
} | ||
def put1<T>(buf: StringBuilder, t: T) -> StringBuilder { | ||
match (t) { | ||
x: bool => buf.putz(x); | ||
x: long => buf.putd(x); | ||
x: u64 => buf.putd(x); | ||
x: string => buf.puts(x); | ||
x: (StringBuilder -> StringBuilder) => return x(buf); | ||
_ => buf.puts("<unknown value type>"); | ||
} | ||
return buf; | ||
} | ||
def eqArray<T>(expected: Array<T>, result: Array<T>) { | ||
if (result == expected) return; | ||
if (result == null) return failArray(expected, result); | ||
if (result.length != expected.length) return failArray(expected, result); | ||
for (i < expected.length) if (expected[i] != result[i]) failArray(expected, result); | ||
} | ||
def failArray<T>(expected: Array<T>, result: Array<T>) { | ||
var buf = StringBuilder.new(); | ||
buf.puts("expected ["); | ||
var prev = false; | ||
for (e in expected) { | ||
if (prev) buf.csp(); | ||
put1(buf, e); | ||
} | ||
buf.puts("], result = "); | ||
if (result == null) { | ||
buf.puts("null"); | ||
} else { | ||
buf.puts("["); | ||
var prev = false; | ||
for (e in result) { | ||
if (prev) buf.csp(); | ||
put1(buf, e); | ||
} | ||
buf.puts("]"); | ||
} | ||
error(buf.toString()); | ||
} | ||
def nonnull<T>(val: T) { | ||
var n: T; | ||
if (val == n) error("expected nonnull value"); | ||
} | ||
def error(msg: string) { | ||
System.error(Strings.format1("%sTest error", name), msg); | ||
} | ||
def error1<T>(msg: string, param: T) { | ||
error(Strings.format1(msg, param)); | ||
} | ||
def error2<T, U>(msg: string, param1: T, param2: U) { | ||
error(Strings.format2(msg, param1, param2)); | ||
} | ||
def error3<T, U, V>(msg: string, param1: T, param2: U, param3: V) { | ||
error(Strings.format3(msg, param1, param2, param3)); | ||
} | ||
} | ||
component OldUnitTests { | ||
var tests: List<UnitTest>; | ||
var count = 0; | ||
new() { | ||
Aeneas.startup = run; | ||
} | ||
def register(x: UnitTest) { | ||
tests = List.new(x, tests); | ||
count++; | ||
} | ||
def run() { | ||
UnitTests.run([]); | ||
var progress = ProgressPrinter.new(count); | ||
for (l = Lists.reverse(tests); l != null; l = l.tail) { | ||
progress.begin(l.head.name); | ||
l.head.run(); | ||
l.head.output.reset(); | ||
progress.pass(); | ||
} | ||
if (progress.passed == count) { | ||
Terminal.put("Unit tests "); | ||
Terminal.green("passed", ()); | ||
Terminal.put(".\n"); | ||
} | ||
def X_ = Aeneas.startup = run; | ||
def run() { | ||
var result = UnitTests.run([]); | ||
if (result == 0) { | ||
Terminal.put("Unit tests "); | ||
Terminal.green("passed", ()); | ||
Terminal.put(".\n"); | ||
} | ||
} |