-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_runner.lua
More file actions
135 lines (119 loc) · 2.76 KB
/
test_runner.lua
File metadata and controls
135 lines (119 loc) · 2.76 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
#!/usr/bin/env lua
package.path = package.path .. ";./lua/?.lua;./lua/?/init.lua"
local function run_lua_tests()
print("Running Lua tests for im-switch plugin...")
local test_module = require("im-switch.init_test")
local success = test_module.run_all_tests()
return success
end
local function run_integration_test()
print("\nRunning integration test...")
local im_switch = require("im-switch.init")
_G.vim = {
fn = {
has = function(feature)
if feature == "mac" or feature == "macunix" then
return 1
elseif feature == "unix" then
return 1
end
return 0
end,
executable = function(path)
return 1
end,
fnamemodify = function(path, modifier)
return "./im-switch"
end,
},
tbl_deep_extend = function(behavior, ...)
local result = {}
for _, t in ipairs({ ... }) do
for k, v in pairs(t) do
result[k] = v
end
end
return result
end,
api = {
nvim_create_augroup = function(name, opts)
return 1
end,
nvim_create_autocmd = function(events, opts) end,
},
notify = function(msg, level)
print("NOTIFY: " .. msg)
end,
log = { levels = { WARN = 1 } },
split = function(str, delimiter)
local result = {}
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end,
}
_G.debug = {
getinfo = function(level, what)
return { source = "@" .. os.getenv("PWD") .. "/lua/im-switch/init.lua" }
end,
}
_G.io = {
popen = function(cmd)
local handle = io.popen(cmd .. " 2>&1")
if not handle then
return {
read = function()
return ""
end,
close = function()
return false
end,
}
end
return handle
end,
}
local success, err = pcall(function()
im_switch.setup({ debug = true })
local current = im_switch.get_current()
if current and current ~= "" then
print("✓ get_current: " .. current)
else
print("✗ get_current returned empty or nil")
end
local inputs = im_switch.list_inputs()
if inputs and #inputs > 0 then
print("✓ list_inputs: found " .. #inputs .. " inputs")
for i, input in ipairs(inputs) do
if i <= 3 then
print(" - " .. input)
end
end
if #inputs > 3 then
print(" ... and " .. (#inputs - 3) .. " more")
end
else
print("✗ list_inputs returned empty or nil")
end
end)
if not success then
print("✗ Integration test failed: " .. err)
return false
end
print("✓ Integration test completed")
return true
end
local function main()
local lua_success = run_lua_tests()
local integration_success = run_integration_test()
print("\n" .. string.rep("=", 50))
if lua_success and integration_success then
print("All tests passed!")
os.exit(0)
else
print("Some tests failed!")
os.exit(1)
end
end
main()