-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_check.lua
More file actions
103 lines (97 loc) · 3.2 KB
/
Copy pathrun_check.lua
File metadata and controls
103 lines (97 loc) · 3.2 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
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env lua
local FILES = {
"main.lua",
"run_build.lua",
"run_check.lua",
"run_tests.lua",
"src/cli.lua",
"src/lexer.lua",
"src/parser.lua",
"src/scope_resolver.lua",
"src/stdlib_analyzer.lua",
"src/stdlib_selector.lua",
"src/ITranspiler.lua",
"src/stdlib/bash/base.lua",
"src/stdlib/bash/io.lua",
"src/stdlib/bash/math.lua",
"src/stdlib/bash/os.lua",
"src/stdlib/bash/string.lua",
"src/stdlib/bash/table.lua",
"src/stdlib/powershell/base.lua",
"src/stdlib/powershell/io.lua",
"src/stdlib/powershell/math.lua",
"src/stdlib/powershell/os.lua",
"src/stdlib/powershell/string.lua",
"src/stdlib/powershell/table.lua",
"src/bash_transpiler.lua",
"src/ps1_transpiler.lua",
"src/shlua.lua",
"tests/lexer.test.lua",
"tests/parser.test.lua",
"tests/bash_transpiler.test.lua",
"tests/ps1_transpiler.test.lua",
"tests/coroutine.test.lua",
"tests/integration.test.lua",
"tests/stdlib_analyzer.test.lua",
"tests/dist.test.lua",
"tests/script_test_helper.lua",
"tests/stdlib_conformance.lua",
"tests/fixtures/hard_test.lua",
"tests/scripts/00_minimal.test.lua",
"tests/scripts/01_variables.test.lua",
"tests/scripts/02_conditionals.test.lua",
"tests/scripts/03_loops.test.lua",
"tests/scripts/04_functions.test.lua",
"tests/scripts/05_closures.test.lua",
"tests/scripts/06_coroutines.test.lua",
"tests/scripts/07_complex.test.lua",
"tests/scripts/08_bash_stdlib.test.lua",
"tests/scripts/09_powershell_stdlib.test.lua",
"tests/scripts/10_hard_test.test.lua",
"tests/scripts/11_tables.test.lua",
}
local function runCommand(command)
local handle = assert(io.popen(command .. " 2>&1"))
local output = handle:read("*a")
local success, _, code = handle:close()
return success and (not code or code == 0), output
end
local function runCheck(name, command)
io.write("Running " .. name .. "... ")
local ok, output = runCommand(command)
if ok then
print("OK")
return true
end
print("FAILED")
io.write(output)
if output:sub(-1) ~= "\n" then
print()
end
return false
end
local function quotedFiles()
local values = {}
for _, path in ipairs(FILES) do
table.insert(values, '"' .. path .. '"')
end
return table.concat(values, " ")
end
print("=== ShLua Code Quality Checks ===")
local files = quotedFiles()
local allPassed = true
allPassed = runCheck("build + bundle syntax", "lua run_build.lua") and allPassed
allPassed = runCheck("Lua syntax (luac -p)", "luac -p " .. files .. ' "dist/shlua.lua"') and allPassed
allPassed = runCheck("StyLua format", "stylua --check -- " .. files) and allPassed
allPassed = runCheck("Luacheck", "luacheck " .. files) and allPassed
allPassed = runCheck("bundled CLI", "lua dist/shlua.lua --help") and allPassed
local apiCheck = "lua -e \"package.path='dist/?.lua'; local l=require('shlua'); "
.. "assert(type(l.transpile('print(1)','bash'))=='string')\""
allPassed = runCheck("bundled reusable API", apiCheck) and allPassed
print()
if allPassed then
print("=== ALL CHECKS PASSED ===")
os.exit(0)
end
print("=== SOME CHECKS FAILED ===")
os.exit(1)