| 1 |
package tests; |
| 2 |
|
| 3 |
import sys.io.*; |
| 4 |
import sys.FileSystem; |
| 5 |
import haxe.io.*; |
| 6 |
import haxe.unit.TestCase; |
| 7 |
import haxelib.Data; |
| 8 |
|
| 9 |
|
| 10 |
class TestInstall extends TestBase |
| 11 |
{ |
| 12 |
|
| 13 |
static inline var REPO = "haxelib-repo"; |
| 14 |
static inline var PROJECT_FOLDER = "UseGitDep"; |
| 15 |
static inline var REPO_ROOT = "test/libraries"; |
| 16 |
static var CWD:String = null; |
| 17 |
static var origRepo:String = null; |
| 18 |
var repo:String = null; |
| 19 |
|
| 20 |
|
| 21 |
//--------------- constructor ---------------// |
| 22 |
|
| 23 |
public function new() |
| 24 |
{ |
| 25 |
super(); |
| 26 |
this.repo = Path.join([Sys.getCwd(), "test", REPO]); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
//--------------- initialize ----------------// |
| 31 |
|
| 32 |
override public function setup():Void |
| 33 |
{ |
| 34 |
origRepo = ~/\r?\n/.split(runHaxelib(["config"]).stdout)[0]; |
| 35 |
origRepo = Path.normalize(origRepo); |
| 36 |
|
| 37 |
if (runHaxelib(["setup", repo]).exitCode != 0) { |
| 38 |
throw "haxelib setup failed"; |
| 39 |
} |
| 40 |
|
| 41 |
CWD = Sys.getCwd(); |
| 42 |
var dir = Path.join([CWD, REPO_ROOT, PROJECT_FOLDER]); |
| 43 |
Sys.setCwd(dir); |
| 44 |
} |
| 45 |
|
| 46 |
override public function tearDown():Void |
| 47 |
{ |
| 48 |
// restore original CWD: |
| 49 |
Sys.setCwd(CWD); |
| 50 |
|
| 51 |
if (runHaxelib(["setup", origRepo]).exitCode != 0) { |
| 52 |
throw "haxelib setup failed"; |
| 53 |
} |
| 54 |
deleteDirectory(repo); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
//----------------- tests -------------------// |
| 59 |
|
| 60 |
public function testInstallHaxelibParameter():Void |
| 61 |
{ |
| 62 |
var r = runHaxelib(["install", "haxelib.json"]); |
| 63 |
assertTrue(r.exitCode == 0); |
| 64 |
|
| 65 |
checkLibrary(getLibraryName()); |
| 66 |
} |
| 67 |
|
| 68 |
public function testInstallHaxelibDependencyWithTag():Void |
| 69 |
{ |
| 70 |
var r = runHaxelib(["install", "tag_haxelib.json"]); |
| 71 |
assertTrue(r.exitCode == 0); |
| 72 |
|
| 73 |
var lib = getLibraryName(); |
| 74 |
checkLibrary(lib); |
| 75 |
|
| 76 |
// if that repo "README.md" was added in tag/rev.: "0.9.3" |
| 77 |
assertFalse(FileSystem.exists(Path.join([lib, "git", "README.md"]))); |
| 78 |
} |
| 79 |
|
| 80 |
public function testReinstallHxml() { |
| 81 |
var r = runHaxelib(["install", "git-deps.hxml", "--always"]); |
| 82 |
assertEquals(0, r.exitCode); |
| 83 |
var r = runHaxelib(["install", "git-deps.hxml", "--always"]); |
| 84 |
assertEquals(0, r.exitCode); |
| 85 |
var r = runHaxelib(["path", "hx.signal"]); |
| 86 |
assertEquals(0, r.exitCode); |
| 87 |
} |
| 88 |
|
| 89 |
function getLibraryName():String |
| 90 |
{ |
| 91 |
var haxelibFile = File.read("haxelib.json", false); |
| 92 |
var details = Data.readData(haxelibFile.readAll().toString(), false ); |
| 93 |
haxelibFile.close(); |
| 94 |
return details.dependencies.toArray()[0].name; |
| 95 |
} |
| 96 |
|
| 97 |
function checkLibrary(lib:String):Void |
| 98 |
{ |
| 99 |
// Library folder exists |
| 100 |
var libFolder = Path.join([repo, lib]); |
| 101 |
assertTrue(FileSystem.exists(libFolder)); |
| 102 |
assertTrue(FileSystem.isDirectory(libFolder)); |
| 103 |
|
| 104 |
// Library version is set to git |
| 105 |
var current = File.read(Path.join([libFolder, ".current"]), false); |
| 106 |
assertTrue(current.readAll().toString() == "git"); |
| 107 |
current.close(); |
| 108 |
} |
| 109 |
|
| 110 |
} |