Ver código fonte

[CI] Enable sys tests for NodeJS (#10437)

* [CI] Add sys tests for nodejs

* Update hxml for running sys test locally

* [CI] Enable an ignored nodejs sys test case

* [CI] Disable `File.append()` hxnodejs test on Mac
tobil4sk 4 anos atrás
pai
commit
359beb001e

+ 5 - 0
tests/runci/targets/Js.hx

@@ -110,6 +110,11 @@ class Js {
 		runCommand("haxe", ["build.hxml"]);
 		runCommand("haxe", ["build.hxml"]);
 		runCommand("node", ["test.js"]);
 		runCommand("node", ["test.js"]);
 
 
+		changeDirectory(sysDir);
+		runCommand("npm", ["install", "deasync"], true);
+		runCommand("haxe", ["compile-js.hxml"].concat(args));
+		runCommand("node", ["bin/js/sys.js"]);
+
 		changeDirectory(miscJsDir);
 		changeDirectory(miscJsDir);
 		runCommand("haxe", ["run.hxml"]);
 		runCommand("haxe", ["run.hxml"]);
 	}
 	}

+ 3 - 0
tests/sys/.gitignore

@@ -0,0 +1,3 @@
+node_modules
+package.json
+package-lock.json

+ 22 - 0
tests/sys/compile-js.hxml

@@ -0,0 +1,22 @@
+compile-each.hxml
+--main Main
+-js bin/js/sys.js
+-lib hxnodejs
+
+--next
+compile-each.hxml
+--main TestArguments
+-js bin/js/TestArguments.js
+-lib hxnodejs
+
+--next
+compile-each.hxml
+--main ExitCode
+-js bin/js/ExitCode.js
+-lib hxnodejs
+
+--next
+compile-each.hxml
+--main UtilityProcess
+-js bin/js/UtilityProcess.js
+-lib hxnodejs

+ 1 - 0
tests/sys/compile.hxml

@@ -8,3 +8,4 @@
 --next compile-java.hxml
 --next compile-java.hxml
 --next compile-php.hxml
 --next compile-php.hxml
 --next compile-hl.hxml
 --next compile-hl.hxml
+--next compile-js.hxml

+ 2 - 1
tests/sys/genTestRes.py

@@ -87,7 +87,8 @@ for data in allFilenames:
       ("../../bin/neko/UtilityProcess.n", "bin-neko"),
       ("../../bin/neko/UtilityProcess.n", "bin-neko"),
       ("../../bin/php/UtilityProcess/index.php", "bin-php"),
       ("../../bin/php/UtilityProcess/index.php", "bin-php"),
       ("../../bin/python/UtilityProcess.py", "bin-py"),
       ("../../bin/python/UtilityProcess.py", "bin-py"),
-      ("../../src/UtilityProcess.hx", "bin-eval")
+      ("../../src/UtilityProcess.hx", "bin-eval"),
+      ("../../bin/js/UtilityProcess.js", "bin-js")
     ]:
     ]:
       os.symlink(target, os.path.join(TESTDIR, data, name), target_is_directory = False)
       os.symlink(target, os.path.join(TESTDIR, data, name), target_is_directory = False)
 
 

+ 23 - 14
tests/sys/run.hxml

@@ -3,26 +3,35 @@
 # Compile everything first.
 # Compile everything first.
 compile.hxml
 compile.hxml
 
 
+# Install Dependencies
+# --next
+# --cmd luarocks install haxe-deps 0.0.1-6
+# --cmd npm install deasync
+
 # Mac/Linux
 # Mac/Linux
 --next
 --next
--cmd echo Neko   && neko bin/neko/sys.n
--cmd echo Python && python3 bin/python/sys.py
--cmd echo Cpp    && bin/cpp/Main-debug
--cmd echo CS     && mono bin/cs/bin/Main-Debug.exe
--cmd echo Java   && java -jar bin/java/Main-Debug.jar
--cmd echo Php    && php bin/php/Main/index.php
+--cmd echo Neko   && neko bin/neko/sys.n
+--cmd echo Python && python3 bin/python/sys.py
+--cmd echo Cpp    && bin/cpp/Main-debug
+--cmd echo CS     && mono bin/cs/bin/Main-Debug.exe
+--cmd echo Java   && java -jar bin/java/Main-Debug.jar
+--cmd echo Php    && php bin/php/Main/index.php
+--cmd echo Hl     && hl bin/hl/sys.hl
+--cmd echo Js     && node bin/js/sys.js
 
 
 # Windows
 # Windows
 # --next
 # --next
