-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunTests.luau
89 lines (75 loc) · 2.91 KB
/
RunTests.luau
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
--Simple test runner that runs all tests in the game.
--This most likely won't be used directly due to how simple it is, but exists for quick testing.
--!strict
local MESSAGE_TYPE_TO_NAME = {
[Enum.MessageType.MessageOutput] = "OUTPUT",
[Enum.MessageType.MessageWarning] = "WARNING",
[Enum.MessageType.MessageError] = "ERROR",
[Enum.MessageType.MessageInfo] = "INFO",
}
local RunModuleScript = require(script.Parent:WaitForChild("Runner"):WaitForChild("RunModuleScript"))
local Test = require(script.Parent:WaitForChild("State"):WaitForChild("Test"):WaitForChild("Test"))
local MdouleScriptDiscovery = require(script.Parent:WaitForChild("State"):WaitForChild("Discovery"):WaitForChild("ModuleScriptDiscovery"))
local FormatLines = require(script.Parent:WaitForChild("Util"):WaitForChild("FormatLines"))
local StateSummary = {
NOT_RUN = 0,
PASSED = 0,
FAILED = 0,
SKIPPED = 0,
}
--[[
Outputs the results of a test.
--]]
local function OutputTest(TestInstance: Test.Test, Prefix: string): ()
--Print the test information.
local DurationText = nil
if TestInstance.StartTime and TestInstance.EndTime then
DurationText = ` ({string.format("%.3f", TestInstance.EndTime - TestInstance.StartTime)} seconds)`
end
local TestMessage = `{Prefix}[{TestInstance.State}] {TestInstance.Name}{DurationText}`
if TestInstance.State == "PASSED" then
print(TestMessage)
else
warn(TestMessage)
for _, Output in TestInstance.Output do
local Lines = FormatLines(Output.Contents, Output.ContentsSize)
for _, Line in Lines do
local Message = `{Prefix} [{MESSAGE_TYPE_TO_NAME[Output.MessageType]}] {Line}`
if Output.MessageType == Enum.MessageType.MessageOutput then
print(Message)
else
warn(Message)
end
end
end
end
--Add the total.
if StateSummary[TestInstance.State] then
StateSummary[TestInstance.State] += 1
end
--Print the child tests.
for _, ChildTest in TestInstance.ChildTests do
OutputTest(ChildTest :: Test.Test, `{Prefix} `)
end
end
--Discover the ModuleScript tests.
local ModuleScriptDiscoveryInstance = MdouleScriptDiscovery.new(game)
local ModuleScriptTests = {}
for _, ChildTest in ModuleScriptDiscoveryInstance.RootTest.ChildTests do
table.insert(ModuleScriptTests, ChildTest)
end
table.sort(ModuleScriptTests, function(a, b) return a.Name < b.Name end)
ModuleScriptDiscoveryInstance:Destroy()
--Run the tests.
for _, ModuleScriptTest in ModuleScriptTests do
print(`Running test \"{ModuleScriptTest.Name}\"...`)
RunModuleScript(ModuleScriptTest :: Test.Test)
OutputTest(ModuleScriptTest :: Test.Test, "")
end
--Print the summary.
print("\nTest summary:")
for State, Total in StateSummary do
print(` {State}: {Total}`)
end
--Return the summary.
return StateSummary