Skip to content

Commit

Permalink
[tests] update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Feb 12, 2025
1 parent 664a10b commit 067c8c3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 79 deletions.
56 changes: 20 additions & 36 deletions tests/server/src/cases/issues/Issue12001.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ class Issue12001 extends TestCase {
assertSuccess();
}

function testDefineType1(_) {
@:async
@:timeout(3000)
function testRedefineType(async:Async) {
vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
vfs.putContent("Main.hx", getTemplate("issues/Issue12001/Main.hx"));
var args = ["-main", "Main", "--macro", "Macro.defineType()"];
runHaxe(args);
assertSuccess();

runHaxe(args);
assertSuccess();
assertSkipping("Main", DependencyDirty("Foo - Tainted define_type"));
var args = ["-main", "Main", "--interp", "--macro", "Macro.defineType()"];
var i = 0;
function test() {
// Was failing with nightlies (HxbFailure)
runHaxe(args, () -> {
assertSuccess();
assertHasPrint("Foo.test() = " + i);
if (++i >= 5) async.done();
else test();
});
}
test();
}

function testDefineModule(_) {
Expand All @@ -39,48 +46,25 @@ class Issue12001 extends TestCase {
assertSuccess();
}

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

runHaxe(args);
assertSuccess();
assertSkipping("Main", DependencyDirty("Bar - Tainted define_module"));
}

@:async
@:timeout(3000)
function testRedefineModule(async:Async) {
vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
vfs.putContent("Main.hx", getTemplate("issues/Issue12001/Main2.hx"));
var args = ["-main", "Main", "--interp", "--macro", "Macro.redefineModule()"];
vfs.putContent("Main.hx", getTemplate("issues/Issue12001/Main1.hx"));
var args = ["-main", "Main", "--interp", "--macro", "Macro.defineModule()"];
var i = 0;
function test() {
// Was failing with nightlies (HxbFailure)
runHaxe(args, () -> {
assertSuccess();
assertHasPrint("Foobar.test() = " + i);
assertHasPrint("Bar.test() = " + i);
if (++i >= 5) async.done();
else test();
});
}
test();
}

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

// Nothing is loading Baz, so it can be defined again
runHaxe(args);
assertSuccess();
}

@:async
@:timeout(3000)
function testRedefineAfterTyping(async:Async) {
Expand All @@ -92,7 +76,7 @@ class Issue12001 extends TestCase {
runHaxe(args, () -> {
assertSuccess();
// Newest version is being included
assertHasPrint("Foobaz.test() = " + i);
assertHasPrint("Baz.test() = " + i);
if (++i >= 5) async.done();
else test();
});
Expand Down
45 changes: 7 additions & 38 deletions tests/server/test/templates/issues/Issue12001/Macro.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import haxe.macro.Context;

@:persistent var i = 0;
function defineType() {
Context.onAfterInitMacros(() -> {
Context.defineType({
Expand All @@ -8,12 +9,13 @@ function defineType() {
name: "Foo",
kind: TDClass(null, null, false, false, false),
fields: (macro class Foo {
public static function test() {}
public static function test() Sys.println("Foo.test() = " + $v{i++});
}).fields
});
});
}

@:persistent var j = 0;
function defineModule() {
Context.onAfterInitMacros(() -> {
Context.defineModule("Bar", [{
Expand All @@ -22,28 +24,14 @@ function defineModule() {
name: "Bar",
kind: TDClass(null, null, false, false, false),
fields: (macro class Bar {
public static function test() {}
}).fields
}]);
});
}

@:persistent var i = 0;
function redefineModule() {
Context.onAfterInitMacros(() -> {
Context.defineModule("Foobar", [{
pos: Context.currentPos(),
pack: [],
name: "Foobar",
kind: TDClass(null, null, false, false, false),
fields: (macro class Foobar {
public static function test() Sys.println("Foobar.test() = " + $v{i++});
public static function test() Sys.println("Bar.test() = " + $v{j++});
}).fields
}]);
});
}

function hook() {
@:persistent var k = 0;
function hookRedefine() {
var generated = false;
Context.onAfterTyping((_) -> {
if (generated) return;
Expand All @@ -55,26 +43,7 @@ function hook() {
name: "Baz",
kind: TDClass(null, null, false, false, false),
fields: (macro class Baz {
public static function test() {}
}).fields
}]);
});
}

@:persistent var j = 0;
function hookRedefine() {
var generated = false;
Context.onAfterTyping((_) -> {
if (generated) return;
generated = true;

Context.defineModule("Foobaz", [{
pos: Context.currentPos(),
pack: [],
name: "Foobaz",
kind: TDClass(null, null, false, false, false),
fields: (macro class Foobaz {
public static function __init__() Sys.println("Foobaz.test() = " + $v{j++});
public static function __init__() Sys.println("Baz.test() = " + $v{k++});
}).fields
}]);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/server/test/templates/issues/Issue12001/Main.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function main() {
Foo.test;
Foo.test();
}
2 changes: 1 addition & 1 deletion tests/server/test/templates/issues/Issue12001/Main1.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function main() {
Bar.test;
Bar.test();
}
3 changes: 0 additions & 3 deletions tests/server/test/templates/issues/Issue12001/Main2.hx

This file was deleted.

0 comments on commit 067c8c3

Please sign in to comment.