-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunTests.j
executable file
·99 lines (86 loc) · 2.17 KB
/
RunTests.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env objj
@import <Foundation/CPObject.j>
@implementation OLTestRunner : CPObject
{
}
- (void)startWithArguments:(CPArray)arguments
{
var arg = @"Tests/*/*Test*.j";
var globbedArguments = [self globArgument:arg];
var ojtestOptions = {args:globbedArguments};
print("Running 'ojtest " + arg + "'...");
runCommand("ojtest", ojtestOptions);
}
- (CPArray)globArgument:(CPString)argument
{
var arguments = [];
var paths = [""];
var tokens = argument.split("/");
for (var i = 0; i < tokens.length; i++)
{
var token = tokens[i];
var newPaths = [];
for (var j = 0; j < paths.length; j++)
{
var path = paths[j];
if (path !== "")
{
path += "/";
}
var newPath = [self globPath:path withToken:token];
for (var k = 0; k < newPath.length; k++)
{
newPaths.push(newPath[k]);
}
}
paths = newPaths;
}
return paths;
}
- (CPArray)globPath:(CPString)currentPath withToken:(CPString)token
{
var paths = [];
var wildcardLocation = token.indexOf("*");
if (wildcardLocation === -1)
{
if (currentPath === "")
{
paths.push(token);
}
else
{
paths.push(currentPath + token);
}
}
else
{
var regExString = token.split("*").join(".*");
var regEx = new RegExp(regExString, "i");
var filesOrFolders = [self runlsForPath:currentPath];
for (var j = 0; j < filesOrFolders.length; j++)
{
var fileOrFolder = filesOrFolders[j];
if (fileOrFolder && regEx.test(fileOrFolder))
{
paths.push(currentPath + fileOrFolder);
}
}
}
return paths;
}
- (JSObject)runlsForPath:(CPString)path
{
var options = {output: ''};
if (path === "")
{
runCommand("ls", options);
}
else
{
runCommand("ls", path, options);
}
return options.output.split("\n");
}
@end
var testRunner = [[OLTestRunner alloc] init];
[testRunner startWithArguments:args];