-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroca_main.brs
104 lines (84 loc) · 3.09 KB
/
roca_main.brs
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
100
101
102
103
104
function main() as object
files = []
dirsToSearch = ["test", "tests", "source", "components"]
for each dir in dirsToSearch
files.append(__roca_findTestFiles("pkg:/" + dir))
end for
rootSuites = []
filesWithFocusedCases = []
for each filePath in files
' user-facing
filePathWithoutPkg = filePath.replace("pkg:", "")
suite = _brs_.runInScope(filePath, {})
if suite = invalid then
print "Error running tests: Runtime exception occurred in " + filePathWithoutPkg
return {}
end if
if GetInterface(suite, "ifArray") = invalid then
suite = [suite]
end if
for each subSuite in suite
if subSuite.mode = "focus" or subSuite.__state.hasFocusedDescendants then
filesWithFocusedCases.push(filePathWithoutPkg)
end if
rootSuites.push(subSuite)
end for
end for
tap = tap()
tap.version()
focusedCasesDetected = filesWithFocusedCases.count() > 0
if focusedCasesDetected then
tap.plan(filesWithFocusedCases.count())
else
tap.plan(rootSuites.count())
end if
args = {
exec: true,
focusedCasesDetected: focusedCasesDetected
index: 0,
tap: tap
}
for each filePath in files
' user-facing
filePathWithoutPkg = filePath.replace("pkg:", "")
' Don't allow test files to pollute each other
_brs_.resetMocks()
suite = _brs_.runInScope(filePath, args)
' If brs returned invalid for runInScope, that means the suite threw an exception, so we should bail.
if suite = invalid then
tap.bail("Error running tests: Runtime exception occurred in " + filePath.replace("pkg:", ""))
return {}
end if
' If there are focused cases, only update the index when we've run a focused root suite.
' Otherwise, always update it.
if focusedCasesDetected <> true or suite.__state.hasFocusedDescendants then
args.index += 1
end if
end for
return {
filesWithFocusedCases: filesWithFocusedCases
}
end function
' Recursively searches directories for '*.test.brs' files starting at `path`.
'
' @param {string} [path="pkg:"] - the path to search
' @param {roArray} [testFiles=[]] - the current set of discovered test files
'
' @returns {roArray} an array containing the fully-qualified path to each '*.test.brs' file
' discovered recursively from `path`
function __roca_findTestFiles(path as string, testFiles = [] as object) as object
files = ListDir(path)
for each maybeDir in files
subDirPath = [path, maybeDir].join("/")
' check to see if this is a sub-directory
subDirFiles = ListDir(subDirPath)
if subDirFiles.count() > 0 then
testFiles = __roca_findTestFiles(subDirPath, testFiles)
end if
end for
filesInPath = MatchFiles(path, "*.test.brs")
for each file in filesInPath
testFiles.push([path, file].join("/"))
end for
return testFiles
end function