Skip to content

Commit

Permalink
[test] sys test upgrade
Browse files Browse the repository at this point in the history
 * Test PHP
 * Decoupled sys test from RunCi, particularly RunCi doesn't have to pass the test arguments.
 * Added test cases for Sys.command, sys.io.Process, and Sys.exitCode
  • Loading branch information
andyli committed Mar 26, 2015
1 parent c025c3a commit 5e4b7f9
Show file tree
Hide file tree
Showing 22 changed files with 395 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -44,7 +44,7 @@ script:
- mkdir ~/haxelib && haxelib setup ~/haxelib
- haxelib git hx-yaml https://github.com/mikestead/hx-yaml master src
- haxe -version
- haxe -neko RunCi.n -main RunCi -lib hx-yaml
- haxe RunCi.hxml
- neko RunCi.n

branches:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -60,5 +60,5 @@ build_script:
test_script:
- cd %APPVEYOR_BUILD_FOLDER%/tests/
- haxe -version
- haxe -neko RunCi.n -main RunCi -lib hx-yaml
- haxe RunCi.hxml
- neko RunCi.n
13 changes: 11 additions & 2 deletions tests/README.md
Expand Up @@ -6,8 +6,8 @@ We have a number of test suites, which are placed in their own folders in this d

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).
3. Compile the script: `haxe RunCi.hxml`.
4. Define the test target by `export TEST=$TARGET` (or `set "TEST=$TARGET"` on Windows), 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.
Expand All @@ -22,3 +22,12 @@ Assuming all test dependencies has been installed, we compile and run the unit t
2. Compile: `haxe compile.hxml`.
3. Start a dev server: `nekotools server`.
4. Open `http://localhost:2000/unit.html` in your browser.

## Sys tests

The "sys" folder contains tests for the system targets. It can also be run separately instead of using "RunCi.hx".

Assuming all test dependencies has been installed, we compile and run the sys tests for all targets at once as follows:

1. Change to the "sys" directory.
2. If you're on Windows, comment out the relevant lines in "run.hxml". `haxe run.hxml`.
26 changes: 10 additions & 16 deletions tests/RunCi.hx
Expand Up @@ -477,11 +477,6 @@ class RunCi {
static function main():Void {
Sys.putEnv("OCAMLRUNPARAM", "b");

var args = [
for (arg in new haxe.xml.Fast(Xml.parse(File.getContent('$sysDir/args.xml'))).node.args.nodes.arg)
arg.innerData
];

var tests:Array<TEST> = switch (ci) {
case null:
[Sys.getEnv("TEST") == null ? Macro : Sys.getEnv("TEST")];
Expand Down Expand Up @@ -525,7 +520,7 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-macro.hxml"]);
runCommand("haxe", ["compile-each.hxml", "--run", "Main"].concat(args));
runCommand("haxe", ["compile-each.hxml", "--run", "Main"]);

//BYTECODE
switch (ci) {
Expand All @@ -549,12 +544,15 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-neko.hxml"]);
changeDirectory("bin/neko");
runCommand("neko", ["sys.n"].concat(args));
runCommand("neko", ["bin/neko/sys.n"]);
case Php:
getPhpDependencies();
runCommand("haxe", ["compile-php.hxml","-D","travis"]);
runCommand("php", ["bin/php/index.php"]);

changeDirectory(sysDir);
runCommand("haxe", ["compile-php.hxml"]);
runCommand("php", ["bin/php/Main/index.php"]);
case Python:
var pys = getPythonDependencies();

Expand All @@ -565,9 +563,8 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-python.hxml"]);
changeDirectory("bin/python");
for (py in pys) {
runCommand(py, ["sys.py"].concat(args));
runCommand(py, ["bin/python/sys.py"]);
}

changeDirectory(miscDir + "pythonImport");
Expand All @@ -591,8 +588,7 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-cpp.hxml"]);
changeDirectory("bin/cpp");
runCpp("Main-debug", args);
runCpp("bin/cpp/Main-debug", []);
case Js:
getJSDependencies();

Expand Down Expand Up @@ -636,8 +632,7 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-java.hxml"]);
changeDirectory("bin/java");
runCommand("java", ["-jar", "Main-Debug.jar"].concat(args));
runCommand("java", ["-jar", "bin/java/Main-Debug.jar"]);

infoMsg("Testing java-lib extras");
changeDirectory('$unitDir/bin');
Expand Down Expand Up @@ -684,8 +679,7 @@ class RunCi {

changeDirectory(sysDir);
runCommand("haxe", ["compile-cs.hxml"]);
changeDirectory("bin/cs");
runCs("bin/Main-Debug.exe", args);
runCs("bin/cs/bin/Main-Debug.exe", []);

changeDirectory(miscDir + "csTwoLibs");
for (i in 1...5)
Expand Down
3 changes: 3 additions & 0 deletions tests/RunCi.hxml
@@ -0,0 +1,3 @@
-neko RunCi.n
-main RunCi
-lib hx-yaml
2 changes: 2 additions & 0 deletions tests/sys/.gitignore
@@ -0,0 +1,2 @@
TestArguments.txt
testcase-test-file.txt
11 changes: 11 additions & 0 deletions tests/sys/compile-cpp.hxml
@@ -1,2 +1,13 @@
compile-each.hxml
-main Main
-cpp bin/cpp

--next
compile-each.hxml
-main TestArguments
-cpp bin/cpp

--next
compile-each.hxml
-main ExitCode
-cpp bin/cpp
11 changes: 11 additions & 0 deletions tests/sys/compile-cs.hxml
@@ -1,2 +1,13 @@
compile-each.hxml
-main Main
-cs bin/cs

--next
compile-each.hxml
-main TestArguments
-cs bin/cs

--next
compile-each.hxml
-main ExitCode
-cs bin/cs
3 changes: 1 addition & 2 deletions tests/sys/compile-each.hxml
@@ -1,4 +1,3 @@
-debug
-cp src
-resource args.xml
-main Main
-resource args.xml
11 changes: 11 additions & 0 deletions tests/sys/compile-java.hxml
@@ -1,2 +1,13 @@
compile-each.hxml
-main Main
-java bin/java

--next
compile-each.hxml
-main TestArguments
-java bin/java

--next
compile-each.hxml
-main ExitCode
-java bin/java
1 change: 1 addition & 0 deletions tests/sys/compile-macro.hxml
@@ -1,2 +1,3 @@
compile-each.hxml
-main Main
--interp
13 changes: 12 additions & 1 deletion tests/sys/compile-neko.hxml
@@ -1,2 +1,13 @@
compile-each.hxml
-neko bin/neko/sys.n
-main Main
-neko bin/neko/sys.n

--next
compile-each.hxml
-main TestArguments
-neko bin/neko/TestArguments.n

--next
compile-each.hxml
-main ExitCode
-neko bin/neko/ExitCode.n
13 changes: 13 additions & 0 deletions tests/sys/compile-php.hxml
@@ -0,0 +1,13 @@
compile-each.hxml
-main Main
-php bin/php/Main

--next
compile-each.hxml
-main TestArguments
-php bin/php/TestArguments

--next
compile-each.hxml
-main ExitCode
-php bin/php/ExitCode
13 changes: 12 additions & 1 deletion tests/sys/compile-python.hxml
@@ -1,2 +1,13 @@
compile-each.hxml
-python bin/python/sys.py
-main Main
-python bin/python/sys.py

--next
compile-each.hxml
-main TestArguments
-python bin/python/TestArguments.py

--next
compile-each.hxml
-main ExitCode
-python bin/python/ExitCode.py
3 changes: 3 additions & 0 deletions tests/sys/compile.hxml
@@ -1,3 +1,6 @@
# This is not run by CIs, just for convenience when testing manually.
# Note that compile-macro.hxml is not included.

--next compile-neko.hxml
--next compile-python.hxml
--next compile-cpp.hxml
Expand Down
28 changes: 28 additions & 0 deletions tests/sys/run.hxml
@@ -0,0 +1,28 @@
# This is not run by CIs, just for convenience when testing manually.

# Compile everything first.
compile.hxml

# Mac/Linux
--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

# Windows
# --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

# Macro has to be placed at the end since it would exit the compilation process.
--next
-cmd echo Macro
--next
compile-macro.hxml
37 changes: 37 additions & 0 deletions tests/sys/src/ExitCode.hx
@@ -0,0 +1,37 @@
/**
This is intented to be used by TestSys and io.TestProcess.
*/
class ExitCode {
static public var bin:String =
#if neko
"bin/neko/ExitCode.n";
#elseif cpp
#if debug
"bin/cpp/ExitCode-debug";
#else
"bin/cpp/ExitCode";
#end
#elseif cs
#if debug
"bin/cs/bin/ExitCode-Debug.exe";
#else
"bin/cs/bin/ExitCode.exe";
#end
#elseif java
#if debug
"bin/java/ExitCode-Debug.jar";
#else
"bin/java/ExitCode.jar";
#end
#elseif python
"bin/python/ExitCode.py";
#elseif php
"bin/php/ExitCode/index.php";
#else
null;
#end

static function main():Void {
Sys.exit(Std.parseInt(Sys.args()[0]));
}
}
1 change: 1 addition & 0 deletions tests/sys/src/Main.hx
Expand Up @@ -4,6 +4,7 @@ class Main {
runner.add(new TestSys());
runner.add(new TestFileSystem());
runner.add(new io.TestFileInput());
runner.add(new io.TestProcess());
var code = runner.run() ? 0 : 1;
Sys.exit(code);
}
Expand Down
63 changes: 63 additions & 0 deletions tests/sys/src/TestArguments.hx
@@ -0,0 +1,63 @@
/**
This test is intented to be used by TestSys and io.TestProcess.
*/
class TestArguments extends haxe.unit.TestCase {
static public var expectedArgs(get, null):Array<String>;
static function get_expectedArgs() {
return expectedArgs != null ? expectedArgs : expectedArgs = [
for (arg in new haxe.xml.Fast(Xml.parse(haxe.Resource.getString("args.xml"))).node.args.nodes.arg)
arg.innerData
];
}

static public var bin:String =
#if neko
"bin/neko/TestArguments.n";
#elseif cpp
#if debug
"bin/cpp/TestArguments-debug";
#else
"bin/cpp/TestArguments";
#end
#elseif cs
#if debug
"bin/cs/bin/TestArguments-Debug.exe";
#else
"bin/cs/bin/TestArguments.exe";
#end
#elseif java
#if debug
"bin/java/TestArguments-Debug.jar";
#else
"bin/java/TestArguments.jar";
#end
#elseif python
"bin/python/TestArguments.py";
#elseif php
"bin/php/TestArguments/index.php";
#else
null;
#end

function testArgs() {
var args = Sys.args();
// trace(args);
for (i in 0...expectedArgs.length) {
assertEquals(expectedArgs[i], args[i]);
}
assertEquals(expectedArgs.length, args.length);
}

static function main():Void {
var log = sys.io.File.write("TestArguments.txt");
haxe.unit.TestRunner.print = function(v){
log.writeString(v);
};
var runner = new haxe.unit.TestRunner();
runner.add(new TestArguments());
var code = runner.run() ? 0 : 1;
log.flush();
log.close();
Sys.exit(code);
}
}

1 comment on commit 5e4b7f9

@nadako
Copy link
Member

@nadako nadako commented on 5e4b7f9 Mar 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyli can we close #3411 and #3402 issues now that we have tests for Sys.command and argument escaping? I'm sure there are some issues with specific targets, but it's better to report and fix them separately as I don't really understand what should I do for #3411 and #3402

Please sign in to comment.