-# -cmd echo Neko   && neko bin\neko\sys.n
-# -cmd echo Python && python3 bin\python\sys.py
-# -cmd echo Cpp    && bin\cpp\Main-debug.exe
-# -cmd echo CS     && bin\cs\bin\Main-Debug.exe
-# -cmd echo Java   && java -jar bin\java\Main-Debug.jar
-# -cmd echo Php    && php bin\php\Main\index.php
+# --cmd echo Neko   && neko bin\neko\sys.n
+# --cmd echo Python && python3 bin\python\sys.py
+# --cmd echo Cpp    && bin\cpp\Main-debug.exe
+# --cmd echo CS     && bin\cs\bin\Main-Debug.exe
+# --cmd echo Java   && java -jar bin\java\Main-Debug.jar
+# --cmd echo Php    && php bin\php\Main\index.php
+# --cmd echo Hl     && hl bin/hl/sys.hl
+# --cmd echo Js     && node bin/js/sys.js
 
 
 # Macro has to be placed at the end since it would exit the compilation process.
 # Macro has to be placed at the end since it would exit the compilation process.
 --next
 --next
--cmd echo Macro
+--cmd echo Macro
 --next
 --next
-compile-macro.hxml
+compile-macro.hxml

+ 2 - 0
tests/sys/src/ExitCode.hx

