From 55abb0d18bbab60de77cae2c59fde5e3e5cb9501 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 15:57:37 +0800 Subject: [PATCH 1/7] Try adding some tests --- .gitignore | 2 +- .travis.yml | 6 ++---- .vscode/tasks.json | 4 ++-- haxe_libraries/ansi.hxml | 3 +++ haxe_libraries/tink_chunk.hxml | 3 +++ haxe_libraries/tink_macro.hxml | 5 +++++ haxe_libraries/tink_priority.hxml | 3 +++ haxe_libraries/tink_streams.hxml | 6 ++++++ haxe_libraries/tink_syntaxhub.hxml | 6 ++++++ haxe_libraries/tink_testrunner.hxml | 7 +++++++ haxe_libraries/tink_unittest.hxml | 6 ++++++ haxe_libraries/travix.hxml | 3 +++ tests.hxml | 3 +++ tests/InstallTest.hx | 17 +++++++++++++++++ tests/ListTest.hx | 8 ++++++++ tests/RunTests.hx | 14 ++++++++++++++ tests/TestBase.hx | 18 ++++++++++++++++++ tests/UseTest.hx | 27 +++++++++++++++++++++++++++ tests/import.hx | 2 ++ 19 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 haxe_libraries/ansi.hxml create mode 100644 haxe_libraries/tink_chunk.hxml create mode 100644 haxe_libraries/tink_macro.hxml create mode 100644 haxe_libraries/tink_priority.hxml create mode 100644 haxe_libraries/tink_streams.hxml create mode 100644 haxe_libraries/tink_syntaxhub.hxml create mode 100644 haxe_libraries/tink_testrunner.hxml create mode 100644 haxe_libraries/tink_unittest.hxml create mode 100644 haxe_libraries/travix.hxml create mode 100644 tests.hxml create mode 100644 tests/InstallTest.hx create mode 100644 tests/ListTest.hx create mode 100644 tests/RunTests.hx create mode 100644 tests/TestBase.hx create mode 100644 tests/UseTest.hx create mode 100644 tests/import.hx diff --git a/.gitignore b/.gitignore index 8126980..ff49f08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/bin/switchx.js +/bin /node_modules diff --git a/.travis.yml b/.travis.yml index b454767..10d7afc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,10 @@ os: - linux install: - - npm install haxeshim -g - - npm install lix.pm -g + - npm install haxe-travix lix.pm haxeshim -g - lix download - haxe switchx.hxml - npm install . -g script: - - - switchx list \ No newline at end of file + - travix neko \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f1e8333..a78be59 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,6 @@ { - "version": "0.1.0", + "version": "2.0.0", "command": "haxe", - "args": ["switchx.hxml", "--next", "-cmd", "node bin/switchx.js list"], + "args": ["switchx.hxml", "--next", "-cmd", "travix neko"], "problemMatcher": "$haxe" } diff --git a/haxe_libraries/ansi.hxml b/haxe_libraries/ansi.hxml new file mode 100644 index 0000000..302023a --- /dev/null +++ b/haxe_libraries/ansi.hxml @@ -0,0 +1,3 @@ +# @install: lix --silent download 'haxelib:ansi#1.0.0' into ansi/1.0.0/haxelib +-D ansi=1.0.0 +-cp ${HAXESHIM_LIBCACHE}/ansi/1.0.0/haxelib/src diff --git a/haxe_libraries/tink_chunk.hxml b/haxe_libraries/tink_chunk.hxml new file mode 100644 index 0000000..6a976be --- /dev/null +++ b/haxe_libraries/tink_chunk.hxml @@ -0,0 +1,3 @@ +# @install: lix --silent download 'https://github.com/haxetink/tink_chunk/archive/85ca1bd1c5aa1666a46fc6f7fd1827c917e92e51.tar.gz' into tink_chunk/0.1.0/github/85ca1bd1c5aa1666a46fc6f7fd1827c917e92e51 +-D tink_chunk=0.1.0 +-cp ${HAXESHIM_LIBCACHE}/tink_chunk/0.1.0/github/85ca1bd1c5aa1666a46fc6f7fd1827c917e92e51/src diff --git a/haxe_libraries/tink_macro.hxml b/haxe_libraries/tink_macro.hxml new file mode 100644 index 0000000..1ebb005 --- /dev/null +++ b/haxe_libraries/tink_macro.hxml @@ -0,0 +1,5 @@ +# @install: lix --silent download 'haxelib:tink_macro#0.14.0' into tink_macro/0.14.0/haxelib +-D tink_macro=0.14.0 +-cp ${HAXESHIM_LIBCACHE}/tink_macro/0.14.0/haxelib/src + +-lib tink_core \ No newline at end of file diff --git a/haxe_libraries/tink_priority.hxml b/haxe_libraries/tink_priority.hxml new file mode 100644 index 0000000..c74caec --- /dev/null +++ b/haxe_libraries/tink_priority.hxml @@ -0,0 +1,3 @@ +# @install: lix --silent download 'haxelib:tink_priority#0.1.3' into tink_priority/0.1.3/haxelib +-D tink_priority=0.1.3 +-cp ${HAXESHIM_LIBCACHE}/tink_priority/0.1.3/haxelib/src diff --git a/haxe_libraries/tink_streams.hxml b/haxe_libraries/tink_streams.hxml new file mode 100644 index 0000000..f32ce0c --- /dev/null +++ b/haxe_libraries/tink_streams.hxml @@ -0,0 +1,6 @@ +# @install: lix --silent download 'https://github.com/haxetink/tink_streams/archive/f45067c82b80c4e9c0b215530ec3ddc0b24bf88d.tar.gz' into tink_streams/0.1.0/github/f45067c82b80c4e9c0b215530ec3ddc0b24bf88d +-D tink_streams=0.1.0 +-cp ${HAXESHIM_LIBCACHE}/tink_streams/0.1.0/github/f45067c82b80c4e9c0b215530ec3ddc0b24bf88d/src +# temp for development, delete this file when pure branch merged +-D pure +-lib tink_core \ No newline at end of file diff --git a/haxe_libraries/tink_syntaxhub.hxml b/haxe_libraries/tink_syntaxhub.hxml new file mode 100644 index 0000000..0825d72 --- /dev/null +++ b/haxe_libraries/tink_syntaxhub.hxml @@ -0,0 +1,6 @@ +# @install: lix --silent download 'haxelib:tink_syntaxhub#0.3.6' into tink_syntaxhub/0.3.6/haxelib +-D tink_syntaxhub=0.3.6 +-cp ${HAXESHIM_LIBCACHE}/tink_syntaxhub/0.3.6/haxelib/src +--macro tink.SyntaxHub.use() +-lib tink_priority +-lib tink_macro \ No newline at end of file diff --git a/haxe_libraries/tink_testrunner.hxml b/haxe_libraries/tink_testrunner.hxml new file mode 100644 index 0000000..a6c4702 --- /dev/null +++ b/haxe_libraries/tink_testrunner.hxml @@ -0,0 +1,7 @@ +# @install: lix --silent download 'haxelib:tink_testrunner#0.6.0' into tink_testrunner/0.6.0/haxelib +-D tink_testrunner=0.6.0 +-cp ${HAXESHIM_LIBCACHE}/tink_testrunner/0.6.0/haxelib/src + +-lib ansi +-lib tink_macro +-lib tink_streams \ No newline at end of file diff --git a/haxe_libraries/tink_unittest.hxml b/haxe_libraries/tink_unittest.hxml new file mode 100644 index 0000000..dd5d7e5 --- /dev/null +++ b/haxe_libraries/tink_unittest.hxml @@ -0,0 +1,6 @@ +# @install: lix --silent download 'https://github.com/haxetink/tink_unittest/archive/5936b2646b06833d9e5f1c6c90a19b9a6a063f31.tar.gz' into tink_unittest/0.5.2/github/5936b2646b06833d9e5f1c6c90a19b9a6a063f31 +-D tink_unittest=0.5.2 +-cp ${HAXESHIM_LIBCACHE}/tink_unittest/0.5.2/github/5936b2646b06833d9e5f1c6c90a19b9a6a063f31/src +--macro tink.unit.AssertionBufferInjector.use() +-lib tink_syntaxhub +-lib tink_testrunner \ No newline at end of file diff --git a/haxe_libraries/travix.hxml b/haxe_libraries/travix.hxml new file mode 100644 index 0000000..13c61c2 --- /dev/null +++ b/haxe_libraries/travix.hxml @@ -0,0 +1,3 @@ +# @install: lix --silent download 'haxelib:travix#0.9.0' into travix/0.9.0/haxelib +-D travix=0.9.0 +-cp ${HAXESHIM_LIBCACHE}/travix/0.9.0/haxelib/src diff --git a/tests.hxml b/tests.hxml new file mode 100644 index 0000000..3cd7a54 --- /dev/null +++ b/tests.hxml @@ -0,0 +1,3 @@ +-cp tests +-main RunTests +-lib tink_unittest \ No newline at end of file diff --git a/tests/InstallTest.hx b/tests/InstallTest.hx new file mode 100644 index 0000000..c7ed5a7 --- /dev/null +++ b/tests/InstallTest.hx @@ -0,0 +1,17 @@ +package; + +@:asserts +class InstallTest extends TestBase { + public function official() { + asserts.assert(switchx(['install', '3.4.0']).exitCode == 0); + + var list = switchx(['list']).stdout; + asserts.assert(contains(list, ['3.4.0', '3.4.2'])); + return asserts.done(); + } + + function contains(arr:String, v:Array) { + for(v in v) if(arr.indexOf(v) == -1) return false; + return true; + } +} \ No newline at end of file diff --git a/tests/ListTest.hx b/tests/ListTest.hx new file mode 100644 index 0000000..782c451 --- /dev/null +++ b/tests/ListTest.hx @@ -0,0 +1,8 @@ +package; + +class ListTest extends TestBase { + public function list() { + var proc = new Process('node', ['bin/switchx.js','list']); + return assert(switchx(['list']).exitCode == 0); + } +} \ No newline at end of file diff --git a/tests/RunTests.hx b/tests/RunTests.hx new file mode 100644 index 0000000..7a21f3d --- /dev/null +++ b/tests/RunTests.hx @@ -0,0 +1,14 @@ +package; + +import tink.testrunner.*; +import tink.unit.*; + +class RunTests { + static function main() { + Runner.run(TestBatch.make([ + new ListTest(), + new InstallTest(), + new UseTest(), + ])).handle(Runner.exit); + } +} \ No newline at end of file diff --git a/tests/TestBase.hx b/tests/TestBase.hx new file mode 100644 index 0000000..5d2b561 --- /dev/null +++ b/tests/TestBase.hx @@ -0,0 +1,18 @@ +package; + +class TestBase { + public function new() {} + + function switchx(args:Array) { + return run('node', ['bin/switchx.js'].concat(args)); + } + + function run(cmd, args) { + var proc = new Process(cmd, args); + return { + exitCode: proc.exitCode(), + stdout: proc.stdout.readAll().toString(), + stderr: proc.stderr.readAll().toString(), + } + } +} \ No newline at end of file diff --git a/tests/UseTest.hx b/tests/UseTest.hx new file mode 100644 index 0000000..c8715cd --- /dev/null +++ b/tests/UseTest.hx @@ -0,0 +1,27 @@ +package; + +using StringTools; + +@:asserts +class UseTest extends TestBase { + public function official() { + switchx(['install', '3.4.0']); + asserts.assert(switchx(['use', '3.4.0']).exitCode == 0); + asserts.assert(haxeVer() == '3.4.0'); + switchx(['install', '3.4.2']); + asserts.assert(switchx(['use', '3.4.2']).exitCode == 0); + asserts.assert(haxeVer() == '3.4.2'); + return asserts.done(); + } + + function contains(arr:String, v:Array) { + for(v in v) if(arr.indexOf(v) == -1) return false; + return true; + } + + function haxeVer() { + var proc = run('haxe', ['-version']); + var ver = proc.stdout + proc.stderr; // HACK: haxe prints to stderr?! + return ver.replace('\n', ''); + } +} \ No newline at end of file diff --git a/tests/import.hx b/tests/import.hx new file mode 100644 index 0000000..6b5d685 --- /dev/null +++ b/tests/import.hx @@ -0,0 +1,2 @@ +import tink.unit.Assert.assert; +import sys.io.Process; \ No newline at end of file From b27442eaef68c0e7d63a17f0b56a49a9d0f825c4 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 16:02:04 +0800 Subject: [PATCH 2/7] tell me why --- tests/TestBase.hx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/TestBase.hx b/tests/TestBase.hx index 5d2b561..e626750 100644 --- a/tests/TestBase.hx +++ b/tests/TestBase.hx @@ -9,10 +9,14 @@ class TestBase { function run(cmd, args) { var proc = new Process(cmd, args); + var stdout = proc.stdout.readAll().toString(); + var stderr = proc.stderr.readAll().toString(); + trace(stdout); + trace(stderr); return { exitCode: proc.exitCode(), - stdout: proc.stdout.readAll().toString(), - stderr: proc.stderr.readAll().toString(), + stdout: stdout, + stderr: stderr, } } } \ No newline at end of file From 9adc47389fc8fdef7ae9f4757c8f33bd92953814 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 16:07:17 +0800 Subject: [PATCH 3/7] install node dependencies --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 10d7afc..5f406e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ install: - lix download - haxe switchx.hxml - npm install . -g + - npm install script: - travix neko \ No newline at end of file From 30b9e1fe2f208af307d9e36748137da12e8785c8 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 16:16:57 +0800 Subject: [PATCH 4/7] Test nightly --- tests/TestBase.hx | 2 -- tests/UseTest.hx | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/TestBase.hx b/tests/TestBase.hx index e626750..8d67df7 100644 --- a/tests/TestBase.hx +++ b/tests/TestBase.hx @@ -11,8 +11,6 @@ class TestBase { var proc = new Process(cmd, args); var stdout = proc.stdout.readAll().toString(); var stderr = proc.stderr.readAll().toString(); - trace(stdout); - trace(stderr); return { exitCode: proc.exitCode(), stdout: stdout, diff --git a/tests/UseTest.hx b/tests/UseTest.hx index c8715cd..7e871fd 100644 --- a/tests/UseTest.hx +++ b/tests/UseTest.hx @@ -4,13 +4,22 @@ using StringTools; @:asserts class UseTest extends TestBase { - public function official() { - switchx(['install', '3.4.0']); - asserts.assert(switchx(['use', '3.4.0']).exitCode == 0); - asserts.assert(haxeVer() == '3.4.0'); - switchx(['install', '3.4.2']); - asserts.assert(switchx(['use', '3.4.2']).exitCode == 0); - asserts.assert(haxeVer() == '3.4.2'); + + @:variant('ada466c', '3.4.2') + @:variant('c294a69', '4.0.0') + public function nightly(sha:String, version:String) { + switchx(['install', sha]); + asserts.assert(switchx(['use', sha]).exitCode == 0); + asserts.assert(haxeVer() == '$version (git build development @ $sha)'); + return asserts.done(); + } + + @:variant('3.4.0') + @:variant('3.4.2') + public function official(version:String) { + switchx(['install', version]); + asserts.assert(switchx(['use', version]).exitCode == 0); + asserts.assert(haxeVer() == version); return asserts.done(); } From 2c3e216786986f02934cb64c83cc7507f185b966 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 16:39:37 +0800 Subject: [PATCH 5/7] scope tests --- .vscode/settings.json | 3 ++- tests/RunTests.hx | 1 + tests/ScopeTest.hx | 53 +++++++++++++++++++++++++++++++++++++++++++ tests/TestBase.hx | 28 ++++++++++++++++++++--- 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 tests/ScopeTest.hx diff --git a/.vscode/settings.json b/.vscode/settings.json index 5515484..829dcd5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "haxe.displayConfigurations": [ - ["switchx.hxml"] + ["switchx.hxml"], + ["tests.hxml"] ] } diff --git a/tests/RunTests.hx b/tests/RunTests.hx index 7a21f3d..a5ebd73 100644 --- a/tests/RunTests.hx +++ b/tests/RunTests.hx @@ -9,6 +9,7 @@ class RunTests { new ListTest(), new InstallTest(), new UseTest(), + new ScopeTest(), ])).handle(Runner.exit); } } \ No newline at end of file diff --git a/tests/ScopeTest.hx b/tests/ScopeTest.hx new file mode 100644 index 0000000..8a2ab24 --- /dev/null +++ b/tests/ScopeTest.hx @@ -0,0 +1,53 @@ +package; + +import haxe.crypto.*; + +using haxe.io.Path; +using haxe.Json; +using sys.io.File; +using sys.FileSystem; +using tink.CoreApi; + +@:asserts +class ScopeTest extends TestBase { + + var dir:String; + + @:before + public function mkdir() { + dir = Sha1.encode(Std.string(Std.random(999999))).substr(0, 12); // fancy way to make a random folder name + dir.createDirectory(); + Sys.setCwd(dir); + return Noise; + } + + @:after + public function rmrf() { + Sys.setCwd(TestBase.CWD); + deleteDirectory(dir); + return Noise; + } + + public function create() { + asserts.assert(switchx(['scope', 'create'], true).exitCode == 0); + var haxerc = '.haxerc'.getContent().parse(); + asserts.assert(haxerc.version == '3.4.2'); + asserts.assert(haxerc.resolveLibs == 'mixed'); + return asserts.done(); + } + + public function delete() { + switchx(['scope', 'create']); + asserts.assert(switchx(['scope', 'delete']).exitCode == 0); + asserts.assert(!'.haxerc'.exists()); + return asserts.done(); + } + + public function display() { + switchx(['scope', 'create']); + var display = switchx(['scope']); + asserts.assert(display.exitCode == 0); + asserts.assert(display.stdout == '[local] ${Sys.getCwd().removeTrailingSlashes()}\n'); + return asserts.done(); + } +} \ No newline at end of file diff --git a/tests/TestBase.hx b/tests/TestBase.hx index 8d67df7..5c71e1b 100644 --- a/tests/TestBase.hx +++ b/tests/TestBase.hx @@ -1,20 +1,42 @@ package; +using sys.io.File; +using sys.FileSystem; + class TestBase { + + public static var CWD(default, null) = Sys.getCwd(); + public function new() {} - function switchx(args:Array) { - return run('node', ['bin/switchx.js'].concat(args)); + function switchx(args:Array, debug = false) { + return run('node', ['$CWD/bin/switchx.js'].concat(args), debug); } - function run(cmd, args) { + function run(cmd, args, debug = false) { var proc = new Process(cmd, args); var stdout = proc.stdout.readAll().toString(); var stderr = proc.stderr.readAll().toString(); + + if(debug) { + trace(stdout); + trace(stderr); + } + return { exitCode: proc.exitCode(), stdout: stdout, stderr: stderr, } } + + function deleteDirectory(path:String) { + for(p in path.readDirectory()) { + var full = '$path/$p'; + trace(full); + if(full.isDirectory()) deleteDirectory(full); + else full.deleteFile(); + } + path.deleteDirectory(); + } } \ No newline at end of file From 63d24027f9dfbf2eafaf85d649f997a87f5bb906 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Thu, 8 Jun 2017 17:04:06 +0800 Subject: [PATCH 6/7] Test install nightly --- tests/InstallTest.hx | 26 ++++++++++++++++++-------- tests/ScopeTest.hx | 2 +- tests/TestBase.hx | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/InstallTest.hx b/tests/InstallTest.hx index c7ed5a7..7ac23d4 100644 --- a/tests/InstallTest.hx +++ b/tests/InstallTest.hx @@ -1,17 +1,27 @@ package; +using InstallTest; + @:asserts class InstallTest extends TestBase { - public function official() { - asserts.assert(switchx(['install', '3.4.0']).exitCode == 0); - - var list = switchx(['list']).stdout; - asserts.assert(contains(list, ['3.4.0', '3.4.2'])); + + @:variant('ada466c') + @:variant('c294a69') + public function nightly(sha:String) { + switchx(['install', sha]); + asserts.assert(switchx(['use', sha]).exitCode == 0); + asserts.assert(switchx(['list']).stdout.contains('-> $sha')); return asserts.done(); } - function contains(arr:String, v:Array) { - for(v in v) if(arr.indexOf(v) == -1) return false; - return true; + @:variant('3.4.0') + @:variant('3.4.2') + public function official(version) { + asserts.assert(switchx(['install', version]).exitCode == 0); + asserts.assert(switchx(['list']).stdout.contains('-> $version')); + return asserts.done(); } + + static function contains(arr:String, v:String) + return arr.indexOf(v) != -1; } \ No newline at end of file diff --git a/tests/ScopeTest.hx b/tests/ScopeTest.hx index 8a2ab24..735fff2 100644 --- a/tests/ScopeTest.hx +++ b/tests/ScopeTest.hx @@ -29,7 +29,7 @@ class ScopeTest extends TestBase { } public function create() { - asserts.assert(switchx(['scope', 'create'], true).exitCode == 0); + asserts.assert(switchx(['scope', 'create']).exitCode == 0); var haxerc = '.haxerc'.getContent().parse(); asserts.assert(haxerc.version == '3.4.2'); asserts.assert(haxerc.resolveLibs == 'mixed'); diff --git a/tests/TestBase.hx b/tests/TestBase.hx index 5c71e1b..e332884 100644 --- a/tests/TestBase.hx +++ b/tests/TestBase.hx @@ -33,7 +33,6 @@ class TestBase { function deleteDirectory(path:String) { for(p in path.readDirectory()) { var full = '$path/$p'; - trace(full); if(full.isDirectory()) deleteDirectory(full); else full.deleteFile(); } From 58c2eacfb6996a9600d6dc0fea6ab222d1621c02 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Fri, 9 Jun 2017 21:55:40 +0800 Subject: [PATCH 7/7] Test changing scope --- tests/ScopeTest.hx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/ScopeTest.hx b/tests/ScopeTest.hx index 735fff2..a7c737c 100644 --- a/tests/ScopeTest.hx +++ b/tests/ScopeTest.hx @@ -50,4 +50,23 @@ class ScopeTest extends TestBase { asserts.assert(display.stdout == '[local] ${Sys.getCwd().removeTrailingSlashes()}\n'); return asserts.done(); } + + @:variant('scoped') + @:variant('mixed') + @:variant('haxelib') + public function change(mode:String) { + switchx(['scope', 'create']); + asserts.assert(switchx(['libs', mode]).exitCode == 0); + var haxerc = '.haxerc'.getContent().parse(); + asserts.assert(haxerc.resolveLibs == mode); + return asserts.done(); + } + + @:variant('rubbish') + @:variant('') + public function invalidChange(mode:String) { + switchx(['scope', 'create']); + asserts.assert(switchx(['libs', mode]).exitCode != 0); + return asserts.done(); + } } \ No newline at end of file