2
0
Эх сурвалжийг харах

Merge pull request #2391 from andyli/travis

TravisCI: run neko/macro/php/cpp tests
Simon Krajewski 11 жил өмнө
parent
commit
a0f83a3466
3 өөрчлөгдсөн 103 нэмэгдсэн , 10 устгасан
  1. 17 0
      .travis.yml
  2. 45 0
      tests/unit/RunTravis.hx
  3. 41 10
      tests/unit/Test.hx

+ 17 - 0
.travis.yml

@@ -1,5 +1,21 @@
 language: node_js
 
+env:
+  - TARGET=neko
+  - TARGET=macro
+  - TARGET=php
+  - TARGET=cpp
+  # - TARGET=flash8
+  # - TARGET=flash9
+  # - TARGET=js
+  # - TARGET=as3
+  # - TARGET=java
+  # - TARGET=cs
+
+matrix:
+  allow_failures:
+    - env: TARGET=php
+
 before_install:
   - sudo apt-get install ocaml zlib1g-dev libgc-dev -y
   - git clone https://github.com/HaxeFoundation/neko.git ~/neko && cd ~/neko && make && sudo make install && cd $TRAVIS_BUILD_DIR
@@ -11,3 +27,4 @@ script:
   - cd tests/unit/
   - mkdir ~/haxelib && haxelib setup ~/haxelib
   - haxe -version
+  - haxe -main RunTravis --interp

+ 45 - 0
tests/unit/RunTravis.hx

@@ -0,0 +1,45 @@
+import sys.io.Process;
+
+class RunTravis {
+	static function runProcess(cmd:String, args:Array<String>):Void {
+		var p = new Process(cmd, args);
+		Sys.println(p.stdout.readAll().toString());
+		Sys.println(p.stderr.readAll().toString());
+
+		var exitCode = p.exitCode();
+		Sys.println('Process exited with $exitCode: $cmd $args');
+
+		if (exitCode != 0) {
+			Sys.exit(1);
+		}
+	}
+
+	static function main():Void {
+		var cwd = Sys.getCwd();
+		switch (Sys.getEnv("TARGET")) {
+			case "macro":
+				runProcess("haxe", ["compile-macro.hxml"]);
+			case "neko":
+				runProcess("haxe", ["compile-neko.hxml"]);
+				runProcess("neko", ["unit.n"]);
+			case "php":
+				runProcess("sudo", ["apt-get", "install", "php5", "-y"]);
+				runProcess("haxe", ["compile-php.hxml"]);
+				runProcess("php", ["php/index.php"]);
+			case "cpp":
+				//hxcpp dependencies
+				runProcess("sudo", ["apt-get", "install", "gcc-multilib", "g++-multilib", "-y"]);
+
+				//install and build hxcpp
+				runProcess("haxelib", ["git", "hxcpp", "https://github.com/HaxeFoundation/hxcpp.git"]);
+				Sys.setCwd(Sys.getEnv("HOME") + "/haxelib/hxcpp/git/runtime/");
+				runProcess("haxelib", ["run", "hxcpp", "BuildLibs.xml"]);
+				Sys.setCwd(cwd);
+				
+				runProcess("haxe", ["compile-cpp.hxml"]);
+				runProcess("./cpp/Test-debug", []);
+			case target:
+				throw "unknown target: " + target;
+		}
+	}
+}

+ 41 - 10
tests/unit/Test.hx

@@ -12,15 +12,20 @@ class Test #if swf_mark implements mt.Protect #end {
 
 	function eq<T>( v : T, v2 : T, ?pos ) {
 		count++;
-		if( v != v2 ) report(Std.string(v)+" should be "+Std.string(v2),pos);
+		if( v != v2 ) {
+			report(Std.string(v)+" should be "+Std.string(v2),pos);
+			success = false;
+		}
 	}
 
 	function feq( v : Float, v2 : Float, ?pos ) {
 		count++;
 		if (!Math.isFinite(v) || !Math.isFinite(v2))
 			eq(v, v2, pos);
-		else if ( Math.abs(v - v2) > 1e-15 )
+		else if ( Math.abs(v - v2) > 1e-15 ) {
 			report(v+" should be "+v2,pos);
+			success = false;
+		}
 	}
 
 	function t( v, ?pos ) {
@@ -40,6 +45,7 @@ class Test #if swf_mark implements mt.Protect #end {
 		try {
 			f();
 			report("No exception occured",pos);
+			success = false;
 		} catch( e : Dynamic ) {
 		}
 	}
