feat: Add validation for test files structure based on lua_test devDependency

This commit is contained in:
2025-12-30 02:20:29 +00:00
parent 9bf6dc4af0
commit 7c2ea0b417

View File

@@ -174,6 +174,52 @@ function M.validate_naming_conventions(package_path, metadata)
return errors, warnings
end
-- Validate test files structure
function M.validate_test_structure(package_path, metadata)
local errors = {}
local warnings = {}
-- Check if lua_test is a devDependency
local has_lua_test = false
if metadata.devDependencies then
for _, dep in ipairs(metadata.devDependencies) do
if dep == "lua_test" then
has_lua_test = true
break
end
end
end
if not has_lua_test then
-- No lua_test, tests are optional
return errors, warnings
end
local tests_path = package_path .. "/scripts/tests"
-- Check for common test files
local common_tests = {
"metadata.test.lua",
"components.test.lua"
}
local found_tests = false
for _, test_file in ipairs(common_tests) do
local test_path = tests_path .. "/" .. test_file
local file = io.open(test_path, "r")
if file then
file:close()
found_tests = true
end
end
if not found_tests then
table.insert(warnings, "No test files found (metadata.test.lua, components.test.lua) despite lua_test devDependency")
end
return errors, warnings
end
-- Validate complete package structure
function M.validate_package_structure(package_path, metadata)
local results = {
@@ -222,6 +268,16 @@ function M.validate_package_structure(package_path, metadata)
table.insert(results.warnings, warn)
end
-- Test structure (only if lua_test is a devDependency)
local test_errors, test_warnings = M.validate_test_structure(package_path, metadata)
for _, err in ipairs(test_errors) do
table.insert(results.errors, err)
results.valid = false
end
for _, warn in ipairs(test_warnings) do
table.insert(results.warnings, warn)
end
return results
end