Browse Source

[tests] Support checking compiler stderr output

Dan Korostelev 11 năm trước cách đây
mục cha
commit
bc1b174182
1 tập tin đã thay đổi với 37 bổ sung3 xóa
  1. 37 3
      tests/misc/src/Main.hx

+ 37 - 3
tests/misc/src/Main.hx

@@ -1,4 +1,5 @@
 import sys.FileSystem;
 import sys.FileSystem;
+import sys.io.File;
 import haxe.io.Path;
 import haxe.io.Path;
 import haxe.macro.Expr;
 import haxe.macro.Expr;
 
 
@@ -30,7 +31,8 @@ class Main {
 					Sys.setCwd(dirPath);
 					Sys.setCwd(dirPath);
 					Sys.println('Running haxe $path');
 					Sys.println('Running haxe $path');
 					var expectFailure = file.endsWith("-fail.hxml");
 					var expectFailure = file.endsWith("-fail.hxml");
-					var success = runCommand("haxe", [file], expectFailure);
+					var expectStderr = if (FileSystem.exists('$file.stderr')) prepareExpectedOutput(File.getContent('$file.stderr')) else null;
+					var success = runCommand("haxe", [file], expectFailure, expectStderr);
 					++count;
 					++count;
 					if (!success) {
 					if (!success) {
 						failures++;
 						failures++;
@@ -48,11 +50,28 @@ class Main {
 		};
 		};
 	}
 	}
 
 
-	static function runCommand(command:String, args:Array<String>, expectFailure:Bool) {
+	static function prepareExpectedOutput(s:String):String {
+		s = s.replace("\r\n", "\n"); // get rid of windows newlines
+
+		var cwd = Path.removeTrailingSlashes(FileSystem.fullPath(Sys.getCwd()));
+
+		var context = {cwd: cwd};
+		var macros = {normPath: normPath};
+
+		return new haxe.Template(s).execute(context, macros);
+	}
+
+	static function normPath(resolve, p:String):String {
+		if (Sys.systemName() == "Windows")
+			p = p.replace("/", "\\");
+		return p.toLowerCase();
+	}
+
+	static function runCommand(command:String, args:Array<String>, expectFailure:Bool, expectStderr:String) {
 		var proc = new sys.io.Process(command, args);
 		var proc = new sys.io.Process(command, args);
 		var exit = proc.exitCode();
 		var exit = proc.exitCode();
 		var success = exit == 0;
 		var success = exit == 0;
-		return switch [success, expectFailure] {
+		var result = switch [success, expectFailure] {
 			case [true, false]:
 			case [true, false]:
 				true;
 				true;
 			case [true, true]:
 			case [true, true]:
@@ -65,5 +84,20 @@ class Main {
 				Sys.print(stderr);
 				Sys.print(stderr);
 				false;
 				false;
 		}
 		}
+
+		if (result && expectStderr != null)
+		{
+			var stderr = proc.stderr.readAll().toString().replace("\r\n", "\n");
+			if (stderr != expectStderr)
+			{
+				Sys.println("Actual stderr output doesn't match the expected one");
+				Sys.println('Expected:\n"$expectStderr"');
+				Sys.println('Actual:\n"$stderr"');
+				result = false;
+			}
+		}
+
+		return result;
+
 	}
 	}
 }
 }