Forráskód Böngészése

Bring back spec tests (#8107)

* [tests] run spec tests again

* [tests] deal with some more "no assertions"
Simon Krajewski 6 éve
szülő
commit
3464afe2b4

+ 3 - 1
tests/unit/src/unit/TestMain.hx

@@ -74,7 +74,6 @@ class TestMain {
 			#if !no_pattern_matching
 			new TestMatch(),
 			#end
-			new TestSpecification(),
 			#if cs
 			new TestCSharp(),
 			#end
@@ -109,6 +108,9 @@ class TestMain {
 			//new TestRemoting(),
 		];
 
+		for (specClass in unit.UnitBuilder.generateSpec("src/unitstd")) {
+			classes.push(specClass);
+		}
 		TestIssues.addIssueClasses("src/unit/issues", "unit.issues");
 		TestIssues.addIssueClasses("src/unit/hxcpp_issues", "unit.hxcpp_issues");
 

+ 36 - 11
tests/unit/src/unit/UnitBuilder.hx

@@ -29,11 +29,11 @@ using StringTools;
 
 class UnitBuilder {
 
-	static public macro function build(basePath:String, filter:String = ".unit.hx"):Array<Field> {
-		var ret = Context.getBuildFields();
+	static public macro function generateSpec(basePath:String, filter:String = ".unit.hx") {
+		var ret = [];
 		var numFiles = 0;
 
-		function readDir(path) {
+		function readDir(path, pack:Array<String>) {
 			var dir = sys.FileSystem.readDirectory(path);
 			path = path.endsWith("\\") || path.endsWith("/") ? path : path + "/";
 			for (file in dir) {
@@ -46,22 +46,47 @@ class UnitBuilder {
 						params: [],
 						expr: read(filePath)
 					}
-					ret.push( {
-						name: "test" + ~/\./g.map(file, function(_) return "_"),
+					var p = Context.makePosition( { min:0, max:0, file:filePath + file } );
+					var field = {
+						name: "test",
 						kind: FFun(func),
-						pos: Context.makePosition( { min:0, max:0, file:filePath + file } ),
+						pos: p,
 						access: [APublic],
 						doc: null,
 						meta: []
-					});
+					};
+					var pack = ["unit", "spec"].concat(pack);
+					var typeName = "Test" + file.substr(0, file.indexOf("."));
+					Context.defineModule(pack.join(".") + "." + typeName, [{
+						pack: pack,
+						name: typeName,
+						pos: p,
+						kind: TDClass({
+							pack: ["unit"],
+							name: "Test"
+						}),
+						fields: [field]
+					}], [{
+						path: [{pos: p, name: "unit"}, {pos: p, name: "spec"}, {pos: p, name: "TestSpecification"}],
+						mode: INormal
+					}, {
+						// TODO: import.hx doesn't work for this?
+						path: [{pos: p, name: "haxe"}, {pos: p, name: "macro"}, {pos: p, name: "Expr"}],
+						mode: INormal
+					}]);
+					var tp:TypePath = {
+						pack: pack,
+						name: typeName
+					}
+					ret.push(macro new $tp());
 				} else if (sys.FileSystem.isDirectory(filePath)) {
-					readDir(filePath);
+					readDir(filePath, pack.concat([file]));
 				}
 			}
 		}
-		readDir(basePath);
-		//trace("Added " +numFiles + " .unit.hx files");
-		return ret;
+		readDir(basePath, []);
+		// trace("Added " +numFiles + " .unit.hx files");
+		return macro $a{ret};
 	}
 
 	#if macro

+ 13 - 23
tests/unit/src/unit/TestSpecification.hx → tests/unit/src/unit/spec/TestSpecification.hx

@@ -1,7 +1,4 @@
-package unit;
-
-import haxe.ds.List;
-import haxe.macro.Expr;
+package unit.spec;
 
 typedef T = {
 	function func():Void;
@@ -48,26 +45,26 @@ typedef T = {
 
 class CChild extends C { }
 
-private class EmptyClass {
+class EmptyClass {
 	public function new() { }
 }
 
-@:keep private class ReallyEmptyClass { }
+@:keep class ReallyEmptyClass { }
 
-private class ClassWithToString {
+class ClassWithToString {
 	public function new() { }
 	public function toString() return "ClassWithToString.toString()";
 }
 
-private class ClassWithToStringChild extends ClassWithToString {
+class ClassWithToStringChild extends ClassWithToString {
 
 }
 
-private class ClassWithToStringChild2 extends ClassWithToString {
+class ClassWithToStringChild2 extends ClassWithToString {
 	public override function toString() return "ClassWithToStringChild2.toString()";
 }
 
-@:keep private class ClassWithCtorDefaultValues {
+@:keep class ClassWithCtorDefaultValues {
 	public var a : Null<Int>;
 	public var b : String;
 	public function new(a = 1, b = "foo") {
@@ -76,11 +73,11 @@ private class ClassWithToStringChild2 extends ClassWithToString {
 	}
 }
 
-private class ClassWithCtorDefaultValuesChild extends ClassWithCtorDefaultValues {
+class ClassWithCtorDefaultValuesChild extends ClassWithCtorDefaultValues {
 
 }
 
-@:keep private class ClassWithCtorDefaultValues2 {
+@:keep class ClassWithCtorDefaultValues2 {
 	public var a : Null<Float>;
 	public var b : String;
 	public function new(a = 1.1, b = "foo") {
@@ -89,12 +86,12 @@ private class ClassWithCtorDefaultValuesChild extends ClassWithCtorDefaultValues
 	}
 }
 
-private enum SomeEnum<T> {
+enum SomeEnum<T> {
 	NoArguments;
 	OneArgument(t:T);
 }
 
-private class IntWrap {
+class IntWrap {
 	public var i(default, null):Int;
 
 	public function new(i:Int) {
@@ -108,7 +105,7 @@ private class IntWrap {
 	}
 }
 
-private enum E {
+enum E {
 	NoArgs;
 	OneArg(i:Int);
 	RecArg(e:E);
@@ -154,11 +151,4 @@ class RttiClass3 extends RttiClass1 {
 	override function f():Int {
 		return 33;
 	}
-}
-
-#if !macro
-@:build(unit.UnitBuilder.build("src/unitstd"))
-#end
-class TestSpecification extends Test {
-
-}
+}

+ 1 - 0
tests/unit/src/unit/spec/import.hx

@@ -0,0 +1 @@
+import haxe.macro.Expr;

+ 3 - 1
tests/unit/src/unitstd/Ssl.unit.hx

@@ -102,4 +102,6 @@ cert.issuer("O") == "Test Dev CA";
 var cert2 = cert.next();
 cert2.commonName == "localhost";
 
-#end
+#else
+1 == 1;
+#end

+ 0 - 3
tests/unit/src/unitstd/Sys.unit.hx

@@ -1,3 +0,0 @@
-#if sys
-
-#end

+ 2 - 2
tests/unit/src/unitstd/Type.unit.hx

@@ -25,7 +25,7 @@ Type.getSuperClass(ClassWithToStringChild) == ClassWithToString;
 
 // getClassName
 Type.getClassName(String) == "String";
-Type.getClassName(C) == "unit.C";
+Type.getClassName(C) == "unit.spec.C";
 //Type.getClassName(null) == null;
 Type.getClassName(Type.getClass([])) == "Array";
 
@@ -35,7 +35,7 @@ Type.getEnumName(haxe.macro.Expr.ExprDef) == "haxe.macro.ExprDef";
 
 // resolveClass
 Type.resolveClass("String") == String;
-Type.resolveClass("unit.C") == C;
+Type.resolveClass("unit.spec.C") == C;
 //Type.resolveClass("Float") == null;
 //Type.resolveClass(null) == null;
 Type.resolveClass("MyNonExistingClass") == null;

+ 2 - 0
tests/unit/src/unitstd/Unicode.unit.hx

@@ -295,4 +295,6 @@ test("()", "ä", "[]", ~/:(\w):/);
 test("a", "É", "b", ~/:(é):/i);
 test("a", "é", "b", ~/:(É):/i);
 
+#else
+1 == 1;
 #end

+ 3 - 1
tests/unit/src/unitstd/haxe/ds/WeakMap.unit.hx

@@ -84,4 +84,6 @@ a.length == 2;
 a[0] in ["9", "7"];
 a[1] in ["9", "7"];
 o.remove(k2) == false;
-#end
+#else
+1 == 1;
+#end

+ 2 - 0
tests/unit/src/unitstd/haxe/iterators/StringIteratorUnicode.unit.hx

@@ -11,4 +11,6 @@ function traverse(s:String) {
 traverse("abcde") == ["a".code, "b".code, "c".code, "d".code, "e".code];
 traverse("aa😂éé") == ["a".code, "a".code, "😂".code, "é".code, "é".code];
 
+#else
+1 == 1;
 #end

+ 3 - 0
tests/unit/src/unitstd/haxe/iterators/StringKeyValueIteratorUnicode.unit.hx

@@ -18,4 +18,7 @@ var r = traverse("aa😂éé");
 r.k == [0, 1, 2, 3, 4];
 r.v == ["a".code, "a".code, "😂".code, "é".code, "é".code];
 
+#else
+1 == 1;
+
 #end

+ 2 - 0
tests/unit/src/unitstd/haxe/macro/ComplexTypeTools.macro.unit.hx

@@ -2,4 +2,6 @@
 var tt = function(c) return Std.string(haxe.macro.ComplexTypeTools.toType(c));
 tt(macro : String) == "String";
 tt(macro : Int) == "String";
+#else
+1 == 1;
 #end

+ 2 - 2
tests/unit/src/unitstd/haxe/rtti/Rtti.unit.hx

@@ -46,7 +46,7 @@ cl.isExtern == false;
 cl.isInterface == false;
 cl.params == [];
 cl.fields.length == 0;
-cl.superClass.path == "unit.RttiClass1";
+cl.superClass.path == "unit.spec.RttiClass1";
 cl.superClass.params.length == 0;
 cl.interfaces.length == 0;
 cl.fields.length == 0;
@@ -58,7 +58,7 @@ cl.isExtern == false;
 cl.isInterface == false;
 cl.params == [];
 cl.fields.length == 1;
-cl.superClass.path == "unit.RttiClass1";
+cl.superClass.path == "unit.spec.RttiClass1";
 cl.superClass.params.length == 0;
 cl.interfaces.length == 0;
 cl.fields.length == 1;

+ 2 - 0
tests/unit/src/unitstd/haxe/zip/Compress.unit.hx

@@ -49,4 +49,6 @@ c.get(4) == 0;
 c.get(5) == 0;
 c.get(6) == 0;
 c.get(7) == 1;
+#else
+1 == 1;
 #end

+ 3 - 1
tests/unit/src/unitstd/haxe/zip/Uncompress.unit.hx

@@ -27,4 +27,6 @@ r.done == true;
 r.read == 12;
 r.write == 4;
 c.toString() == "test";
-#end
+#else
+1 == 1;
+#end

+ 2 - 0
tests/unit/src/unitstd/sys/io/File.unit.hx

@@ -40,4 +40,6 @@ fu.close();
 sys.FileSystem.exists(filename) == true;
 
 sys.FileSystem.deleteFile(filename);
+#else
+1 == 1;
 #end

+ 3 - 1
tests/unit/src/unitstd/sys/net/Socket.unit.hx

@@ -57,4 +57,6 @@ c.read() == "abc";
 
 c.close();
 s.close();
-#end
+#else
+1 == 1;
+#end