Skip to content
This repository has been archived by the owner on Mar 3, 2018. It is now read-only.

Tests #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/bin/switchx.js
/bin
/node_modules
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ 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
- npm install

script:

- switchx list
- travix neko
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"haxe.displayConfigurations": [
["switchx.hxml"]
["switchx.hxml"],
["tests.hxml"]
]
}
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions haxe_libraries/ansi.hxml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions haxe_libraries/tink_chunk.hxml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions haxe_libraries/tink_macro.hxml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions haxe_libraries/tink_priority.hxml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions haxe_libraries/tink_streams.hxml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions haxe_libraries/tink_syntaxhub.hxml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions haxe_libraries/tink_testrunner.hxml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions haxe_libraries/tink_unittest.hxml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions haxe_libraries/travix.hxml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-cp tests
-main RunTests
-lib tink_unittest
27 changes: 27 additions & 0 deletions tests/InstallTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package;

using InstallTest;

@:asserts
class InstallTest extends TestBase {

@: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();
}

@: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;
}
8 changes: 8 additions & 0 deletions tests/ListTest.hx
Original file line number Diff line number Diff line change
@@ -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);
}
}
15 changes: 15 additions & 0 deletions tests/RunTests.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package;

import tink.testrunner.*;
import tink.unit.*;

class RunTests {
static function main() {
Runner.run(TestBatch.make([
new ListTest(),
new InstallTest(),
new UseTest(),
new ScopeTest(),
])).handle(Runner.exit);
}
}
72 changes: 72 additions & 0 deletions tests/ScopeTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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']).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();
}

@: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();
}
}
41 changes: 41 additions & 0 deletions tests/TestBase.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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<String>, debug = false) {
return run('node', ['$CWD/bin/switchx.js'].concat(args), debug);
}

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';
if(full.isDirectory()) deleteDirectory(full);
else full.deleteFile();
}
path.deleteDirectory();
}
}
36 changes: 36 additions & 0 deletions tests/UseTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package;

using StringTools;

@:asserts
class UseTest extends TestBase {

@: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();
}

function contains(arr:String, v:Array<String>) {
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', '');
}
}
2 changes: 2 additions & 0 deletions tests/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import tink.unit.Assert.assert;
import sys.io.Process;