Debian Codegraph @

extra/haxelib_src/test/HaxelibTests.hx

raw
1 import haxe.io.Path;
2 import haxelib.client.Vcs.VcsID;
3 import haxe.unit.TestRunner;
4 import sys.*;
5 import sys.io.*;
6 import tests.*;
7 using StringTools;
8
9 class HaxelibTests {
10 public static function runCommand(cmd:String, args:Array<String>):Void
11 {
12 Sys.println('Command: $cmd $args');
13
14 var exitCode = Sys.command(cmd, args);
15
16 Sys.println('Command exited with $exitCode: $cmd $args');
17
18 if(exitCode != 0)
19 Sys.exit(exitCode);
20 }
21
22 static function cmdSucceed(cmd:String, ?args:Array<String>):Bool {
23 var p = try {
24 new Process(cmd, args);
25 } catch(e:Dynamic) {
26 return false;
27 }
28 var exitCode = p.exitCode();
29 p.close();
30 return exitCode == 0;
31 }
32
33 static public function deleteDirectory(dir:String) {
34 if (!FileSystem.exists(dir)) return;
35 var exitCode = switch (Sys.systemName()) {
36 case "Windows":
37 Sys.command("rmdir", ["/S", "/Q", StringTools.replace(FileSystem.fullPath(dir), "/", "\\")]);
38 case _:
39 Sys.command("rm", ["-rf", dir]);
40 }
41 if (exitCode != 0) {
42 throw 'unable to delete $dir';
43 }
44 }
45
46 static function main():Void {
47 var r = new TestRunner();
48
49 r.add(new TestSemVer());
50 r.add(new TestData());
51 r.add(new TestRemoveSymlinks());
52 r.add(new TestRemoveSymlinksBroken());
53
54 var isCI = Sys.getEnv("CI") != null;
55
56 if (isCI || cmdSucceed("hg", ["version"])) {
57 // Hg impl. suports tags & revs. Here "78edb4b" is a first revision "initial import" at that repo:
58 TestHg.init();
59 r.add(new TestHg());
60 } else {
61 Sys.println("hg not found.");
62 }
63 if (isCI || cmdSucceed("git", ["version"])) {
64 // Git impl. suports only tags. Here "0.9.2" is a first revision too ("initial import"):
65 TestGit.init();
66 r.add(new TestGit());
67 } else {
68 Sys.println("git not found.");
69 }
70 r.add(new TestVcsNotFound());
71
72 r.add(new TestInstall());
73
74 var success = r.run();
75 Sys.exit(success ? 0 : 1);
76 }
77 }