This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure all files have tests associated
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
local fs = require("@lune/fs") | ||
local process = require("@lune/process") | ||
|
||
local crayon = require("./lib/crayon") | ||
|
||
local cwd = process.cwd:gsub("\\", "/"):gsub("/$", "") | ||
local src = `{cwd}/src` | ||
local tests = `{src}/__tests__` | ||
|
||
local IGNORED_FILES = { | ||
`{src}/Array/init.luau`, | ||
`{src}/Dictionary/init.luau`, | ||
`{src}/Set/init.luau`, | ||
`{src}/init.luau`, | ||
`{src}/None.luau`, | ||
`{src}/Util.luau`, | ||
} | ||
|
||
local function get_file_paths(root: string) | ||
local paths = {} | ||
|
||
for _, path in fs.readDir(root) do | ||
local fullPath = `{root}/{path}` | ||
|
||
if fs.isFile(fullPath) then | ||
table.insert(paths, fullPath) | ||
continue | ||
end | ||
|
||
if fs.isDir(fullPath) and fullPath == tests then | ||
continue | ||
end | ||
|
||
for _, subpath in get_file_paths(fullPath) do | ||
table.insert(paths, subpath) | ||
end | ||
end | ||
|
||
return paths | ||
end | ||
|
||
local function main() | ||
local files = get_file_paths(src) | ||
local missing = 0 | ||
|
||
for _, file in files do | ||
if not file:match("%.luau$") or table.find(IGNORED_FILES, file) then | ||
continue | ||
end | ||
|
||
local relativePath = file:sub(#src + 2) | ||
local testFilePath = (`{tests}/{relativePath}`):gsub("%.luau$", ".spec.luau") | ||
|
||
if not fs.isFile(testFilePath) then | ||
print( | ||
crayon.label("MISSING", crayon.bgRed), | ||
"No test found for", | ||
crayon.yellow(`"./{relativePath}"`) | ||
) | ||
|
||
missing += 1 | ||
continue | ||
end | ||
end | ||
|
||
if missing > 0 then | ||
print( | ||
crayon.label("FAIL", crayon.bgRed), | ||
"Missing", | ||
crayon.bold(tostring(missing)), | ||
"test files." | ||
) | ||
|
||
process.exit(1) | ||
end | ||
end | ||
|
||
main() |