| 1 |
package tests; |
| 2 |
|
| 3 |
import sys.io.*; |
| 4 |
import sys.FileSystem; |
| 5 |
import haxe.io.*; |
| 6 |
import haxe.unit.TestCase; |
| 7 |
|
| 8 |
import haxelib.client.Cli; |
| 9 |
import haxelib.client.Vcs; |
| 10 |
|
| 11 |
class TestVcs extends TestBase |
| 12 |
{ |
| 13 |
//----------- properties, fields ------------// |
| 14 |
|
| 15 |
static inline var REPO_ROOT = "test/libraries"; |
| 16 |
static inline var REPO_DIR = "vcs"; |
| 17 |
static var CWD:String = null; |
| 18 |
|
| 19 |
var id:VcsID = null; |
| 20 |
var vcsName:String = null; |
| 21 |
var url:String = null; |
| 22 |
var rev:String = null; |
| 23 |
var counter:Int = 0; |
| 24 |
|
| 25 |
//--------------- constructor ---------------// |
| 26 |
|
| 27 |
public function new(id:VcsID, vcsName:String, url:String, ?rev:String) |
| 28 |
{ |
| 29 |
super(); |
| 30 |
this.id = id; |
| 31 |
this.url = url; |
| 32 |
this.rev = rev; |
| 33 |
this.vcsName = vcsName; |
| 34 |
|
| 35 |
CWD = Sys.getCwd(); |
| 36 |
counter = 0; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
//--------------- initialize ----------------// |
| 41 |
|
| 42 |
override public function setup():Void |
| 43 |
{ |
| 44 |
Sys.setCwd(Path.join([CWD, REPO_ROOT])); |
| 45 |
|
| 46 |
if(FileSystem.exists(REPO_DIR)) { |
| 47 |
deleteDirectory(REPO_DIR); |
| 48 |
} |
| 49 |
FileSystem.createDirectory(REPO_DIR); |
| 50 |
|
| 51 |
Sys.setCwd(REPO_DIR); |
| 52 |
} |
| 53 |
|
| 54 |
override public function tearDown():Void |
| 55 |
{ |
| 56 |
// restore original CWD: |
| 57 |
Sys.setCwd(CWD); |
| 58 |
|
| 59 |
deleteDirectory(Path.join([CWD, REPO_ROOT, REPO_DIR])); |
| 60 |
} |
| 61 |
|
| 62 |
//----------------- tests -------------------// |
| 63 |
|
| 64 |
|
| 65 |
public function testGetVcs():Void |
| 66 |
{ |
| 67 |
assertTrue(Vcs.get(id, {quiet: true}) != null); |
| 68 |
assertTrue(Vcs.get(id, {quiet: true}).name == vcsName); |
| 69 |
} |
| 70 |
|
| 71 |
public function testAvailable():Void |
| 72 |
{ |
| 73 |
assertTrue(getVcs().available); |
| 74 |
} |
| 75 |
|
| 76 |
// --------------- clone --------------- // |
| 77 |
|
| 78 |
public function testGetVcsByDir():Void |
| 79 |
{ |
| 80 |
var vcs = getVcs(); |
| 81 |
testCloneSimple(); |
| 82 |
|
| 83 |
assertEquals(vcs, Vcs.get(id, {quiet: true})); |
| 84 |
} |
| 85 |
|
| 86 |
public function testCloneSimple():Void |
| 87 |
{ |
| 88 |
var vcs = getVcs(); |
| 89 |
var dir = vcs.directory + counter++; |
| 90 |
vcs.clone(dir, url); |
| 91 |
|
| 92 |
assertTrue(FileSystem.exists(dir)); |
| 93 |
assertTrue(FileSystem.isDirectory(dir)); |
| 94 |
|
| 95 |
assertTrue(FileSystem.exists('$dir/.${vcs.directory}')); |
| 96 |
assertTrue(FileSystem.isDirectory('$dir/.${vcs.directory}')); |
| 97 |
} |
| 98 |
|
| 99 |
public function testCloneBranch():Void |
| 100 |
{ |
| 101 |
var vcs = getVcs(); |
| 102 |
var dir = vcs.directory + counter++; |
| 103 |
vcs.clone(dir, url, "develop"); |
| 104 |
|
| 105 |
assertTrue(FileSystem.exists(dir)); |
| 106 |
assertTrue(FileSystem.isDirectory(dir)); |
| 107 |
|
| 108 |
assertTrue(FileSystem.exists('$dir/.${vcs.directory}')); |
| 109 |
assertTrue(FileSystem.isDirectory('$dir/.${vcs.directory}')); |
| 110 |
} |
| 111 |
|
| 112 |
public function testCloneBranchTag_0_9_2():Void |
| 113 |
{ |
| 114 |
var vcs = getVcs(); |
| 115 |
var dir = vcs.directory + counter++; |
| 116 |
vcs.clone(dir, url, "develop", "0.9.2"); |
| 117 |
Sys.sleep(3); |
| 118 |
assertTrue(FileSystem.exists(dir)); |
| 119 |
assertTrue(FileSystem.exists('$dir/.${vcs.directory}')); |
| 120 |
|
| 121 |
// if that repo "README.md" was added in tag/rev.: "0.9.3" |
| 122 |
assertFalse(FileSystem.exists(dir + "/README.md")); |
| 123 |
} |
| 124 |
|
| 125 |
public function testCloneBranchTag_0_9_3():Void |
| 126 |
{ |
| 127 |
var vcs = getVcs(); |
| 128 |
var dir = vcs.directory + counter++; |
| 129 |
vcs.clone(dir, url, "develop", "0.9.3"); |
| 130 |
|
| 131 |
assertTrue(FileSystem.exists(dir)); |
| 132 |
assertTrue(FileSystem.exists('$dir/.${vcs.directory}')); |
| 133 |
|
| 134 |
// if that repo "README.md" was added in tag/rev.: "0.9.3" |
| 135 |
assertTrue(FileSystem.exists(dir + "/README.md")); |
| 136 |
} |
| 137 |
|
| 138 |
public function testCloneBranchRev():Void |
| 139 |
{ |
| 140 |
var vcs = getVcs(); |
| 141 |
var dir = vcs.directory + counter++; |
| 142 |
vcs.clone(dir, url, "develop", rev); |
| 143 |
|
| 144 |
assertTrue(FileSystem.exists(dir)); |
| 145 |
assertTrue(FileSystem.exists('$dir/.${vcs.directory}')); |
| 146 |
|
| 147 |
// if that repo "README.md" was added in tag/rev.: "0.9.3" |
| 148 |
assertFalse(FileSystem.exists(dir + "/README.md")); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
// --------------- update --------------- // |
| 153 |
|
| 154 |
public function testUpdateBranchTag_0_9_2__toLatest():Void |
| 155 |
{ |
| 156 |
var vcs = getVcs(); |
| 157 |
var dir = vcs.directory + counter;// increment will do in `testCloneBranchTag_0_9_2` |
| 158 |
|
| 159 |
testCloneBranchTag_0_9_2(); |
| 160 |
assertFalse(FileSystem.exists("README.md")); |
| 161 |
|
| 162 |
// save CWD: |
| 163 |
var cwd = Sys.getCwd(); |
| 164 |
Sys.setCwd(cwd + dir); |
| 165 |
assertTrue(FileSystem.exists("." + vcs.directory)); |
| 166 |
|
| 167 |
// in this case `libName` can get any value: |
| 168 |
vcs.update("LIBNAME"); |
| 169 |
|
| 170 |
// Now we get actual version (0.9.3 or newer) with README.md. |
| 171 |
assertTrue(FileSystem.exists("README.md")); |
| 172 |
|
| 173 |
// restore CWD: |
| 174 |
Sys.setCwd(cwd); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
public function testUpdateBranchTag_0_9_2__toLatest__afterUserChanges_withReset():Void |
| 179 |
{ |
| 180 |
var vcs = getVcs(); |
| 181 |
var dir = vcs.directory + counter;// increment will do in `testCloneBranchTag_0_9_2` |
| 182 |
|
| 183 |
testCloneBranchTag_0_9_2(); |
| 184 |
assertFalse(FileSystem.exists("README.md")); |
| 185 |
|
| 186 |
// save CWD: |
| 187 |
var cwd = Sys.getCwd(); |
| 188 |
Sys.setCwd(cwd + dir); |
| 189 |
|
| 190 |
// creating user-changes: |
| 191 |
FileSystem.deleteFile("build.hxml"); |
| 192 |
File.saveContent("file", "new file \"file\" with content"); |
| 193 |
|
| 194 |
//Hack: set the default answer: |
| 195 |
Cli.defaultAnswer = true; |
| 196 |
|
| 197 |
// update to HEAD: |
| 198 |
// in this case `libName` can get any value: |
| 199 |
vcs.update("LIBNAME"); |
| 200 |
|
| 201 |
// Now we get actual version (0.9.3 or newer) with README.md. |
| 202 |
assertTrue(FileSystem.exists("README.md")); |
| 203 |
|
| 204 |
// restore CWD: |
| 205 |
Sys.setCwd(cwd); |
| 206 |
} |
| 207 |
|
| 208 |
public function testUpdateBranchTag_0_9_2__toLatest__afterUserChanges_withoutReset():Void |
| 209 |
{ |
| 210 |
var vcs = getVcs(); |
| 211 |
var dir = vcs.directory + counter;// increment will do in `testCloneBranchTag_0_9_2` |
| 212 |
|
| 213 |
testCloneBranchTag_0_9_2(); |
| 214 |
assertFalse(FileSystem.exists("README.md")); |
| 215 |
|
| 216 |
// save CWD: |
| 217 |
var cwd = Sys.getCwd(); |
| 218 |
Sys.setCwd(cwd + dir); |
| 219 |
|
| 220 |
// creating user-changes: |
| 221 |
FileSystem.deleteFile("build.hxml"); |
| 222 |
File.saveContent("file", "new file \"file\" with content"); |
| 223 |
|
| 224 |
//Hack: set the default answer: |
| 225 |
Cli.defaultAnswer = false; |
| 226 |
|
| 227 |
// update to HEAD: |
| 228 |
// in this case `libName` can get any value: |
| 229 |
vcs.update("LIBNAME"); |
| 230 |
|
| 231 |
// We get no reset and update: |
| 232 |
assertTrue(FileSystem.exists("file")); |
| 233 |
assertFalse(FileSystem.exists("build.hxml")); |
| 234 |
assertFalse(FileSystem.exists("README.md")); |
| 235 |
|
| 236 |
// restore CWD: |
| 237 |
Sys.setCwd(cwd); |
| 238 |
} |
| 239 |
|
| 240 |
//----------------- tools -------------------// |
| 241 |
|
| 242 |
inline function getVcs():Vcs |
| 243 |
{ |
| 244 |
return Vcs.get(id, {quiet: true}); |
| 245 |
} |
| 246 |
} |