Skip to content

Commit

Permalink
[tests] add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Feb 11, 2025
1 parent 9ae3a10 commit cf14ba3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/server/src/cases/issues/Issue12001.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cases.issues;

class Issue12001 extends TestCase {
function testDefineType(_) {
vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
var args = ["-main", "Empty", "--macro", "Macro.defineType()"];
runHaxe(args);
assertSuccess();

runHaxe(args);
Assert.isFalse(0 == errorMessages.length);
assertErrorMessage("Cannot redefine module Foo");
}

function testDefineModule(_) {
vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
var args = ["-main", "Empty", "--macro", "Macro.defineModule()"];
runHaxe(args);
assertSuccess();

runHaxe(args);
Assert.isFalse(0 == errorMessages.length);
assertErrorMessage("Cannot redefine module Bar");
}
}
25 changes: 25 additions & 0 deletions tests/server/test/templates/issues/Issue12001/Macro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import haxe.macro.Context;

function defineType() {
Context.onAfterInitMacros(() -> {
Context.defineType({
pos: Context.currentPos(),
pack: [],
name: "Foo",
kind: TDAbstract(macro :String, [], [], []),
fields: []
});
});
}

function defineModule() {
Context.onAfterInitMacros(() -> {
Context.defineModule("Bar", [{
pos: Context.currentPos(),
pack: [],
name: "Bar",
kind: TDAbstract(macro :String, [], [], []),
fields: []
}]);
});
}

0 comments on commit cf14ba3

Please sign in to comment.