Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,17 @@ jobs:
timeout-minutes: 22
shell: bash
run: |
# Master pushes also run every executing test on Lua (-PallBackends) where the Lua is 5.3, as
# the exemptions were established on: Linux installs lua5.3 and Windows uses the bundled lua.exe.
# macOS takes Homebrew's unpinned Lua and runs a single test fork.
ALL_BACKENDS=""
if [[ "${{ github.event_name }}" == "push" && "${{ runner.os }}" != "macOS" ]]; then
ALL_BACKENDS="-PallBackends"
fi
if [[ "${{ github.event_name }}" == "push" && "${{ runner.os }}" == "Linux" ]]; then
./gradlew test jacocoTestReport --no-daemon --stacktrace --quiet
./gradlew test jacocoTestReport $ALL_BACKENDS --no-daemon --stacktrace --quiet
else
./gradlew test --no-daemon --stacktrace --quiet
./gradlew test $ALL_BACKENDS --no-daemon --stacktrace --quiet
fi

- name: Upload coverage to Coveralls
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ tool discovery, map-build fixtures, or runtime packaging. Regressions have repea

* `test().executeProg()` runs the compiled program in the interpreter and requires a `testSuccess()` call.
* `test().testLua(true).executeProg()` runs the **Lua path only** (`testLua` sets `luaOnly`, which skips the Jass and interpreter runs; add `.luaOnly(false)` to keep them). It syntax-checks the emitted Lua with luac and executes it with a stock Lua interpreter (5.3 on Windows and the Linux CI, see below) against the WC3 runtime in `src/test/resources/luaruntime/` (wc3shim + Reforged `common.j.lua`/`blizzard.j.lua` dumps).
* `-PallBackends` (master CI on Linux and Windows) also runs every other executing test on Lua after its Jass runs; `-PallBackends=full` adds a Lua run with `-inline -localOptimizations`. A test which cannot hold on Lua says why, and how it fails there, with `.luaExempt(LuaExemption.X, expectedFailure)` (`testLua(false)` is rejected): it runs no Lua in an ordinary run, and under the flag its Lua run must fail with that text and of the reason's kind (`LuaExemption.mismatch`), so a stale exemption or a new Lua failure fails the test (`LuaExemptionTests`). `KNOWN_LUA_DEFECT` cites its `BACKLOG.md` item by the bold title, and fails every run once that item is gone.
* Interpreter discovery (`WurstScriptTest.getLuaExecutable`): on Linux `lua5.3` from PATH, then the bundled `lua53`; on Windows the bundled `lua.exe`; then `lua53`/`lua` from PATH. The version is never checked: Linux CI asserts 5.3 and the bundled Windows `lua.exe` is 5.3, but CI's macOS job installs whatever `brew install lua` gives. A missing interpreter skips the execution (visibly); a missing `luac` fails the test.
* A Lua run fails when a package fails to initialise ("Could not initialize package X"), even if it reaches `testSuccess`: the generated script reports the failure and goes on without the package. A native which a package init needs belongs in `wc3shim.lua`.
* Use `LuaBackendAuditTests` as the reference style for backend regression repros.
Expand Down
43 changes: 26 additions & 17 deletions BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,20 @@ Notes; finished-work narrative does not.
testSuccess()
```

- **Run every executing test on Lua on master CI (`-PallBackends`).** Forcing `translateAndTestLua`
after the Jass runs of every `executeProg` test that does not opt into Lua (686 tests, October 2026)
passed 645 on plain Lua and 644 with `-inline -localOptimizations`; the failures found the
generic-static item below, four defects with their own fixes (compile-time object ids, old-generic
tuple arguments, a direct `wurstKeyOf` call, the `Reflection` natives) and 24 tests stopped by natives missing from `wc3shim.lua`. The two Lua variants
cost about 300 s of test time each over the suite. Proposal: `-PallBackends` (master CI only, PR CI
unchanged) runs Lua after Jass for every executing test, `-PallBackends=full` adds the inlined
variant. A test that cannot hold on Lua says why with `.luaExempt(LuaExemption.X)` instead of
`testLua(false)`: an enum whose every reason names its record (`REAL_EQUALITY_TOLERANCE`, AGENTS.md §7;
`CLASS_AND_METHOD_TYPE_PARAMS`, §9; `TEST_LUA_COMPUTES_IN_DOUBLE`, docs/WC3_RUNTIME.md "Numbers";
`INTERPRETER_MOCK_ONLY`; `MISSING_TEST_NATIVE` with the native's name; `KNOWN_LUA_DEFECT` with the
backlog item). In that mode an exempt test still runs on Lua and must fail there, so a stale
exemption fails the run (21 of 48 `testLua(false)` were stale and now run Lua). Land the shim natives
first. `executeTests()` (Wurst `@Test` functions) has no Lua path in the harness at all.
- **Executing tests left off Lua.** Master CI runs every executing test on Lua too (`-PallBackends`) on
its Linux and Windows jobs, whose Lua is 5.3; macOS, with Homebrew's unpinned Lua, does not. The 13
`MISSING_TEST_NATIVE` exemptions wait for natives in `wc3shim.lua`, and `executeTests()` (Wurst `@Test`
functions) has no Lua path in the harness at all. `-PallBackends=full`, which adds
`-inline -localOptimizations`, found nothing the plain run did not (October 2026), so CI runs only that.

- **A generic class's static is split on Lua when its constructor passes a constant static to a method.**
`GenericsWithTypeclassesTests.arrayListInClosure` stops on Lua at `ImTranslator.assertNoLiveErasedGenericStatic`
("init_Hello uses the erased generic static ArrayList_nextFreeIndex, which has specialised copies"),
and is exempt from Lua. Reduced: `class L<T:>` with `static int next = 0` and `static constant int CAP = 16`,
a constructor calling `alloc(CAP)`, a private method which reads and writes `next`, and `new L<C>()` for a
class `C`. With the literal `16` for `CAP`, or with the constructor using `next` itself, it passes; the
closure the test is named after plays no part, and it still fails after #1509. Fix it in
`EliminateGenerics`, where the store is split, and replace the exemption with `testLua(true).luaOnly(false)`.

- **A generic class constructed with a tuple loses the static its constructor writes, on Lua.** In
`class Outer<T:>` with `static T last` and `construct(T value)` / `last = value`,
Expand All @@ -285,6 +285,15 @@ Notes; finished-work narrative does not.
Bound the Jass search and make the interpreter answer as the backends do (docs/WC3_RUNTIME.md
"Objects and memory").

- **`GetHandleId` of a unit or another agent is the compiler's own counter on Lua.** `LuaNativeLowering`
replaces `GetHandleId` of the `OPAQUE_RUNTIME_HANDLE_TYPES` (unit, item, timer, trigger, ...) with
`__wurst_GetHandleId`, which numbers handles from 1 in `__wurst_objectIndexMap` and keeps every handle it
numbered. The game's ids start at 0x100000 (measured on the 3.0.0 client), as the interpreter's do, so
`InterpreterTests.conversionNativesAsMeasured` is exempt from Lua, and a program which subtracts 0x100000
to index an array reads a negative index there. The tests check the remap's shape
(`LuaTranslationTests.getHandleIdIsRemappedToWurstPolyfillInLua`), not this difference. Call the game's
`GetHandleId`, or record why the remap is needed and document the difference (AGENTS.md §7).

- **Represent raw Lua helper bindings structurally.** Lua name compression now runs after backend
lowering so it includes descriptors, field storage and resolved dispatch slots. `LuaLiteral` still
embeds helper bindings and references as text (for example the object/string index helpers), so
Expand Down Expand Up @@ -525,9 +534,9 @@ Notes; finished-work narrative does not.
- Tests run five Jass configurations plus the interpreter, then the Lua target separately.
`testAssertOkLines(true, ...)` covers both the pre-transform interpreter and full monomorphisation.
- `@Test` functions are interpreter unit tests by design; `StdLibOwnTests` and `grill test` run them
there. The only Lua-target execution the suite has is `test().testLua(true).executeProg()`, which
runs the emitted script in a real Lua 5.3 against the shim in `src/test/resources/luaruntime/`. Its
reach is bounded by how much of the roughly one thousand natives the shim models, so those tests
there. The suite executes Lua only in `test().testLua(true).executeProg()` and, under `-PallBackends`,
in every other executing test: the emitted script runs in a real Lua 5.3 against the shim in
`src/test/resources/luaruntime/`. Its reach is bounded by how much of the roughly one thousand natives the shim models, so those tests
stay small and targeted. There is no Wurst-level end-to-end feature; correctness in a real map on
the Lua target is asserted in the agent workflow.
- `WURST_LANGUAGE.md` ships as a compiler resource at
Expand Down
10 changes: 10 additions & 0 deletions de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ test {
systemProperty 'wurst.test.imDumps', 'true'
}

// -PallBackends (master CI): every executing test runs the Lua target after its Jass runs too, and a test
// exempt from Lua (luaExempt) must fail there; -PallBackends=full adds Lua with -inline -localOptimizations.
if (project.hasProperty('allBackends')) {
def allBackends = project.findProperty('allBackends').toString()
if (!(allBackends in ['', 'true', 'full'])) {
throw new GradleException("-PallBackends takes no value or 'full', not '$allBackends'")
}
systemProperty 'wurst.test.allBackends', allBackends == 'full' ? 'full' : 'lua'
}

// The collector for the test JVMs; -PtestGc='-XX:+UseG1GC' (or another flag) overrides it.
jvmArgs((project.findProperty('testGc') ?: '-XX:+UseParallelGC').toString().split(' '))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ public void testCompiletimeObjectIdMigrationStress() {
test().executeProg(true)
.runCompiletimeFunctions(true)
.executeProgOnlyAfterTransforms()
.luaExempt(LuaExemption.OBJECT_BOOKKEEPING, "Succeed function not called")
.lines("package Test",
"native testSuccess()",
"class A",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public class GenericsWithTypeclassesTests extends WurstScriptTest {

private static final String STATIC_SPLIT_BY_CONSTANT_ARGUMENT_ON_LUA =
"A generic class's static is split on Lua when its constructor passes a constant static to a method.";

@Test
public void identity() {
Expand Down Expand Up @@ -1779,7 +1781,8 @@ public void inheritedField_lazyClosure_uses_enclosing_receiver() {

@Test
public void arrayListInClosure() {
testAssertOkLines(true,
test().executeProg(true).luaExempt(LuaExemption.KNOWN_LUA_DEFECT, STATIC_SPLIT_BY_CONSTANT_ARGUMENT_ON_LUA,
"uses the erased generic static ArrayList_nextFreeIndex, which has specialised copies").lines(
"package Hello",
"import NoWurst",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

public class InterpreterTests extends WurstScriptTest {

private static final String LUA_HANDLE_IDS =
"`GetHandleId` of a unit or another agent is the compiler's own counter on Lua.";



@Test
public void testR2SW() {
test().executeProg(true).testLua(false).lines(
test().executeProg(true).testLua(true).luaOnly(false).lines(
"package Test",
"native testSuccess()",
"native testFail(string msg)",
Expand Down Expand Up @@ -128,7 +130,7 @@ public void returnAndExitwhenLeaveTheRightStatements() {

@Test(expectedExceptions = {InterpreterException.class})
public void r2swBeyondTheModelledRange() {
test().executeProg(true).testLua(false).lines(
test().executeProg(true).lines(
"package Test",
"native testSuccess()",
"@extern native R2SW(real r, integer width, integer precision) returns string",
Expand All @@ -140,7 +142,7 @@ public void r2swBeyondTheModelledRange() {

@Test(expectedExceptions = {InterpreterException.class})
public void arrayDefaultTestFail() {
test().executeProg(true).testLua(false).lines(
test().executeProg(true).lines(
"package Test",
"native testSuccess()",
"native testFail(string msg)",
Expand Down Expand Up @@ -180,7 +182,7 @@ public void displayNativesAcceptNullForceAndLocalPlayer() {

@Test
public void setPlayerTechMaxAllowed() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).testLua(true).luaOnly(false).lines(
"package Test",
"init",
" SetPlayerTechMaxAllowed(Player(0), 'hfoo', 3)",
Expand All @@ -191,7 +193,7 @@ public void setPlayerTechMaxAllowed() {

@Test
public void playerStateAndSlotNatives() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GetPlayerSlotState").lines(
"package Test",
"init",
" let gold = ConvertPlayerState(1)",
Expand Down Expand Up @@ -220,7 +222,7 @@ public void playerStateAndSlotNatives() {

@Test
public void unitStateAbilityAndOrderNatives() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GetOwningPlayer").lines(
"package Test",
"init",
" let u = CreateUnit(Player(2), 'hfoo', 12.5, -3.25, 90.0)",
Expand Down Expand Up @@ -402,7 +404,7 @@ public void unitStateAbilityAndOrderNatives() {
* unselectable. */
@Test
public void unitSelectableAndAliveNatives() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "BlzIsUnitSelectable").lines(
"package Test",
"init",
" let u = CreateUnit(Player(0), 'hfoo', 0.0, 0.0, 0.0)",
Expand Down Expand Up @@ -460,7 +462,7 @@ public void unitSelectableAndAliveNatives() {
* evaluate their ConvertX initialisers itself. */
@Test
public void commonJConstantsCarryTheirHandles() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "IsUnitType").lines(
"package Test",
"init",
" if UNIT_TYPE_DEAD == null",
Expand Down Expand Up @@ -512,7 +514,7 @@ public void derivedAndLessCommonConstants() {
*/
@Test
public void stringNativesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "S2R").lines(
"package Test",
"@noinline function w(real x) returns real",
" return x",
Expand Down Expand Up @@ -572,7 +574,7 @@ public void stringNativesAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void mathNativesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "R2S").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand All @@ -591,7 +593,7 @@ public void mathNativesAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void hashtableNativesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "CreateItem").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand Down Expand Up @@ -624,7 +626,8 @@ public void hashtableNativesAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void conversionNativesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.KNOWN_LUA_DEFECT, LUA_HANDLE_IDS,
"GetHandleId of a unit gave false").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand All @@ -647,7 +650,7 @@ public void conversionNativesAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void playerResourcesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).testLua(true).luaOnly(false).lines(
"package Test",
"init",
" let p = Player(1)",
Expand All @@ -666,7 +669,7 @@ public void playerResourcesAsMeasured() {
* data: a new unit has 100 life and no mana. */
@Test
public void unitLifeAndManaAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GetUnitState").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand Down Expand Up @@ -753,7 +756,7 @@ public void unitLifeAndManaAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void abilityNativesAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "UnitAddAbility").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand All @@ -777,7 +780,7 @@ public void abilityNativesAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client, with the default experience table. */
@Test
public void heroLevelsAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GetHeroLevel").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand Down Expand Up @@ -814,7 +817,7 @@ public void heroLevelsAsMeasured() {
/** Every expected value here was measured on the 3.0.0 client. */
@Test
public void groupOrderAsMeasured() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GroupAddUnit").lines(
"package Test",
"function measured(string name, string actual, string expected)",
" if actual != expected",
Expand Down Expand Up @@ -874,7 +877,7 @@ public void getOwningPlayerNullUnitReturnsWurstNull() {

@Test
public void destructableWidgetLifeNatives() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "GetWidgetLife").lines(
"package Test",
"init",
" let d = CreateDestructable('LTlt', 1.0, 2.0, 0.0, 1.0, 0)",
Expand All @@ -897,7 +900,7 @@ public void destructableWidgetLifeNatives() {

@Test
public void unitAndAbilityInfoNatives() {
test().withStdLib().executeProg(true).testLua(false).lines(
test().withStdLib().executeProg(true).luaExempt(LuaExemption.MISSING_TEST_NATIVE, "RemoveUnit").lines(
"package Test",
"native GetUnitBuildTime(integer unitid) returns integer",
"init",
Expand All @@ -924,7 +927,7 @@ public void unitAndAbilityInfoNatives() {
* != and the orderings compare exactly. So a != b is not not (a == b) for reals. */
@Test
public void jassRealEqualityAllowsAThousandth() {
test().executeProg(true).testLua(false).lines(
test().executeProg(true).luaExempt(LuaExemption.REAL_EQUALITY_TOLERANCE, "within 0.001 is equal").lines(
"package Test",
"native testSuccess()",
"native testFail(string msg)",
Expand Down
Loading
Loading