Browse Source

[tests] Add test for #11549 (#12092)

* [tests] Display tests: allow running for a specific target

* [tests] Display tests: better error reporting for test metadata

* [tests] Add test for #11549

* Install hxjava for display tests..

* [tests] Run target specific display tests if any

* [tests] Move test for #11549

* [tests] hxjava no longer needed for macro tests

* [tests] Better typing
Rudy Ges 5 months ago
parent
commit
de340ec5c3

+ 16 - 0
tests/display/src/BaseDisplayTestContext.hx

@@ -22,6 +22,7 @@ class BaseDisplayTestContext {
 	var markers:Map<Int, Int>;
 	var fieldName:String;
 
+	public var target:Null<haxe.macro.Compiler.Platform> = Cross;
 	public final source:File;
 
 	public function new(path:String, fieldName:String, source:String, markers:Map<Int, Int>) {
@@ -57,6 +58,21 @@ class BaseDisplayTestContext {
 	}
 
 	public function runHaxe(args:Array<String>, ?stdin:String) {
+		args = switch (target) {
+			case Cross: args;
+			case Js: ["--js", "out.js"].concat(args);
+			case Lua: ["--lua", "out.lua"].concat(args);
+			case Neko: ["--neko", "out.n"].concat(args);
+			case Flash: ["--swf", "out.swf"].concat(args);
+			case Php: ["--php", "php-out"].concat(args);
+			case Cpp: ["--cpp", "cpp-out"].concat(args);
+			case Jvm: ["--jvm", "out.jar"].concat(args);
+			case Python: ["--python", "out.py"].concat(args);
+			case Hl: ["--hl", "out.hl"].concat(args);
+			case Eval: ["--interp"].concat(args);
+			case CustomTarget(name): ["--custom-target", name].concat(args);
+		}
+
 		return haxeServer.rawRequest([
 			"--cwd", dir,
 			"-cp", '${Sys.getCwd()}/src-misc',

+ 14 - 2
tests/display/src/Macro.hx

@@ -11,6 +11,11 @@ class Macro {
 	static function buildTestCase():Array<Field> {
 		var fields = Context.getBuildFields();
 		var c = Context.getLocalClass().get();
+
+		var setupTarget = macro {};
+		var target = haxe.macro.Context.definedValue("display.target");
+		if (target != null) setupTarget = macro ctx.target = $i{target};
+
 		for (field in fields) {
 			if (field.doc == null) {
 				continue;
@@ -28,11 +33,14 @@ class Macro {
 			var filename = Context.getPosInfos(c.pos).file;
 			for (meta in field.meta) {
 				if (meta.name == ":filename") {
+					if (meta.params.length != 1) {
+						Context.error("String argument expected", meta.pos);
+					}
 					switch (meta.params[0].expr) {
 						case EConst(CString(s)):
 							filename = Path.directory(filename) + "/" + s;
 						case _:
-							throw "String expected";
+							Context.error("String expected", meta.params[0].pos);
 					}
 				}
 			}
@@ -44,6 +52,7 @@ class Macro {
 						static var methodArgs = {method: haxe.display.Protocol.Methods.ResetCache, id: 1, params: {}};
 						var args = ['--display', haxe.Json.stringify(methodArgs)];
 						ctx.runHaxe(args);
+						$setupTarget;
 						${f.expr}
 					};
 				case _:
@@ -55,6 +64,9 @@ class Macro {
 	#end
 
 	macro static public function getCases(pack:String) {
+		var target = haxe.macro.Context.definedValue("display.target");
+		if (target != null) pack = '$pack.${target.toLowerCase()}';
+
 		var cases = [];
 		var singleCase = haxe.macro.Context.definedValue("test");
 		function loop(pack:Array<String>) {
@@ -70,7 +82,7 @@ class Macro {
 				if (p.ext == "hx") {
 					var tp = {pack: pack, name: p.file};
 					cases.push(macro new $tp());
-				} else if (Path.join([path, file]).isDirectory()) {
+				} else if (file.startsWith("_") && Path.join([path, file]).isDirectory()) {
 					loop(pack.concat([file]));
 				}
 			}

+ 27 - 0
tests/display/src/cases/jvm/Issue11549.hx

@@ -0,0 +1,27 @@
+package cases.jvm;
+
+class Issue11549 extends DisplayTestCase {
+	/**
+		import java.util.concurrent.Executors;
+		import java.util.concurrent.TimeUnit;
+		import java.lang.Runnable;
+
+		final exec = Executors.newSingleThreadScheduledExecutor();
+
+		function schedule(f:() -> Void)
+			exec.schedule(f, 0, TimeUnit.MILLISECONDS);
+
+		function greeter():Void {
+			trace("hello");
+			exec.shutdown();
+		}
+
+		function main() {
+			schedule(greeter);
+			exec.{-1-}
+		}
+	**/
+	function test() {
+		eq(true, hasField(fields(pos(1)), "isTerminated", "() -> Bool"));
+	}
+}

+ 18 - 0
tests/runci/Display.hx

@@ -0,0 +1,18 @@
+package runci;
+
+import haxe.io.Path;
+import haxe.macro.Compiler.Platform;
+import sys.FileSystem;
+
+class Display {
+	static public function maybeRunDisplayTests(target:Platform) {
+		final target = target.getName();
+		final pack = Path.join([Config.displayDir, "src", "cases", target.toLowerCase()]);
+		if (FileSystem.exists(pack)) {
+			System.changeDirectory(Config.displayDir);
+			System.haxelibInstallGit("Simn", "haxeserver");
+			System.runCommand("haxe", ["build.hxml", "-D", "display.protocol=xml", "-D", 'display.target=$target']);
+			System.runCommand("haxe", ["build.hxml", "-D", "display.protocol=jsonrpc", "-D", 'display.target=$target']);
+		}
+	}
+}

+ 2 - 0
tests/runci/targets/Cpp.hx

@@ -72,6 +72,8 @@ class Cpp {
 				runCpp("bin/cppia/Host-debug", ["bin/unit.cppia", "-jit"]);
 		}
 
+		Display.maybeRunDisplayTests(Cpp);
+
 		changeDirectory(sysDir);
 		runCommand("haxe", ["-D", archFlag, "--each", "compile-cpp.hxml"].concat(args));
 		runSysTest(FileSystem.fullPath("bin/cpp/Main-debug"));

+ 2 - 0
tests/runci/targets/Flash.hx

@@ -252,6 +252,8 @@ class Flash {
 			runFlash("bin/unit.swf");
 		}
 
+		Display.maybeRunDisplayTests(Flash);
+
 		changeDirectory(miscFlashDir);
 		runCommand("haxe", ["run.hxml"]);
 	}

+ 2 - 0
tests/runci/targets/Hl.hx

@@ -120,6 +120,8 @@ class Hl {
 		changeDirectory(threadsDir);
 		buildAndRun("build.hxml", "export/threads");
 
+		Display.maybeRunDisplayTests(Hl);
+
 		changeDirectory(sysDir);
 		runCommand("haxe", ["compile-hl.hxml"].concat(args));
 		runSysTest(hlBinary, ["bin/hl/sys.hl"]);

+ 2 - 0
tests/runci/targets/Js.hx

@@ -131,6 +131,8 @@ class Js {
 		runCommand("haxe", ["build.hxml", "-D", "disable-hxb-cache"]);
 		runCommand("node", ["test.js"]);
 
+		Display.maybeRunDisplayTests(Js);
+
 		changeDirectory(sysDir);
 		installNpmPackages(["deasync"]);
 		runCommand("haxe", ["compile-js.hxml"].concat(args));

+ 2 - 0
tests/runci/targets/Jvm.hx

@@ -33,6 +33,8 @@ class Jvm {
 			runCommand("java", ["-jar", "bin/unit.jar"]);
 		}
 
+		Display.maybeRunDisplayTests(Jvm);
+
 		changeDirectory(miscJavaDir);
 		runCommand("haxe", ["run.hxml"]);
 

+ 2 - 0
tests/runci/targets/Lua.hx

@@ -97,6 +97,8 @@ class Lua {
 			runCommand("haxe", ["compile-lua.hxml"].concat(args).concat(luaVer));
 			runCommand("lua", ["bin/unit.lua"]);
 
+			Display.maybeRunDisplayTests(Lua);
+
 			changeDirectory(sysDir);
 			runCommand("haxe", ["compile-lua.hxml"].concat(args).concat(luaVer));
 			runSysTest("lua", ["bin/lua/sys.lua"]);

+ 2 - 0
tests/runci/targets/Macro.hx

@@ -28,6 +28,8 @@ class Macro {
 		changeDirectory(getMiscSubDir("resolution"));
 		runCommand("haxe", ["run.hxml"]);
 
+		Display.maybeRunDisplayTests(Eval);
+
 		changeDirectory(sysDir);
 		runSysTest("haxe", ["compile-macro.hxml"].concat(args));
 

+ 2 - 0
tests/runci/targets/Neko.hx

@@ -11,6 +11,8 @@ class Neko {
 		changeDirectory(getMiscSubDir('neko'));
 		runCommand("haxe", ["run.hxml"].concat(args));
 
+		Display.maybeRunDisplayTests(Neko);
+
 		changeDirectory(sysDir);
 		runCommand("haxe", ["compile-neko.hxml"].concat(args));
 		runSysTest("neko", ["bin/neko/sys.n"]);

+ 2 - 0
tests/runci/targets/Php.hx

@@ -87,6 +87,8 @@ class Php {
 			runCommand("haxe", ["compile-php.hxml"].concat(prefix).concat(args));
 			runCommand("php", generateArgs(binDir + "/index.php"));
 
+			Display.maybeRunDisplayTests(Php);
+
 			changeDirectory(sysDir);
 			if(isCi())
 				deleteDirectoryRecursively(binDir);

+ 2 - 0
tests/runci/targets/Python.hx

@@ -67,6 +67,8 @@ class Python {
 			runCommand(py, ["bin/unit34.py"]);
 		}
 
+		Display.maybeRunDisplayTests(Python);
+
 		changeDirectory(sysDir);
 		runCommand("haxe", ["compile-python.hxml"].concat(args));
 		for (py in pys) {