فهرست منبع

[test] Modified RunCi such that it is easier to be run on local machines. Briefly documented it in README.md.

Andy Li 10 سال پیش
والد
کامیت
5169e0abf5
3فایلهای تغییر یافته به همراه99 افزوده شده و 39 حذف شده
  1. 24 0
      tests/README.md
  2. 75 32
      tests/RunCi.hx
  3. 0 7
      tests/unit/README.md

+ 24 - 0
tests/README.md

@@ -0,0 +1,24 @@
+# Tests
+
+We have a number of test suites, which are placed in their own folders in this directory.
+
+"RunCi.hx" is the script used by our CIs to run all the test suites. It is possible to run it in local machines too:
+
+ 1. Change to this directory.
+ 2. Install lib used by the script: `haxelib git hx-yaml https://github.com/mikestead/hx-yaml master src`.
+ 3. Compile the script: `haxe -neko RunCi.n -main RunCi -lib hx-yaml`.
+ 4. Define the test target by 'export TEST=$TARGET', where "$TARGET" should be one of `macro`, `neko`, `js`, `php`, `cpp`, `flash9`, `as3`, `java`, `cs`, `python`, or `third-party`. However, `flash9`, `as3`, and `third-party` are not likely to work on local machines (TODO).
+ 5. Run it: `neko RunCi.n`.
+
+Note that the script will try to look for test dependencies and install them if they are not found. Look at the `getXXXDependencies` functions for the details.
+
+## Unit tests
+
+The "unit" folder contains a set of unit tests for the Haxe std library. Unit tests can be run separately instead of using "RunCi.hx", which runs all test suites.
+
+Assuming all test dependencies has been installed, we compile and run the unit tests for all targets at once as follows:
+
+ 1. Change to the "unit" directory.
+ 2. Compile: `haxe compile.hxml`.
+ 3. Start a dev server: `nekotools server`.
+ 4. Open `http://localhost:2000/unit.html` in your browser.

+ 75 - 32
tests/RunCi.hx

