Skip to content

Commit 6f92728

Browse files
CopilotSimn
andcommitted
Move diff to tests/tools/diff; use diff in hlcode test failure output
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
1 parent 097c5e9 commit 6f92728

File tree

11 files changed

+16
-3
lines changed

11 files changed

+16
-3
lines changed

tests/hlcode/compile.hxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-p src
2+
-p ../tools
23
--macro Macro.run()
34
-hl bin/test.hl
45
-D dump

tests/hlcode/src/Macro.hx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ class Macro {
9090
var normalizedActual = normalize(actual);
9191
if (normalizedExpected != normalizedActual) {
9292
++failures;
93-
Context.warning('Test failed for $funcName', cf.pos);
94-
Context.warning('Expected:\n$normalizedExpected', cf.pos);
95-
Context.warning(' Actual:\n$normalizedActual', cf.pos);
93+
Context.warning('Test failed for $funcName\n${makeDiff(normalizedExpected, normalizedActual)}', cf.pos);
9694
}
9795
}
9896
}
@@ -123,6 +121,19 @@ class Macro {
123121
}
124122
}
125123

124+
/**
125+
Produce a unified diff between two normalized strings for readable test failure output.
126+
**/
127+
static function makeDiff(expected:String, actual:String):String {
128+
final a = new diff.FileData(haxe.io.Bytes.ofString(expected), "expected", Date.now());
129+
final b = new diff.FileData(haxe.io.Bytes.ofString(actual), "actual", Date.now());
130+
final ctx:diff.Context = {file1: a, file2: b, context: 3};
131+
final script = diff.Analyze.diff2Files(ctx);
132+
final result = diff.Printer.printUnidiff(ctx, script);
133+
// Strip the file header lines (--- expected / +++ actual)
134+
return result.split("\n").slice(2).join("\n");
135+
}
136+
126137
/**
127138
Parse the HL dump into a map of `ClassName.methodName` → function block text.
128139
**/

tests/misc/compile.hxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-p src
2+
-p ../tools
23
#-D MISC_TEST_FILTER=4270
34
-main Main
45
--interp

0 commit comments

Comments
 (0)