浏览代码

[tests] try again to get the display tests running through the server

Simon Krajewski 6 年之前
父节点
当前提交
5673ea51e6
共有 1 个文件被更改,包括 28 次插入13 次删除
  1. 28 13
      tests/display/src/DisplayTestContext.hx

+ 28 - 13
tests/display/src/DisplayTestContext.hx

@@ -1,3 +1,5 @@
+import haxe.io.BytesBuffer;
+
 using StringTools;
 
 import Types;
@@ -21,6 +23,8 @@ class HaxeInvocationException {
 }
 
 class DisplayTestContext {
+	static var haxeServer = new sys.io.Process("haxe", ["--wait", "stdio"]);
+
 	var markers:Map<Int, Int>;
 	var fieldName:String;
 
@@ -108,20 +112,31 @@ class DisplayTestContext {
 			"--display",
 			source.path + "@" + displayPart,
 		];
-		var stdin = source.content;
-		var proc = new sys.io.Process("haxe", args);
-		proc.stdin.writeString(stdin);
-		proc.stdin.close();
-		var stderr = proc.stderr.readAll();
-		var stdout = proc.stdout.readAll();
-		var exit = proc.exitCode();
-		proc.close();
-		var success = exit == 0;
-		var s = stderr.toString();
-		if (!success || s == "") {
-			throw new HaxeInvocationException(s, fieldName, args, stdin);
+		var bb = new BytesBuffer();
+		bb.addString(args.join("\n"));
+		bb.addByte(1);
+		bb.addString(source.content);
+		var b = bb.getBytes();
+		haxeServer.stdin.writeInt32(b.length);
+		haxeServer.stdin.write(b);
+		var data = haxeServer.stderr.readString(haxeServer.stderr.readInt32());
+		var buf = new StringBuf();
+		var hasError = false;
+		for (line in data.split("\n")) {
+			switch (line.fastCodeAt(0)) {
+				case 0x01: // print
+				case 0x02: // error
+					hasError = true;
+				default:
+					buf.add(line);
+					buf.addChar("\n".code);
+			}
+		}
+		var s = buf.toString().trim();
+		if (hasError || s == "") {
+			throw new HaxeInvocationException(s, fieldName, args, source.content);
 		}
-		return s;
+		return s.toString();
 	}
 
 	static function extractType(result:String) {