-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_tests.lua
More file actions
executable file
·228 lines (192 loc) · 5.83 KB
/
Copy pathrun_all_tests.lua
File metadata and controls
executable file
·228 lines (192 loc) · 5.83 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env lua
-- Comprehensive test runner that actually runs all the spec files
package.path = "./?.lua;./lua/?.lua;./lua/ansillary/?.lua;./tests/?.lua;" .. package.path
-- Global test state
local total_tests_passed = 0
local total_tests_failed = 0
local current_describe = ""
local current_suite = ""
local failed_tests = {}
-- Test framework functions
local function describe(name, fn)
current_describe = name
print("\n📁 " .. current_suite .. " > " .. name)
fn()
end
-- Store before_each functions
local before_each_functions = {}
local function before_each(fn)
table.insert(before_each_functions, fn)
end
local function reset_before_each()
before_each_functions = {}
end
local function run_before_each()
for _, fn in ipairs(before_each_functions) do
fn()
end
end
local function it(name, fn)
-- Run before_each functions before each test
run_before_each()
local success, err = pcall(fn)
if success then
print(" ✅ " .. name)
total_tests_passed = total_tests_passed + 1
else
local full_test_name = current_suite .. " > " .. current_describe .. " > " .. name
print(" ❌ " .. name)
print(" 💥 " .. tostring(err))
table.insert(failed_tests, {
name = full_test_name,
error = tostring(err)
})
total_tests_failed = total_tests_failed + 1
end
end
-- Comprehensive assert library
local assert = {}
assert.are = {}
assert.are.equal = function(expected, actual, message)
if expected ~= actual then
local msg = (message or "") .. " Expected: " .. tostring(expected) .. ", got: " .. tostring(actual)
error(msg)
end
end
assert.are.same = function(expected, actual, message)
-- Deep table comparison
local function deep_equal(t1, t2)
if type(t1) ~= type(t2) then return false end
if type(t1) ~= "table" then return t1 == t2 end
for k, v in pairs(t1) do
if not deep_equal(v, t2[k]) then return false end
end
for k, v in pairs(t2) do
if not deep_equal(v, t1[k]) then return false end
end
return true
end
if not deep_equal(expected, actual) then
local msg = (message or "") .. " Tables are not equal"
error(msg)
end
end
assert.is_true = function(value, message)
if not value then
error((message or "") .. " Expected true, got: " .. tostring(value))
end
end
assert.is_false = function(value, message)
if value then
error((message or "") .. " Expected false, got: " .. tostring(value))
end
end
assert.is_nil = function(value, message)
if value ~= nil then
error((message or "") .. " Expected nil, got: " .. tostring(value))
end
end
assert.is_not_nil = function(value, message)
if value == nil then
error((message or "") .. " Expected not nil, got nil")
end
end
assert.is_table = function(value, message)
if type(value) ~= "table" then
error((message or "") .. " Expected table, got: " .. type(value))
end
end
assert.is_string = function(value, message)
if type(value) ~= "string" then
error((message or "") .. " Expected string, got: " .. type(value))
end
end
assert.is_boolean = function(value, message)
if type(value) ~= "boolean" then
error((message or "") .. " Expected boolean, got: " .. type(value))
end
end
assert.has_no = {}
assert.has_no.errors = function(fn, message)
local success, err = pcall(fn)
if not success then
error((message or "") .. " Unexpected error: " .. tostring(err))
end
end
assert.has = {}
assert.has.errors = function(fn, message)
local success, err = pcall(fn)
if success then
error((message or "") .. " Expected an error but none occurred")
end
end
-- Make globals available to spec files
_G.describe = describe
_G.it = it
_G.before_each = before_each
_G.assert = assert
-- Function to run a spec file
local function run_spec_file(filepath)
current_suite = filepath:match("([^/]+)_spec%.lua$") or filepath
print("\n🧪 Running " .. filepath)
-- Reset before_each functions for each spec file
reset_before_each()
-- Set up fresh environment for each spec file
local helper = require("tests.test_helper")
helper.setup_vim_mock()
-- Clear module cache before each spec file
for module_name, _ in pairs(package.loaded) do
if module_name:match("^ansillary") then
package.loaded[module_name] = nil
end
end
local success, err = pcall(dofile, filepath)
if not success then
print("❌ Failed to load spec file " .. filepath .. ": " .. tostring(err))
table.insert(failed_tests, {
name = current_suite .. " > SPEC FILE LOAD ERROR",
error = tostring(err)
})
total_tests_failed = total_tests_failed + 1
end
end
-- List of spec files to run
local spec_files = {
"tests/unit/regex_spec.lua",
"tests/unit/config_spec.lua",
"tests/unit/highlights_spec.lua",
"tests/unit/init_spec.lua",
"tests/integration/full_integration_spec.lua",
}
print("🚀 Running comprehensive test suite for ansillary.nvim")
print("=" .. string.rep("=", 50))
-- Run all spec files
for _, spec_file in ipairs(spec_files) do
local file = io.open(spec_file, "r")
if file then
file:close()
run_spec_file(spec_file)
else
print("❌ Spec file not found: " .. spec_file)
total_tests_failed = total_tests_failed + 1
end
end
-- Print results summary
print("\n" .. "=" .. string.rep("=", 50))
print(string.format("📊 Final Results: %d passed, %d failed", total_tests_passed, total_tests_failed))
if total_tests_failed > 0 then
print("\n❌ Failed tests:")
for i, failed_test in ipairs(failed_tests) do
print(string.format(" %d. %s", i, failed_test.name))
-- Optionally show the error in a shortened format
local short_error = failed_test.error:match("^[^:]*:[^:]*: (.*)") or failed_test.error
if #short_error > 80 then
short_error = short_error:sub(1, 77) .. "..."
end
print(string.format(" → %s", short_error))
end
os.exit(1)
else
print("✅ All tests passed!")
os.exit(0)
end