-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtests.luau
More file actions
91 lines (75 loc) · 2.38 KB
/
tests.luau
File metadata and controls
91 lines (75 loc) · 2.38 KB
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
local fs = require("@lune/fs")
local io = require("@lune/stdio")
local process = require("@lune/process")
local tiniest = require("@tiniest/tiniest_for_lune").configure({
snapshot_path = "./test/__snapshots__",
save_snapshots = false,
})
local lastPackageFile = "./test/last_tested_package.txt"
-- Function to read the last package name from the file
local function readLastPackage()
if fs.isFile(lastPackageFile) then
local content = fs.readFile(lastPackageFile)
return content and content:match("^%s*(.-)%s*$") -- Trim whitespace
end
return nil
end
-- Function to write the last package name to the file
local function writeLastPackage(packageName)
fs.writeFile(lastPackageFile, packageName)
end
-- Prompt the user for the directory name
local dirName = io.prompt("text", "Enter the name of a directory inside lib: ")
-- Handle "last" input
if not dirName or dirName == "last" or dirName == "" then
dirName = readLastPackage()
if not dirName or dirName == "" then
print("No previous package name found.")
process.exit(1)
else
print("Using last package name: " .. dirName)
end
else
writeLastPackage(dirName)
end
if not dirName or dirName == "" then
print("Invalid directory name.")
process.exit(1)
end
local basePath = "lib/" .. dirName
-- Function to collect `.spec` files recursively
local function collectSpecFiles(path, result)
local entries = fs.readDir(path)
for _, entry in pairs(entries) do
local fullPath = path .. "/" .. entry
local isDir = fs.isDir(fullPath)
if not isDir and entry:match("%.spec") then
table.insert(result, fullPath)
elseif isDir then
collectSpecFiles(fullPath, result)
end
end
end
if not fs.isDir(basePath) then
print("Directory does not exist: " .. basePath)
process.exit(1)
end
local specFiles = {}
collectSpecFiles(basePath, specFiles)
local tests = tiniest.collect_tests(function()
local describe = tiniest.describe
local function describe_from_file(name: string)
describe(string.gsub(name, ".luau", ""), function()
require(name)(tiniest)
end)
end
-- Output the collected files
if #specFiles > 0 then
for _, file in pairs(specFiles) do
describe_from_file(file)
end
else
print("No .spec files found in " .. basePath)
end
end)
tiniest.run_tests(tests, {})