@@ -43,7 +43,7 @@ enum Ci {
 
 	AppVeyor:
 	Setting file: "appveyor.yml".
-	Build result: https://ci.appveyor.com/project/Simn/haxe
+	Build result: https://ci.appveyor.com/project/HaxeFoundation/haxe
 */
 class RunCi {
 	static function successMsg(msg:String):Void {
@@ -93,7 +93,7 @@ class RunCi {
 		var name:String = (altName == null) ? repository : altName;
 		try {
 			getHaxelibPath(name);
-			infoMsg('Warning: $name has already been installed.');
+			infoMsg('$name has already been installed.');
 		} catch (e:Dynamic) {
 			var args:Array<String> = ["git", name, 'https://github.com/$account/$repository'];
 			if (branch != null) {
@@ -110,7 +110,7 @@ class RunCi {
 	static function haxelibInstall(library:String):Void {
 		try {
 			getHaxelibPath(library);
-			infoMsg('Warning: $library has already been installed.');
+			infoMsg('$library has already been installed.');
 		} catch (e:Dynamic) {
 			runCommand("haxelib", ["install", library]);
 		}
@@ -290,11 +290,21 @@ class RunCi {
 		}
 	}
 
+	static function commandSucceed(cmd:String, args:Array<String>):Bool {
+		return try {
+			new Process(cmd, args).exitCode() == 0;
+		} catch(e:Dynamic) false;
+	}
+
 	static function getPhpDependencies() {
 		switch (systemName) {
 			case "Linux":
-				runCommand("sudo", ["apt-get", "install", "php5", "-qq"], true);
-				runCommand("sudo", ["apt-get", "install", "php5-mysql", "php5-sqlite", "-qq"], true);
+				if (commandSucceed("php", ["-v"])) {
+					infoMsg('php has already been installed.');
+				} else {
+					runCommand("sudo", ["apt-get", "install", "php5", "-qq"], true);
+					runCommand("sudo", ["apt-get", "install", "php5-mysql", "php5-sqlite", "-qq"], true);
+				}
 			case "Mac":
 				//pass
 		}
@@ -315,13 +325,18 @@ class RunCi {
 
 
 		//install and build hxcpp
-		haxelibInstallGit("HaxeFoundation", "hxcpp", true);
-		var oldDir = Sys.getCwd();
-		changeDirectory(Sys.getEnv("HOME") + "/haxelib/hxcpp/git/tools/hxcpp/");
-		runCommand("haxe", ["compile.hxml"]);
-		changeDirectory(Sys.getEnv("HOME") + "/haxelib/hxcpp/git/project/");
-		runCommand("neko", ["build.n"]);
-		changeDirectory(oldDir);
+		try {
+			getHaxelibPath("hxcpp");
+			infoMsg('hxcpp has already been installed.');
+		} catch(e:Dynamic) {
+			haxelibInstallGit("HaxeFoundation", "hxcpp", true);
+			var oldDir = Sys.getCwd();
+			changeDirectory(Sys.getEnv("HOME") + "/haxelib/hxcpp/git/tools/hxcpp/");
+			runCommand("haxe", ["compile.hxml"]);
+			changeDirectory(Sys.getEnv("HOME") + "/haxelib/hxcpp/git/project/");
+			runCommand("neko", ["build.n"]);
+			changeDirectory(oldDir);
+		}
 
 		gotCppDependencies = true;
 	}
@@ -335,7 +350,11 @@ class RunCi {
 	static function getJSDependencies() {
 		switch (systemName) {
 			case "Linux":
-				runCommand("sudo", ["apt-get", "install", "nodejs", "-qq"], true);
+				if (commandSucceed("node", ["-v"])) {
+					infoMsg('node has already been installed.');
+				} else {
+					runCommand("sudo", ["apt-get", "install", "nodejs", "-qq"], true);
+				}
 			case "Mac":
 				//pass
 		}
@@ -346,10 +365,16 @@ class RunCi {
 	static function getCsDependencies() {
 		switch (systemName) {
 			case "Linux":
-				runCommand("sudo", ["apt-get", "install", "mono-devel", "mono-mcs", "-qq"], true);
+				if (commandSucceed("mono", ["--version"]))
+					infoMsg('mono has already been installed.');
+				else
+					runCommand("sudo", ["apt-get", "install", "mono-devel", "mono-mcs", "-qq"], true);
 				runCommand("mono", ["--version"]);
 			case "Mac":
-				runCommand("brew", ["install", "mono"], true);
+				if (commandSucceed("mono", ["--version"]))
+					infoMsg('mono has already been installed.');
+				else
+					runCommand("brew", ["install", "mono"], true);
 				runCommand("mono", ["--version"]);
 			case "Windows":
 				//pass
@@ -391,21 +416,35 @@ class RunCi {
 	static function getPythonDependencies():Array<String> {
 		switch (systemName) {
 			case "Linux":
-				runCommand("sudo", ["apt-get", "install", "python3", "-qq"], true);
+				if (commandSucceed("python3", ["-V"]))
+					infoMsg('python3 has already been installed.');
+				else
+					runCommand("sudo", ["apt-get", "install", "python3", "-qq"], true);
 				runCommand("python3", ["-V"]);
 
-				var pypyVersion = "pypy3-2.4.0-linux64";
-				runCommand("wget", ['https://bitbucket.org/pypy/pypy/downloads/${pypyVersion}.tar.bz2'], true);
-				runCommand("tar", ["-xf", '${pypyVersion}.tar.bz2']);
-				var pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
+				var pypy = "pypy3";
+				if (commandSucceed(pypy, ["-V"])) {
+					infoMsg('pypy3 has already been installed.');
+				} else {
+					var pypyVersion = "pypy3-2.4.0-linux64";
+					runCommand("wget", ['https://bitbucket.org/pypy/pypy/downloads/${pypyVersion}.tar.bz2'], true);
+					runCommand("tar", ["-xf", '${pypyVersion}.tar.bz2']);
+					pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
+				}
 				runCommand(pypy, ["-V"]);
 
 				return ["python3", pypy];
 			case "Mac":
-				runCommand("brew", ["install", "python3"], true);
+				if (commandSucceed("python3", ["-V"]))
+					infoMsg('python3 has already been installed.');
+				else
+					runCommand("brew", ["install", "python3"], true);
 				runCommand("python3", ["-V"]);
 
-				runCommand("brew", ["install", "pypy3"], true);
+				if (commandSucceed("pypy3", ["-V"]))
+					infoMsg('pypy3 has already been installed.');
+				else
+					runCommand("brew", ["install", "pypy3"], true);
 				runCommand("pypy3", ["-V"]);
 
 				return ["python3", "pypy3"];
@@ -650,16 +689,20 @@ class RunCi {
 					setupFlashPlayerDebugger();
 
 					//setup flex sdk
-					var flexVersion = "4.14.0";
-					runCommand("wget", ['http://archive.apache.org/dist/flex/${flexVersion}/binaries/apache-flex-sdk-${flexVersion}-bin.tar.gz'], true);
-					runCommand("tar", ["-xf", 'apache-flex-sdk-${flexVersion}-bin.tar.gz', "-C", Sys.getEnv("HOME")]);
-					var flexsdkPath = Sys.getEnv("HOME") + '/apache-flex-sdk-${flexVersion}-bin';
-					Sys.putEnv("PATH", Sys.getEnv("PATH") + ":" + flexsdkPath + "/bin");
-					var playerglobalswcFolder = flexsdkPath + "/player";
-					FileSystem.createDirectory(playerglobalswcFolder + "/11.1");
-					runCommand("wget", ["-nv", "http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc", "-O", playerglobalswcFolder + "/11.1/playerglobal.swc"], true);
-					File.saveContent(flexsdkPath + "/env.properties", 'env.PLAYERGLOBAL_HOME=$playerglobalswcFolder');
-					runCommand("mxmlc", ["--version"]);
+					if (commandSucceed("mxmlc", ["--version"])) {
+						infoMsg('mxmlc has already been installed.');
+					} else {
+						var flexVersion = "4.14.0";
+						runCommand("wget", ['http://archive.apache.org/dist/flex/${flexVersion}/binaries/apache-flex-sdk-${flexVersion}-bin.tar.gz'], true);
+						runCommand("tar", ["-xf", 'apache-flex-sdk-${flexVersion}-bin.tar.gz', "-C", Sys.getEnv("HOME")]);
+						var flexsdkPath = Sys.getEnv("HOME") + '/apache-flex-sdk-${flexVersion}-bin';
+						Sys.putEnv("PATH", Sys.getEnv("PATH") + ":" + flexsdkPath + "/bin");
+						var playerglobalswcFolder = flexsdkPath + "/player";
+						FileSystem.createDirectory(playerglobalswcFolder + "/11.1");
+						runCommand("wget", ["-nv", "http://download.macromedia.com/get/flashplayer/updaters/11/playerglobal11_1.swc", "-O", playerglobalswcFolder + "/11.1/playerglobal.swc"], true);
+						File.saveContent(flexsdkPath + "/env.properties", 'env.PLAYERGLOBAL_HOME=$playerglobalswcFolder');
+						runCommand("mxmlc", ["--version"]);
+					}
 
 					runCommand("haxe", ["compile-as3.hxml", "-D", "fdb"]);
 					runFlash("bin/unit9_as3.swf");

+ 0 - 7
tests/unit/README.md

@@ -1,7 +0,0 @@
-# Unit test
-
-Here in this folder is a set of tests for the Haxe compiler. To compile and run the tests:
-
- 1. `haxe compile.hxml`
- 2. `nekotools server`
- 3. open `http://localhost:2000/unit.html` in your browser