|
| 1 | +package cases.issues; |
| 2 | + |
| 3 | +import utest.Async; |
| 4 | + |
| 5 | +class Issue12001 extends TestCase { |
| 6 | + function testDefineType(_) { |
| 7 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 8 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 9 | + var args = ["-main", "Empty", "--macro", "Macro.defineType()"]; |
| 10 | + runHaxe(args); |
| 11 | + assertSuccess(); |
| 12 | + |
| 13 | + // Nothing is loading Foo, so no redefinition issue |
| 14 | + runHaxe(args); |
| 15 | + assertSuccess(); |
| 16 | + } |
| 17 | + |
| 18 | + function testRedefineTypeCatchError(_) { |
| 19 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 20 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 21 | + var args = ["-main", "Empty", "--macro", "Macro.redefineTypeCatchError()"]; |
| 22 | + runHaxe(args); |
| 23 | + assertSuccess(); |
| 24 | + |
| 25 | + runHaxe(args); |
| 26 | + assertSuccess(); |
| 27 | + assertHasPrint("Macro.hx:56: TInst(Foobar,[])"); |
| 28 | + assertHasPrint("Macro.hx:69: Cannot redefine module Foobar"); |
| 29 | + } |
| 30 | + |
| 31 | + @:async |
| 32 | + @:timeout(3000) |
| 33 | + function testRedefineType(async:Async) { |
| 34 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 35 | + vfs.putContent("Main.hx", getTemplate("issues/Issue12001/Main.hx")); |
| 36 | + var args = ["-main", "Main", "--interp", "--macro", "Macro.defineType()"]; |
| 37 | + var i = 0; |
| 38 | + function test() { |
| 39 | + // Was failing with nightlies (HxbFailure) |
| 40 | + runHaxe(args, () -> { |
| 41 | + assertSuccess(); |
| 42 | + assertHasPrint("Foo.test() = " + i); |
| 43 | + if (++i >= 5) async.done(); |
| 44 | + else test(); |
| 45 | + }); |
| 46 | + } |
| 47 | + test(); |
| 48 | + } |
| 49 | + |
| 50 | + function testDefineModule(_) { |
| 51 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 52 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 53 | + var args = ["-main", "Empty", "--macro", "Macro.defineModule()"]; |
| 54 | + runHaxe(args); |
| 55 | + assertSuccess(); |
| 56 | + |
| 57 | + // Nothing is loading Bar, so no redefinition issue |
| 58 | + runHaxe(args); |
| 59 | + assertSuccess(); |
| 60 | + } |
| 61 | + |
| 62 | + function testRedefineModuleCatchError(_) { |
| 63 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 64 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 65 | + var args = ["-main", "Empty", "--macro", "Macro.redefineModuleCatchError()"]; |
| 66 | + runHaxe(args); |
| 67 | + assertSuccess(); |
| 68 | + |
| 69 | + runHaxe(args); |
| 70 | + assertSuccess(); |
| 71 | + assertHasPrint("Macro.hx:77: TInst(Foobaz,[])"); |
| 72 | + assertHasPrint("Macro.hx:90: Cannot redefine module Foobaz"); |
| 73 | + } |
| 74 | + |
| 75 | + @:async |
| 76 | + @:timeout(3000) |
| 77 | + function testRedefineModule(async:Async) { |
| 78 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 79 | + vfs.putContent("Main.hx", getTemplate("issues/Issue12001/Main1.hx")); |
| 80 | + var args = ["-main", "Main", "--interp", "--macro", "Macro.defineModule()"]; |
| 81 | + var i = 0; |
| 82 | + function test() { |
| 83 | + // Was failing with nightlies (HxbFailure) |
| 84 | + runHaxe(args, () -> { |
| 85 | + assertSuccess(); |
| 86 | + assertHasPrint("Bar.test() = " + i); |
| 87 | + if (++i >= 5) async.done(); |
| 88 | + else test(); |
| 89 | + }); |
| 90 | + } |
| 91 | + test(); |
| 92 | + } |
| 93 | + |
| 94 | + @:async |
| 95 | + @:timeout(3000) |
| 96 | + function testRedefineAfterTyping(async:Async) { |
| 97 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx")); |
| 98 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 99 | + var args = ["-main", "Empty", "--interp", "--macro", "Macro.hookRedefine()"]; |
| 100 | + var i = 0; |
| 101 | + function test() { |
| 102 | + runHaxe(args, () -> { |
| 103 | + assertSuccess(); |
| 104 | + // Newest version is being included |
| 105 | + assertHasPrint("Baz.test() = " + i); |
| 106 | + if (++i >= 5) async.done(); |
| 107 | + else test(); |
| 108 | + }); |
| 109 | + } |
| 110 | + test(); |
| 111 | + } |
| 112 | + |
| 113 | + function testInvalidateError(_) { |
| 114 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro1.hx")); |
| 115 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 116 | + var args = ["-main", "Empty", "--interp", "--macro", "Macro.hookInvalidateError()"]; |
| 117 | + runHaxe(args); |
| 118 | + assertErrorMessage("Cannot invalidate loaded module Empty"); |
| 119 | + } |
| 120 | + |
| 121 | + function testInvalidateCaughtError(_) { |
| 122 | + vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro1.hx")); |
| 123 | + vfs.putContent("Empty.hx", getTemplate("Empty.hx")); |
| 124 | + var args = ["-main", "Empty", "--interp", "--macro", "Macro.hookInvalidateCatch()"]; |
| 125 | + runHaxe(args); |
| 126 | + assertSuccess(); |
| 127 | + assertHasPrint("Cannot invalidate loaded module Empty"); |
| 128 | + } |
| 129 | +} |
0 commit comments