forked from slembcke/debugger.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
115 lines (89 loc) · 2.02 KB
/
test.lua
File metadata and controls
115 lines (89 loc) · 2.02 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
local tests = require("test_util")
local dbg = require("debugger")
local function do_nothing() end
local function func1()
dbg()
end
local function func2()
func1()
_ = _ -- nop padding
end
local function func3()
func2()
do_nothing()
end
tests.run_test(tests.step, function()
func3()
end)
tests.run_test(tests.next, function()
func3()
end)
tests.run_test(tests.finish, function()
func3()
end)
tests.run_test(tests.continue, function()
func3()
func3()
func3()
end)
tests.run_test(tests.trace, function()
func3()
end)
tests.run_test(tests.updown, function()
func3()
end)
local func_from_string = (loadstring or load)[[
require("debugger")()
_ = _
]]
tests.run_test(tests.where, function()
func3()
func_from_string()
end)
GLOBAL = false
local upvar = false
tests.run_test(tests.eval, function()
local var = false
dbg()
if not var then tests.print_red "ERROR: local variable not set" end
dbg()
if not upvar then tests.print_red "ERROR: upvalue not set" end
dbg()
if not GLOBAL then tests.print_red "ERROR: global variable not set" end
end)
tests.run_test(tests.print, function()
dbg()
end)
tests.run_test(tests.locals, function()
local var = upvar and "foobar"
dbg()
-- Need a no-op here.
-- Lua 5.1 variables go out of scope right before 'end'
-- All other versions go out of scope right after.
_ = _
end)
tests.run_test(tests.assert_pass, function()
dbg.assert(true)
dbg.assert(true, "should not trigger")
end)
tests.run_test(tests.assert_fail, function()
local _, err = pcall(function() dbg.assert(false) end)
assert(err)
end)
tests.run_test(tests.assert_message, function()
local msg = "should trigger"
local _, err = pcall(function() dbg.assert(false, msg) end)
assert(msg)
end)
tests.run_test(tests.error, function()
pcall(function() dbg.error() end)
end)
tests.run_test(tests.error_message, function()
local msg = "this error message"
local _, err = pcall(function() dbg.error(msg) end)
assert(msg)
end)
tests.run_test(tests.inspect, function()
func3()
end)
tests.print_green "TESTS COMPLETE"