-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.lua
More file actions
executable file
·129 lines (112 loc) · 3.44 KB
/
run_tests.lua
File metadata and controls
executable file
·129 lines (112 loc) · 3.44 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
#!/usr/bin/env nvim -l
-- Simple test runner for context-graph.nvim
-- Run with: nvim -l run_tests.lua
-- Setup test environment
vim.opt.runtimepath:append(".")
-- Add test vendor dependencies
local vendor_path = vim.fn.fnamemodify("tests/vendor/nvim-lspconfig", ":p")
if vim.fn.isdirectory(vendor_path) == 1 then
vim.opt.runtimepath:append(vendor_path)
end
_G.test_results = { passed = 0, failed = 0, errors = {} }
-- Simple test framework
local current_suite = {}
_G.describe = function(name, fn)
print("\n" .. name)
current_suite = { before_each = nil, after_each = nil }
fn()
current_suite = {}
end
_G.pending = function(reason)
print(" ⚠ PENDING: " .. reason)
-- Skip the rest of the test
error("__PENDING__", 0)
end
_G.before_each = function(fn)
current_suite.before_each = fn
end
_G.after_each = function(fn)
current_suite.after_each = fn
end
_G.it = function(desc, fn)
-- Run before_each if defined
if current_suite.before_each then
local ok, err = pcall(current_suite.before_each)
if not ok then
if err == "__PENDING__" then
return -- Skip all tests in pending suite
end
_G.test_results.failed = _G.test_results.failed + 1
print(" ✗ " .. desc)
print(" BEFORE_EACH ERROR: " .. tostring(err))
return
end
end
local ok, err = pcall(fn)
-- Run after_each if defined
if current_suite.after_each then
pcall(current_suite.after_each)
end
if ok then
_G.test_results.passed = _G.test_results.passed + 1
print(" ✓ " .. desc)
elseif err == "__PENDING__" then
-- Already printed by pending(), don't count as failure
return
else
_G.test_results.failed = _G.test_results.failed + 1
print(" ✗ " .. desc)
print(" " .. tostring(err))
table.insert(_G.test_results.errors, { desc = desc, err = err })
end
end
-- Load and run test file(s)
if vim.env.TEST_FILE then
-- Run specific test file
print("\nRunning: " .. vim.env.TEST_FILE)
dofile(vim.env.TEST_FILE)
else
-- Run all test files
-- Get test files but exclude vendor directory
local all_files = vim.fn.globpath("tests", "**/*_spec.lua", false, true)
local test_files = {}
for _, file in ipairs(all_files) do
if not file:match("vendor/") then
table.insert(test_files, file)
end
end
for _, file in ipairs(test_files) do
-- Skip old mocked integration tests and the separate tsserver runner
if not file:match("lsp_integration_spec") and
not file:match("lsp_integration_simple") and
not file:match("lsp_real_tsserver_spec") then
print("\nRunning: " .. file)
dofile(file)
end
end
-- Run real LSP tests if we have lspconfig and tsserver
local has_lspconfig = pcall(require, 'lspconfig')
if has_lspconfig and vim.fn.executable('npx') == 1 then
print("\nRunning: tests/lsp_integration_proper_spec.lua (REAL TSSERVER with lspconfig)")
dofile("tests/lsp_integration_proper_spec.lua")
else
if not has_lspconfig then
print("\nSkipping real LSP tests - nvim-lspconfig not found")
else
print("\nSkipping real LSP tests - npx not found")
end
end
end
-- Summary
print("\n" .. string.rep("=", 50))
print(string.format("Tests: %d passed, %d failed",
_G.test_results.passed, _G.test_results.failed))
if #_G.test_results.errors > 0 then
print("\nFailures:")
for _, err in ipairs(_G.test_results.errors) do
print(" - " .. err.desc)
print(" " .. err.err)
end
os.exit(1)
end
os.exit(0)