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
|
-- Copyright (C) 2024 The Qt Company Ltd.
-- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
local Utils = require("Utils")
local Action = require("Action")
local a = require("async")
local function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str
end
local function printResults(results)
print("Passed:", results.passed)
print("Failed:", results.failed)
for index, value in ipairs(results.failedTests) do
print("Failed test:", value.name, value.error)
end
end
local function runTest(testFile, results)
local testScript, err = loadfile(testFile:nativePath())
if not testScript then
print("Failed to load test:", testFile, err)
return
end
local ok, testFunctions = pcall(testScript)
if not ok then
print("Failed to run test:", testFile, testFunctions)
return
end
for k, v in pairs(testFunctions) do
print("* " .. testFile:fileName() .. " : " .. k)
local ok, res_or_error = pcall(v)
if ok then
results.passed = results.passed + 1
else
results.failed = results.failed + 1
table.insert(results.failedTests, { name = testFile:fileName() .. ":" .. k, error = res_or_error })
end
end
end
local function runTests()
local results = {
passed = 0,
failed = 0,
failedTests = {}
}
local testDir = Utils.FilePath.fromUserInput(script_path()):parentDir()
local tests = a.wait(testDir:dirEntries({ nameFilters = { "tst_*.lua" } }))
for _, testFile in ipairs(tests) do
runTest(testFile, results)
end
printResults(results)
end
local function setup()
Action.create("LuaTests.run", {
text = "Run lua tests",
onTrigger = function() a.sync(runTests)() end,
})
Action.create("LuaTests.layoutDemo", {
text = "Lua Layout Demo",
onTrigger = function()
local script, err = loadfile(Utils.FilePath.fromUserInput(script_path()):parentDir():resolvePath(
"guidemo.lua"):nativePath())
if not script then
print("Failed to load demo:", err)
return
end
script()()
end,
})
end
return { setup = setup }
|