소스 검색

[tests] add test

Rudy Ges 7 달 전
부모
커밋
cf14ba3219
2개의 변경된 파일52개의 추가작업 그리고 0개의 파일을 삭제
  1. 27 0
      tests/server/src/cases/issues/Issue12001.hx
  2. 25 0
      tests/server/test/templates/issues/Issue12001/Macro.hx

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

@@ -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 - 0
tests/server/test/templates/issues/Issue12001/Macro.hx

@@ -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: []
+		}]);
+	});
+}