@@ -39,6 +39,8 @@ class ExitCode {
 		"bin/php/ExitCode/index.php";
 		"bin/php/ExitCode/index.php";
 	#elseif lua
 	#elseif lua
 		"bin/lua/ExitCode.lua";
 		"bin/lua/ExitCode.lua";
+	#elseif js
+		"bin/js/ExitCode.js";
 	#else
 	#else
 		null;
 		null;
 	#end
 	#end

+ 3 - 1
tests/sys/src/Main.hx

@@ -10,8 +10,10 @@ class Main {
 		runner.addCase(new TestFileSystem());
 		runner.addCase(new TestFileSystem());
 		runner.addCase(new io.TestFile());
 		runner.addCase(new io.TestFile());
 		runner.addCase(new io.TestFileInput());
 		runner.addCase(new io.TestFileInput());
+		#if !js
 		runner.addCase(new io.TestProcess());
 		runner.addCase(new io.TestProcess());
-		#if !(java || cs || lua || python || eval) // Sqlite is not implemented for these targets
+		#end
+		#if !(java || cs || lua || python || eval || js) // Sqlite is not implemented for these targets
 		#if !hl // Idk how to resolve "FATAL ERROR : Failed to load library sqlite.hdll"
 		#if !hl // Idk how to resolve "FATAL ERROR : Failed to load library sqlite.hdll"
 		var testSqlite = #if php Sys.systemName() != 'Windows' #else true #end; //our CI doesn't have sqlite php module
 		var testSqlite = #if php Sys.systemName() != 'Windows' #else true #end; //our CI doesn't have sqlite php module
 		if(testSqlite) {
 		if(testSqlite) {

+ 2 - 0
tests/sys/src/TestArguments.hx

@@ -99,6 +99,8 @@ class TestArguments extends utest.Test {
 		"bin/php/TestArguments/index.php";
 		"bin/php/TestArguments/index.php";
 	#elseif lua
 	#elseif lua
 		"bin/lua/TestArguments.lua";
 		"bin/lua/TestArguments.lua";
+	#elseif js
+		"bin/js/TestArguments.js";
 	#else
 	#else
 		null;
 		null;
 	#end
 	#end

+ 4 - 0
tests/sys/src/TestCommandBase.hx

@@ -42,6 +42,8 @@ class TestCommandBase extends utest.Test {
 				run(php.Global.defined('PHP_BINARY') ? php.Const.PHP_BINARY : 'php', [bin].concat(args));
 				run(php.Global.defined('PHP_BINARY') ? php.Const.PHP_BINARY : 'php', [bin].concat(args));
 			#elseif lua
 			#elseif lua
 				run("lua", [bin].concat(args));
 				run("lua", [bin].concat(args));
+			#elseif js
+				run("node", [bin].concat(args));
 			#else
 			#else
 				-1;
 				-1;
 			#end
 			#end
@@ -133,6 +135,8 @@ class TestCommandBase extends utest.Test {
 					run(php.Global.defined('PHP_BINARY') ? php.Const.PHP_BINARY : 'php', [bin].concat(args));
 					run(php.Global.defined('PHP_BINARY') ? php.Const.PHP_BINARY : 'php', [bin].concat(args));
 				#elseif lua
 				#elseif lua
 					run("lua", [bin].concat(args));
 					run("lua", [bin].concat(args));
+				#elseif js
+					run("node", [bin].concat(args));
 				#else
 				#else
 					-1;
 					-1;
 				#end
 				#end

+ 2 - 3
tests/sys/src/TestFileSystem.hx

@@ -141,12 +141,11 @@ class TestFileSystem extends utest.Test {
 	}
 	}
 
 
 	static function normPath(p:String, properCase = false):String {
 	static function normPath(p:String, properCase = false):String {
-		if (Sys.systemName() == "Windows")
-		{
+		if (Sys.systemName() == "Windows") {
 			// on windows, haxe returns lowercase paths with backslashes, drive letter uppercased
 			// on windows, haxe returns lowercase paths with backslashes, drive letter uppercased
 			p = p.substr(0, 1).toUpperCase() + p.substr(1);
 			p = p.substr(0, 1).toUpperCase() + p.substr(1);
 			p = p.replace("/", "\\");
 			p = p.replace("/", "\\");
 		}
 		}
 		return p;
 		return p;
 	}
 	}
-}
+}

+ 14 - 7
tests/sys/src/TestUnicode.hx

@@ -42,6 +42,8 @@ class TestUnicode extends utest.Test {
 		"bin-py";
 		"bin-py";
 #elseif eval
 #elseif eval
 		"bin-eval";
 		"bin-eval";
+#elseif js
+		"bin-js";
 #else
 #else
 		null;
 		null;
 #end
 #end
@@ -389,13 +391,18 @@ class TestUnicode extends utest.Test {
 		assertBytesEqual(File.getBytes("temp-unicode/out.bin"), UnicodeSequences.validBytes);
 		assertBytesEqual(File.getBytes("temp-unicode/out.bin"), UnicodeSequences.validBytes);
 
 
 		// append
 		// append
-		var out = File.append("temp-unicode/out.bin");
-		out.writeString(UnicodeSequences.validString);
-		out.close();
-		var repeated = Bytes.alloc(UnicodeSequences.validBytes.length * 2);
-		repeated.blit(0, UnicodeSequences.validBytes, 0, UnicodeSequences.validBytes.length);
-		repeated.blit(UnicodeSequences.validBytes.length, UnicodeSequences.validBytes, 0, UnicodeSequences.validBytes.length);
-		assertBytesEqual(File.getBytes("temp-unicode/out.bin"), repeated);
+#if js
+		if (Sys.systemName() != "Mac") // File.append() here is broken on mac
+#end
+		{
+			var out = File.append("temp-unicode/out.bin");
+			out.writeString(UnicodeSequences.validString);
+			out.close();
+			var repeated = Bytes.alloc(UnicodeSequences.validBytes.length * 2);
+			repeated.blit(0, UnicodeSequences.validBytes, 0, UnicodeSequences.validBytes.length);
+			repeated.blit(UnicodeSequences.validBytes.length, UnicodeSequences.validBytes, 0, UnicodeSequences.validBytes.length);
+			assertBytesEqual(File.getBytes("temp-unicode/out.bin"), repeated);
+		}
 
 
 		// readLine
 		// readLine
 		var data = File.read("test-res/data.bin");
 		var data = File.read("test-res/data.bin");

+ 5 - 1
tests/sys/src/UtilityProcess.hx

@@ -28,6 +28,8 @@ class UtilityProcess {
 		Path.join(["bin", "python"]);
 		Path.join(["bin", "python"]);
 #elseif eval
 #elseif eval
 		Path.join(["src"]);
 		Path.join(["src"]);
+#elseif js
+		Path.join(["bin", "js"]);
 #else
 #else
 		null;
 		null;
 #end
 #end
@@ -64,6 +66,8 @@ class UtilityProcess {
 		"UtilityProcess.py";
 		"UtilityProcess.py";
 #elseif eval
 #elseif eval
 		"UtilityProcess.hx";
 		"UtilityProcess.hx";
+#elseif js
+		"UtilityProcess.js";
 #else
 #else
 		null;
 		null;
 #end
 #end
@@ -118,7 +122,7 @@ class UtilityProcess {
 			stderr: stderr
 			stderr: stderr
 		};
 		};
 	}
 	}
-	
+
 	public static function main():Void {
 	public static function main():Void {
 		var args = Sys.args();
 		var args = Sys.args();
 		function sequenceIndex(d:String, mode:String):String return (switch (UnicodeSequences.valid[Std.parseInt(d)]) {
 		function sequenceIndex(d:String, mode:String):String return (switch (UnicodeSequences.valid[Std.parseInt(d)]) {

+ 3 - 1
tests/sys/src/net/TestSocket.hx

@@ -19,9 +19,11 @@ class TestSocket extends utest.Test {
 		registeredSockets = [];
 		registeredSockets = [];
 	}
 	}
 
 
+	#if !js // bind is not implemented on nodejs
 	public function testBind() {
 	public function testBind() {
 		var socket = register(new Socket());
 		var socket = register(new Socket());
 		socket.bind(new Host('localhost'), 34567);
 		socket.bind(new Host('localhost'), 34567);
 		Assert.pass();
 		Assert.pass();
 	}
 	}
-}
+	#end
+}