@@ -58,30 +64,39 @@ class Test #if swf_mark implements mt.Protect #end {
 			if( v == v2 )
 				return;
 		report(v+" not in "+Std.string(values),pos);
+		success = false;
 	}
 
 	function hf(c:Class<Dynamic>, n:String, ?pos:haxe.PosInfos) {
 		Test.count++;
-		if (!Lambda.has(Type.getInstanceFields(c), n))
+		if (!Lambda.has(Type.getInstanceFields(c), n)) {
 			Test.report(Type.getClassName(c) + " should have member field " +n, pos);
+			success = false;
+		}
 	}
 
 	function nhf(c:Class<Dynamic>, n:String, ?pos:haxe.PosInfos) {
 		Test.count++;
-		if (Lambda.has(Type.getInstanceFields(c), n))
+		if (Lambda.has(Type.getInstanceFields(c), n)) {
 			Test.report(Type.getClassName(c) + " should not have member field " +n, pos);
+			success = false;
+		}
 	}
 
 	function hsf(c:Class<Dynamic> , n:String, ?pos:haxe.PosInfos) {
 		Test.count++;
-		if (!Lambda.has(Type.getClassFields(c), n))
+		if (!Lambda.has(Type.getClassFields(c), n)) {
 			Test.report(Type.getClassName(c) + " should have static field " +n, pos);
+			success = false;
+		}
 	}
 
 	function nhsf(c:Class<Dynamic> , n:String, ?pos:haxe.PosInfos) {
 		Test.count++;
-		if (Lambda.has(Type.getClassFields(c), n))
+		if (Lambda.has(Type.getClassFields(c), n)) {
 			Test.report(Type.getClassName(c) + " should not have static field " +n, pos);
+			success = false;
+		}
 	}
 
 	function infos( m : String ) {
@@ -98,10 +113,13 @@ class Test #if swf_mark implements mt.Protect #end {
 			count++;
 			if( !asyncWaits.remove(pos) ) {
 				report("Double async result",pos);
+				success = false;
 				return;
 			}
-			if( v != v2 )
+			if( v != v2 ) {
 				report(v2+" should be "+v,pos);
+				success = false;
+			}
 			checkDone();
 		});
 	}
@@ -116,16 +134,21 @@ class Test #if swf_mark implements mt.Protect #end {
 			count++;
 			if( asyncWaits.remove(pos) )
 				checkDone();
-			else
+			else {
 				report("Multiple async events",pos);
+				success = false;
+			}
 		});
 		f(args,function(v) {
 			count++;
 			if( asyncWaits.remove(pos) ) {
 				report("No exception occured",pos);
+				success = false;
 				checkDone();
-			} else
+			} else {
 				report("Multiple async events",pos);
+				success = false;
+			}
 		});
 	}
 
@@ -141,6 +164,7 @@ class Test #if swf_mark implements mt.Protect #end {
 	static var asyncCache = new Array<Void -> Void>();
 	static var AMAX = 3;
 	static var timer : haxe.Timer;
+	static var success = true;
 
 	dynamic static function report( msg : String, ?pos : haxe.PosInfos ) {
 		if( reportInfos != null ) {
@@ -171,8 +195,10 @@ class Test #if swf_mark implements mt.Protect #end {
 	static function asyncTimeout() {
 		if( asyncWaits.length == 0 )
 			return;
-		for( pos in asyncWaits )
+		for( pos in asyncWaits ) {
 			report("TIMEOUT",pos);
+			success = false;
+		}
 		asyncWaits = new Array();
 		checkDone();
 	}
@@ -196,6 +222,7 @@ class Test #if swf_mark implements mt.Protect #end {
 		try msg = Std.string(e) catch( e : Dynamic ) {};
 		reportCount = 0;
 		report("ABORTED : "+msg+" in "+context);
+		success = false;
 		reportInfos = null;
 		trace("STACK :\n"+stack);
 	}
@@ -298,6 +325,10 @@ class Test #if swf_mark implements mt.Protect #end {
 			onError(e,"ABORTED",Type.getClassName(current));
 		}
 		#end
+
+		#if sys
+		Sys.exit(success ? 0 : 1);
+		#end
 	}
 
 }