Debian Codegraph @

extra/haxelib_src/test/tests/TestVcsNotFound.hx

raw
1 package tests;
2
3 import sys.FileSystem;
4 import haxe.io.*;
5
6 import haxelib.client.Vcs;
7
8 class TestVcsNotFound extends TestBase
9 {
10 //----------- properties, fields ------------//
11
12 static inline var REPO_ROOT = "test/libraries";
13 static inline var REPO_DIR = "vcs-no";
14 static var CWD:String = null;
15
16 //--------------- constructor ---------------//
17 public function new()
18 {
19 super();
20 CWD = Sys.getCwd();
21 }
22
23
24 //--------------- initialize ----------------//
25
26 override public function setup():Void
27 {
28 Sys.setCwd(Path.join([CWD, REPO_ROOT]));
29
30 if(FileSystem.exists(REPO_DIR)) {
31 deleteDirectory(REPO_DIR);
32 }
33 FileSystem.createDirectory(REPO_DIR);
34
35 Sys.setCwd(REPO_DIR);
36 }
37
38 override public function tearDown():Void
39 {
40 // restore original CWD & PATH:
41 Sys.setCwd(CWD);
42
43 deleteDirectory(Path.join([CWD, REPO_ROOT, REPO_DIR]));
44 }
45
46 //----------------- tests -------------------//
47
48
49 public function testAvailableHg():Void
50 {
51 assertFalse(getHg().available);
52 }
53
54 public function testAvailableGit():Void
55 {
56 assertFalse(getGit().available);
57 }
58
59
60 public function testCloneHg():Void
61 {
62 var vcs = getHg();
63 try
64 {
65 vcs.clone(vcs.directory, "https://bitbucket.org/fzzr/hx.signal");
66 assertFalse(true);
67 }
68 catch(error:VcsError)
69 {
70 switch(error)
71 {
72 case VcsError.CantCloneRepo(_, repo, stderr): assertTrue(true);
73 default: assertFalse(true);
74 }
75 }
76 }
77
78 public function testCloneGit():Void
79 {
80 var vcs = getGit();
81 try
82 {
83 vcs.clone(vcs.directory, "https://github.com/fzzr-/hx.signal.git");
84 assertFalse(true);
85 }
86 catch(error:VcsError)
87 {
88 switch(error)
89 {
90 case VcsError.CantCloneRepo(_, repo, stderr): assertTrue(true);
91 default: assertFalse(true);
92 }
93 }
94 }
95
96
97 //----------------- tools -------------------//
98
99 inline function getHg():Vcs
100 {
101 return new WrongHg({quiet: true});
102 }
103
104 inline function getGit():Vcs
105 {
106 return new WrongGit({quiet: true});
107 }
108 }
109
110
111
112 class WrongHg extends Mercurial
113 {
114 public function new(settings:Settings)
115 {
116 super(settings);
117 this.directory = "no-hg";
118 this.executable = "no-hg";
119 this.name = "Mercurial-not-found";
120 }
121
122 // copy of Mercurial.searchExecutablebut have a one change - regexp.
123 override private function searchExecutable():Void
124 {
125 super.searchExecutable();
126
127 if(available)
128 return;
129
130 // if we have already msys git/cmd in our PATH
131 var match = ~/(.*)no-hg-no([\\|\/])cmd$/;
132 for(path in Sys.getEnv("PATH").split(";"))
133 {
134 if(match.match(path.toLowerCase()))
135 {
136 var newPath = match.matched(1) + executable + match.matched(2) + "bin";
137 Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + newPath);
138 }
139 }
140 checkExecutable();
141 }
142 }
143
144 class WrongGit extends Git
145 {
146 public function new(settings:Settings)
147 {
148 super(settings);
149 this.directory = "no-git";
150 this.executable = "no-git";
151 this.name = "Git-not-found";
152 }
153
154 // copy of Mercurial.searchExecutablebut have a one change - regexp.
155 override private function searchExecutable():Void
156 {
157 super.searchExecutable();
158
159 if(available)
160 return;
161
162 // if we have already msys git/cmd in our PATH
163 var match = ~/(.*)no-git-no([\\|\/])cmd$/;
164 for(path in Sys.getEnv("PATH").split(";"))
165 {
166 if(match.match(path.toLowerCase()))
167 {
168 var newPath = match.matched(1) + executable + match.matched(2) + "bin";
169 Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + newPath);
170 }
171 }
172 if(checkExecutable())
173 return;
174 // look at a few default paths
175 for(path in ["C:\\Program Files (x86)\\Git\\bin", "C:\\Progra~1\\Git\\bin"])
176 if(FileSystem.exists(path))
177 {
178 Sys.putEnv("PATH", Sys.getEnv("PATH") + ";" + path);
179 if(checkExecutable())
180 return;
181 }
182 }
183 }