adding more tests
This commit is contained in:
parent
8b83bde7cb
commit
68cb653dd5
|
@ -512,8 +512,9 @@ end
|
|||
|
||||
-- Works like assert(), but invokes the debugger on a failure.
|
||||
function dbg.assert(condition, message)
|
||||
message = message or "assertion failed!"
|
||||
if not condition then
|
||||
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..(message or "assertion failed!"))
|
||||
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..message)
|
||||
dbg(false, 1, "dbg.assert()")
|
||||
end
|
||||
|
||||
|
|
|
@ -82,4 +82,30 @@ tests.run_test(tests.locals, function()
|
|||
_ = _
|
||||
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.print_green "TESTS COMPLETE"
|
||||
|
|
|
@ -23,7 +23,7 @@ local LOG_IO = false
|
|||
|
||||
function string.strip(str) return str:match("^%s*(.-)%s*$") end
|
||||
|
||||
local module = {}
|
||||
local tests = {}
|
||||
|
||||
-- Debugger command line string to run next.
|
||||
local commands = {}
|
||||
|
@ -74,13 +74,13 @@ local function ignore()
|
|||
if LOG_IO then print(str) end
|
||||
end
|
||||
|
||||
function module.repl(_, test_body)
|
||||
function tests.repl(_, test_body)
|
||||
dbg.read = dbg_read
|
||||
dbg.write = dbg_write
|
||||
test_body()
|
||||
end
|
||||
|
||||
function module.run_test(test, test_body)
|
||||
function tests.run_test(test, test_body)
|
||||
local coro = coroutine.create(test)
|
||||
coroutine.resume(coro)
|
||||
|
||||
|
@ -93,7 +93,7 @@ function module.run_test(test, test_body)
|
|||
end
|
||||
end
|
||||
|
||||
function module.step()
|
||||
function tests.step()
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "s"
|
||||
expect "test.lua:12 in upvalue 'func2'"; cmd "s"
|
||||
expect "test.lua:13 in upvalue 'func2'"; cmd "s"
|
||||
|
@ -104,7 +104,7 @@ function module.step()
|
|||
print_green "STEP TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.next()
|
||||
function tests.next()
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "n"
|
||||
expect "test.lua:12 in upvalue 'func2'"; cmd "n"
|
||||
expect "test.lua:13 in upvalue 'func2'"; cmd "n"
|
||||
|
@ -114,7 +114,7 @@ function module.next()
|
|||
print_green "NEXT TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.finish()
|
||||
function tests.finish()
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "f"
|
||||
expect "test.lua:12 in upvalue 'func2'"; cmd "f"
|
||||
expect "test.lua:17 in upvalue 'func3'"; cmd "f"
|
||||
|
@ -122,14 +122,14 @@ function module.finish()
|
|||
print_green "FINISH TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.continue()
|
||||
function tests.continue()
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "c"
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "c"
|
||||
expect "break via dbg() => test.lua:8 in upvalue 'func1'"; cmd "c"
|
||||
print_green "CONTINUE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.trace()
|
||||
function tests.trace()
|
||||
ignore(); -- Stack frame info that will be in the trace anyway.
|
||||
|
||||
cmd "t"
|
||||
|
@ -146,7 +146,7 @@ function module.trace()
|
|||
print_green "TRACE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.updown()
|
||||
function tests.updown()
|
||||
ignore();
|
||||
|
||||
cmd "u"
|
||||
|
@ -174,7 +174,7 @@ function module.updown()
|
|||
print_green "UP/DOWN TESTES COMPLETE"
|
||||
end
|
||||
|
||||
function module.where()
|
||||
function tests.where()
|
||||
ignore()
|
||||
|
||||
cmd "w 1"
|
||||
|
@ -193,7 +193,7 @@ function module.where()
|
|||
print_green "WHERE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.eval()
|
||||
function tests.eval()
|
||||
ignore(); cmd "e var = true"
|
||||
expect "debugger.lua => Set local variable var"; cmd "c"
|
||||
|
||||
|
@ -206,7 +206,7 @@ function module.eval()
|
|||
print_green "EVAL TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.print()
|
||||
function tests.print()
|
||||
ignore()
|
||||
|
||||
-- Basic types
|
||||
|
@ -239,7 +239,7 @@ function module.print()
|
|||
print_green "PRINT TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function module.locals()
|
||||
function tests.locals()
|
||||
ignore()
|
||||
|
||||
cmd "l"
|
||||
|
@ -250,6 +250,39 @@ function module.locals()
|
|||
print_green "LOCALS TESTS COMPLETE"
|
||||
end
|
||||
|
||||
module.print_red = print_red
|
||||
module.print_green = print_green
|
||||
return module
|
||||
function tests.assert_pass()
|
||||
-- Should run without failure
|
||||
print_green "ASSERT PASS TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function tests.assert_fail()
|
||||
expect "ERROR: assertion failed!"
|
||||
cmd "c"
|
||||
expect "break via dbg.assert() => test.lua:91 in chunk at test.lua:91"
|
||||
print_green "ASSERT FAIL TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function tests.assert_message()
|
||||
expect "ERROR: should trigger"
|
||||
cmd "c"
|
||||
expect "break via dbg.assert() => test.lua:97 in chunk at test.lua:97"
|
||||
print_green "ASSERT MESSAGE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function tests.error()
|
||||
expect "ERROR: nil"
|
||||
cmd "c"
|
||||
expect "break via dbg.error() => test.lua:102 in chunk at test.lua:102"
|
||||
print_green "ASSERT MESSAGE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
function tests.error_message()
|
||||
expect 'ERROR: "this error message"'
|
||||
cmd "c"
|
||||
expect "break via dbg.error() => test.lua:107 in chunk at test.lua:107"
|
||||
print_green "ASSERT MESSAGE TESTS COMPLETE"
|
||||
end
|
||||
|
||||
tests.print_red = print_red
|
||||
tests.print_green = print_green
|
||||
return tests
|
||||
|
|
Loading…
Reference in New Issue