Skip to content

Commit b60b8ef

Browse files
committed
feature: lute test runs all the tests
1 parent d7ca1cc commit b60b8ef

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ jobs:
4545
- name: Run Luau Tests (POSIX)
4646
if: runner.os != 'Windows'
4747
shell: bash
48-
run: find tests -name "*.test.luau" | xargs -I {} "${{ steps.build_lute.outputs.exe_path }}" run {}
48+
run: ${{ steps.build_lute.outputs.exe_path }} test
4949

5050
- name: Run Luau Tests (Windows)
5151
if: runner.os == 'Windows'
5252
shell: cmd
53-
run: for /r tests %%f in (*.test.luau) do "${{ steps.build_lute.outputs.exe_path }}" run "%%f"
53+
run: ${{ steps.build_lute.outputs.exe_path }} test
5454

5555
run-lute-cxx-unittests:
5656
runs-on: ${{ matrix.os }}

lute/cli/commands/test/finder.luau

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local function findtestfilesrec(directory: path.path): { path.path }
1717
if entry.type == "dir" then
1818
tableext.extend(results, findtestfilesrec(fullPath))
1919
elseif istestfile(entry.name) then
20-
table.insert(results, fullPath)
20+
table.insert(results, path.normalize(fullPath))
2121
end
2222
end
2323

@@ -37,7 +37,7 @@ local function findtestfiles(paths: { string }): { path.path }
3737
if fs.type(pathObj) == "dir" then
3838
tableext.extend(files, findtestfilesrec(pathObj))
3939
elseif istestfile(filepath) then
40-
table.insert(files, pathObj)
40+
table.insert(files, path.normalize(pathObj))
4141
end
4242
end
4343

lute/cli/commands/test/init.luau

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
local finder = require("@self/finder")
22
local luau = require("@std/luau")
33
local path = require("@std/path")
4+
local ps = require("@std/process")
5+
local testtypes = require("@std/test/types")
6+
local runner = require("@std/test/runner")
7+
local reporter = require("@std/test/reporter")
48
local test = require("@std/test")
59

610
local function printHelp()
@@ -85,6 +89,15 @@ local function listtests()
8589
end
8690
end
8791

92+
local function runtests(env: testtypes.testenvironment, runner: testtypes.testrunner, reporter: testtypes.testreporter)
93+
local result = runner(env)
94+
reporter(result)
95+
if result.failed ~= 0 then
96+
ps.exit(1)
97+
end
98+
ps.exit(0)
99+
end
100+
88101
local function main(...: string)
89102
local args = { ... }
90103
local testPaths = {}
@@ -105,6 +118,9 @@ local function main(...: string)
105118

106119
if isListMode then
107120
listtests()
121+
else
122+
local env = test._registered()
123+
runtests(env, runner.run, reporter.simple)
108124
end
109125
end
110126

lute/std/libs/test/runner.luau

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
local types = require("./types")
66
local assert = require("./assert")
7+
local path = require("@std/path")
78

89
type Test = types.Test
910
type TestCase = types.TestCase
@@ -103,7 +104,7 @@ function runner.run(env: TestEnvironment): TestRunResult
103104
test = tc.name,
104105
assertion = if assertName == "xpcall" then nil else assertName,
105106
error = if assertName == "xpcall" then nil else err.msg,
106-
filename = fileName,
107+
filename = path.format(fileName),
107108
linenumber = lineNumber,
108109
}
109110
table.insert(failures, failedtest)
@@ -142,7 +143,7 @@ function runner.run(env: TestEnvironment): TestRunResult
142143
test = testFullName,
143144
assertion = if assertName == "xpcall" then nil else assertName,
144145
error = if assertName == "xpcall" then nil else err.msg,
145-
filename = fileName,
146+
filename = path.format(fileName),
146147
linenumber = lineNumber,
147148
}
148149
table.insert(failures, failedtest)

tests/cli/test.test.luau

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ test.suite("lute test", function(suite)
2626
assert.neq(result.stdout:find("Usage:", 1, true), nil)
2727
end)
2828

29-
suite:case("lute test runs successfully", function(assert)
30-
-- Run lute test without arguments
31-
local result = process.run({ lutePath, "test" })
29+
suite:case("lute test runs tests in discovery folder", function(assert)
30+
-- Run lute test on tests/cli/discovery folder
31+
local result = process.run({ lutePath, "test", "tests/cli/discovery" })
3232

33-
-- Check that it succeeds
33+
-- Check that it runs tests and succeeds
3434
assert.eq(result.exitcode, 0)
3535
end)
3636

@@ -65,8 +65,7 @@ test.run()
6565
fs.close(handle)
6666

6767
-- Run lute on the created test file
68-
local result = process.run({ lutePath, tostring(testFilePath) })
69-
68+
local result = process.run({ lutePath, path.format(testFilePath) })
7069
-- Check that the output doesn't include xpcall
7170
assert.eq(result.exitcode, 1)
7271
assert.eq(result.stdout:find("xpcall", 1, true), nil)
@@ -100,7 +99,7 @@ test.run()
10099
fs.close(handle)
101100

102101
-- Run lute on the created test file
103-
local result = process.run({ lutePath, tostring(testFilePath) })
102+
local result = process.run({ lutePath, path.format(testFilePath) })
104103

105104
-- Check that the output doesn't include xpcall
106105
assert.eq(result.exitcode, 1)

0 commit comments

Comments
 (0)