瀏覽代碼

[tests] add more tests

Rudy Ges 7 月之前
父節點
當前提交
177040f3ac

+ 37 - 0
tests/server/src/cases/issues/Issue12001.hx

@@ -13,6 +13,18 @@ class Issue12001 extends TestCase {
 		assertErrorMessage("Cannot redefine module Foo");
 		assertErrorMessage("Cannot redefine module Foo");
 	}
 	}
 
 
+	function testDefineType1(_) {
+		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);
+		Assert.isFalse(hasErrorMessage('HxbData.HxbFailure("Could not read static field test on Foo while hxbing Main")'));
+		assertErrorMessage("Cannot redefine module Foo");
+	}
+
 	function testDefineModule(_) {
 	function testDefineModule(_) {
 		vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
 		vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
 		vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
 		vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
@@ -24,4 +36,29 @@ class Issue12001 extends TestCase {
 		Assert.isFalse(0 == errorMessages.length);
 		Assert.isFalse(0 == errorMessages.length);
 		assertErrorMessage("Cannot redefine module Bar");
 		assertErrorMessage("Cannot redefine module Bar");
 	}
 	}
+
+	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);
+		Assert.isFalse(0 == errorMessages.length);
+		Assert.isFalse(hasErrorMessage('HxbData.HxbFailure("Could not read static field test on Bar while hxbing Main")'));
+		assertErrorMessage("Cannot redefine module Bar");
+	}
+
+	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();
+
+		runHaxe(args);
+		Assert.isFalse(0 == errorMessages.length);
+		assertErrorMessage("Cannot redefine module Baz");
+	}
 }
 }

+ 28 - 4
tests/server/test/templates/issues/Issue12001/Macro.hx

@@ -6,8 +6,10 @@ function defineType() {
 			pos: Context.currentPos(),
 			pos: Context.currentPos(),
 			pack: [],
 			pack: [],
 			name: "Foo",
 			name: "Foo",
-			kind: TDAbstract(macro :String, [], [], []),
-			fields: []
+			kind: TDClass(null, null, false, false, false),
+			fields: (macro class Foo {
+				public static function test() {}
+			}).fields
 		});
 		});
 	});
 	});
 }
 }
@@ -18,8 +20,30 @@ function defineModule() {
 			pos: Context.currentPos(),
 			pos: Context.currentPos(),
 			pack: [],
 			pack: [],
 			name: "Bar",
 			name: "Bar",
-			kind: TDAbstract(macro :String, [], [], []),
-			fields: []
+			kind: TDClass(null, null, false, false, false),
+			fields: (macro class Bar {
+				public static function test() {}
+			}).fields
 		}]);
 		}]);
 	});
 	});
 }
 }
+
+function hook() {
+	var generated = false;
+	Context.onAfterTyping((_) -> {
+		if (generated) return;
+		generated = true;
+
+		Context.defineModule("Baz", [{
+			pos: Context.currentPos(),
+			pack: [],
+			name: "Baz",
+			kind: TDClass(null, null, false, false, false),
+			fields: (macro class Baz {
+				public static function test() {}
+			}).fields
+		}]);
+	});
+
+	return null;
+}

+ 3 - 0
tests/server/test/templates/issues/Issue12001/Main.hx

@@ -0,0 +1,3 @@
+function main() {
+	Foo.test;
+}

+ 3 - 0
tests/server/test/templates/issues/Issue12001/Main1.hx

@@ -0,0 +1,3 @@
+function main() {
+	Bar.test;
+}