Skip to content

refactor(compiler/tests): restructure test layout and relocate test-only helpers to test source set #7

Description

@Gray-SS

Context

The :modules:compiler:core test suite currently has two structural problems that make it harder to navigate and maintain as coverage grows.


Problem 1 — Test helpers live in src/main

Three files that exist purely to support tests are compiled into the main source set:

  • src/main/java/com/orca/compiler/core/tests/CompilerTestHelper.java
  • src/main/java/com/orca/compiler/core/tests/SourceBuilder.java
  • src/main/java/com/orca/compiler/core/tests/TopLevelSourceBuilder.java

Because they are in src/main, they end up on the production classpath and are included in any build artifact. They should live under src/test/java/…/tests/ instead, where they are only compiled for the test task and never shipped.

Goal: move all three files to src/test/java/com/orca/compiler/core/tests/ and confirm the test suite still passes.


Problem 2 — All test classes are flat and some are too large

All five test classes sit directly in com.orca.compiler.core with no sub-grouping. Two of them are approaching 1 000 lines:

File Lines Sections
TestCodeGen.java ~992 16 sections
TestTypeChecker.java ~910 10 sections
TestParser.java ~390 —
TestLexer.java ~283 —
TestTypeSystem.java ~220 —

Splitting by compiler phase and logical grouping would mirror the structure already used in src/main and make it clear where to add or remove tests.


Proposed layout

src/test/java/com/orca/compiler/core/
    tests/                            ← helpers moved from src/main
        CompilerTestHelper.java
        SourceBuilder.java
        TopLevelSourceBuilder.java
    lexer/
        LexerTest.java
    parser/
        ParserTest.java
    typesystem/
        TypeSystemTest.java
    semantic/
        SemanticTest.java             ← structural typing, type checks (valid + multi-source)
        SemanticScopeTest.java        ← scope/declarations, definite assignment, return statements
        SemanticDeclTest.java         ← constants, operators, impl blocks, collections
    codegen/
        ExpressionCodeGenTest.java    ← literals, arithmetic (int+float), strings, booleans, comparisons
        ControlFlowCodeGenTest.java   ← variables, if/else, while, for
        FunctionCodeGenTest.java      ← functions, impl methods, built-in functions
        CollectionCodeGenTest.java    ← arrays, collections
        IntegrationCodeGenTest.java   ← any type, compound/integration tests

The split boundaries above are proposals — feel free to adjust groupings during implementation.

TestTypeChecker is renamed to SemanticTest (and friends) because the test class covers the full semantic analysis phase, which lives entirely in the Binder — there is no distinct TypeChecker pass.


Acceptance criteria

  • CompilerTestHelper, SourceBuilder, and TopLevelSourceBuilder are moved to src/test
  • Test classes are split into sub-packages that reflect compiler phases
  • All existing tests pass without modification to test logic
  • No test-only code remains in src/main

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode restructuring without behavior change

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions