瀏覽代碼

[tests] Compilation server tests (#11159): add Context.getType vs Context.resolveType variants

Rudy Ges 1 年之前
父節點
當前提交
02d27c191c

+ 10 - 5
tests/server/src/cases/CsSafeTypeBuilding.hx

@@ -91,11 +91,15 @@ class CsSafeTypeBuilding extends TestCase {
 		}
 	}
 
-	@:variant("JsDefineModule", true, "js")
-	@:variant("JsDefineType", false, "js")
-	@:variant("InterpDefineModule", true, "interp")
-	@:variant("InterpDefineType", false, "interp")
-	function test(defineModule:Bool, target:String) {
+	@:variant("Js_DefineModule_GetType", true, true, "js")
+	@:variant("Js_DefineType_GetType", false, true, "js")
+	@:variant("Js_DefineModule_ResolveType", true, false, "js")
+	@:variant("Js_DefineType_ResolveType", false, false, "js")
+	@:variant("Interp_DefineModule_GetType", true, true, "interp")
+	@:variant("Interp_DefineType_GetType", false, true, "interp")
+	@:variant("Interp_DefineModule_ResolveType", true, false, "interp")
+	@:variant("Interp_DefineType_ResolveType", false, false, "interp")
+	function test(defineModule:Bool, getType:Bool, target:String) {
 		var targetArgs = switch target {
 			case "js": ["-js", "out.js", "-lib", "hxnodejs", "-cmd", "node out.js"];
 			case "interp": ["--interp"];
@@ -104,6 +108,7 @@ class CsSafeTypeBuilding extends TestCase {
 
 		var args = ["-main", "Main", "Baz"];
 		if (defineModule) args = args.concat(["-D", "config.defineModule"]);
+		if (getType) args = args.concat(["-D", "config.getType"]);
 		args = args.concat(targetArgs);
 
 		runHaxe(args);

+ 16 - 0
tests/server/test/templates/csSafeTypeBuilding/Macro.macro.hx

@@ -11,11 +11,23 @@ class Macro {
 
 	@:persistent static var generated = new Map<String, Bool>();
 
+	#if config.getType
+	static function isAlive(name:String):Bool {
+		// Null check is just there to make it a one liner
+		// Basically returning true if no exception is caught
+		return try Context.getType(name) != null
+			catch(s:String) {
+				if (s != 'Type not found \'$name\'') throw s;
+				false;
+			};
+	}
+	#else
 	static function isAlive(ct:ComplexType, pos:Position):Bool {
 		// Null check is just there to make it a one liner
 		// Basically returning true if no exception is caught
 		return try Context.resolveType(ct, pos) != null catch(e) false;
 	}
+	#end
 
 	public static function buildFoo() {
 		var from = '[${Context.getLocalModule()}] ';
@@ -29,7 +41,11 @@ class Macro {
 				var ct = TPath({pack: [], name: key});
 
 				if (generated.exists(key)) {
+					#if config.getType
+					if (isAlive(key)) {
+					#else
 					if (isAlive(ct, pos)) {
+					#end
 						print('Reusing previously generated type for $key.');
 						return ct;
 					}