Skip to content

Commit 3a3e019

Browse files
authored
CheckTestCase: more readable expected / actual formatting (#291)
1 parent 693c17a commit 3a3e019

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

test/checks/CheckTestCase.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class CheckTestCase<T:String> extends haxe.unit.TestCase {
3535
assertEquals(expected, msg, pos);
3636
}
3737

38+
override function assertEquals<T>(expected:T, actual:T, ?c:PosInfos) {
39+
currentTest.done = true;
40+
if (actual != expected) {
41+
currentTest.success = false;
42+
currentTest.error = "\nexpected:\n\t'" + expected + "'\nactual:\n\t'" + actual + "'";
43+
currentTest.posInfos = c;
44+
throw currentTest;
45+
}
46+
}
47+
3848
function checkMessage(src:String, check:Check, defines:Array<Array<String>>, fileName:String = FILE_NAME, ?pos:PosInfos):String {
3949
// a fresh Checker and Reporter for every checkMessage
4050
// to allow multiple independant checkMessage calls in a single test

test/misc/ExtensionsTest.hx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package misc;
22

33
import checks.CheckTestCase;
4+
#if (haxeparser >= "3.3.0")
45
import checkstyle.checks.whitespace.IndentationCharacterCheck;
6+
#end
57

68
class ExtensionsTest extends CheckTestCase<ExtensionsTests> {
79

810
public function testExtensions() {
9-
try {
10-
assertNoMsg(new IndentationCharacterCheck(), TEST1);
11-
// the upcoming haxeparser does not fail here, so disabling failing part
12-
// // unless haxeparse bug is fixed, this code is unreachable
13-
// assertFalse(true);
14-
}
15-
catch (e:Dynamic) {
16-
assertEquals("misc.ExtensionsTest", e.classname);
17-
assertEquals("expected '' but was 'Parsing failed: Unexpected >", e.error.substr(0, 49));
18-
}
11+
#if (haxeparser >= "3.3.0")
12+
assertNoMsg(new IndentationCharacterCheck(), TEST1);
13+
#else
14+
assertTrue(true);
15+
#end
1916
}
2017
}
2118

0 commit comments

Comments
 (0)