Skip to content

Add HL bytecode output test suite (tests/hlcode)#12758

Draft
Copilot wants to merge 7 commits intodevelopmentfrom
copilot/add-hlcode-test-suite
Draft

Add HL bytecode output test suite (tests/hlcode)#12758
Copilot wants to merge 7 commits intodevelopmentfrom
copilot/add-hlcode-test-suite

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

Adds a test suite for validating HL code generation output, analogous to the JS optimization tests. Tests use a @:hl(<> ... </>) annotation containing output copied verbatim from dump/hlcode.txt.

Structure

tests/hlcode/
├── compile.hxml          # -main Main -D dump
└── src/
    ├── Main.hx           # minimal entry point
    ├── Macro.hx          # onAfterGenerate validator
    └── cases/            # one .hx file per test topic
        └── HlCodeTests.hx
tests/tools/
└── diff/                 # shared diff utility (moved from tests/misc/src/diff)

The macro auto-discovers all files in src/cases/ (all package cases;), reads dump/hlcode.txt after generation, looks up each annotated function by its fully-qualified name (e.g. cases.HlCodeTests.registerAffixDesc), and compares normalized output.

Normalization

Both expected and actual are normalized before comparison, making tests robust to unrelated changes:

  • Source comment lines (;) — skipped entirely
  • Function indices: fun@23(17h)fun@N(Nh)
  • Instruction source-line prefix: .12 @0@0
  • Global IDs in global/setglobal → sequential $0, $1, … (per-function, order of first appearance)

Failure output

When a test fails, a unified diff is shown to make it easy to spot the difference:

| Test failed for cases.HlCodeTests.registerAffixDesc
| @@ -1,5 +1,5 @@
|  fun@N(Nh) ():virtual(target:enum(cases.EKind))
| -r0 virtual(target:WRONG_TYPE)
| +r0 virtual(target:enum(cases.EKind))
|  r1 enum(cases.EKind)
|  @0 new 0
|  @1 global 1, $0

Example test

@:hl(<>
    fun@364(16Ch) ():virtual(target:enum(cases.EKind))
    ; src/cases/HlCodeTests.hx:30 (cases.HlCodeTests.registerAffixDesc)
        r0 virtual(target:enum(cases.EKind))
        r1 enum(cases.EKind)
        .30    @0 new 0
        .30    @1 global 1, 18
        .30    @2 setfield 0[0],1
        .30    @3 ret 0
</>)
static public function registerAffixDesc():ApplicationDesc {
    return {target: Empty};
}

To add a test: compile with -D dump, copy the relevant block from dump/hlcode.txt into an @:hl(<> ... </>) annotation.

CI

Hooked into the HL target run (tests/runci/targets/Hl.hx) alongside the existing misc HL tests. Requires only the Haxe compiler — no HL runtime needed.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 7, 2026 06:45
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
…w comments

Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test suite for HL code output Add HL bytecode output test suite (tests/hlcode) Mar 7, 2026
Copilot finished work on behalf of Simn March 7, 2026 06:49
@Simn
Copy link
Member

Simn commented Mar 7, 2026

@yuxiaomao Please check if this gives you a good workflow! Feel free to add some cases already, e.g. more of the stuff from #12682.

@Simn
Copy link
Member

Simn commented Mar 7, 2026

@copilot The only problem I'm seeing right now is that if a test fails it just dumps the expected/actual output at me which makes it hard to spot the actual difference. We have a small diff implementation in tests/misc/src/diff which we can use.

Let's take this opportunity to move it to tests/tools/diff so we don't have any weird test-suite interaction going on and all the general purpose stuff is in a more central area.

Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 7, 2026

@copilot The only problem I'm seeing right now is that if a test fails it just dumps the expected/actual output at me which makes it hard to spot the actual difference. We have a sma...

Done in 6f92728. The diff implementation has been moved from tests/misc/src/diff to tests/tools/diff, and tests/misc/compile.hxml updated to reference the new path. Macro.hx now uses it to show a unified diff on failure:

| Test failed for cases.HlCodeTests.registerAffixDesc
| @@ -1,5 +1,5 @@
|  fun@N(Nh) ():virtual(target:enum(cases.EKind))
| -r0 virtual(target:WRONG_TYPE)
| +r0 virtual(target:enum(cases.EKind))
|  r1 enum(cases.EKind)
|  @0 new 0
|  @1 global 1, $0

Copilot finished work on behalf of Simn March 7, 2026 07:19
@Simn Simn changed the base branch from development to hl-infinite-structural-equality+add-hlcode-test-suite March 7, 2026 17:32
@Simn Simn changed the base branch from hl-infinite-structural-equality+add-hlcode-test-suite to development March 7, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants