From 067c8c3d5a24622ecf2f85c590bb01c0b361e48e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 12 Feb 2025 16:17:28 +0100 Subject: [PATCH] [tests] update tests --- tests/server/src/cases/issues/Issue12001.hx | 56 +++++++------------ .../test/templates/issues/Issue12001/Macro.hx | 45 +++------------ .../test/templates/issues/Issue12001/Main.hx | 2 +- .../test/templates/issues/Issue12001/Main1.hx | 2 +- .../test/templates/issues/Issue12001/Main2.hx | 3 - 5 files changed, 29 insertions(+), 79 deletions(-) delete mode 100644 tests/server/test/templates/issues/Issue12001/Main2.hx diff --git a/tests/server/src/cases/issues/Issue12001.hx b/tests/server/src/cases/issues/Issue12001.hx index 7e06364afb3..ce4408d2355 100644 --- a/tests/server/src/cases/issues/Issue12001.hx +++ b/tests/server/src/cases/issues/Issue12001.hx @@ -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(_) { @@ -39,29 +46,18 @@ 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(); }); @@ -69,18 +65,6 @@ class Issue12001 extends TestCase { 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) { @@ -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(); }); diff --git a/tests/server/test/templates/issues/Issue12001/Macro.hx b/tests/server/test/templates/issues/Issue12001/Macro.hx index 7f1640ce019..effd3530d5c 100644 --- a/tests/server/test/templates/issues/Issue12001/Macro.hx +++ b/tests/server/test/templates/issues/Issue12001/Macro.hx @@ -1,5 +1,6 @@ import haxe.macro.Context; +@:persistent var i = 0; function defineType() { Context.onAfterInitMacros(() -> { Context.defineType({ @@ -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", [{ @@ -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; @@ -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 }]); }); diff --git a/tests/server/test/templates/issues/Issue12001/Main.hx b/tests/server/test/templates/issues/Issue12001/Main.hx index afce2304763..30367f8cb3d 100644 --- a/tests/server/test/templates/issues/Issue12001/Main.hx +++ b/tests/server/test/templates/issues/Issue12001/Main.hx @@ -1,3 +1,3 @@ function main() { - Foo.test; + Foo.test(); } diff --git a/tests/server/test/templates/issues/Issue12001/Main1.hx b/tests/server/test/templates/issues/Issue12001/Main1.hx index 3ba5022b7ae..0b97ed04e59 100644 --- a/tests/server/test/templates/issues/Issue12001/Main1.hx +++ b/tests/server/test/templates/issues/Issue12001/Main1.hx @@ -1,3 +1,3 @@ function main() { - Bar.test; + Bar.test(); } diff --git a/tests/server/test/templates/issues/Issue12001/Main2.hx b/tests/server/test/templates/issues/Issue12001/Main2.hx deleted file mode 100644 index 24c8ee7337b..00000000000 --- a/tests/server/test/templates/issues/Issue12001/Main2.hx +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - Foobar.test(); -}