From abdfd7835410d060c50b6108da581258ee2bafc8 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 8 Mar 2014 23:00:47 +0000 Subject: [PATCH] Added tester.test.error() to tester.lua script --- test/tester.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/tester.lua b/test/tester.lua index 99fe7aa..8a3319b 100644 --- a/test/tester.lua +++ b/test/tester.lua @@ -128,6 +128,18 @@ function tester.test.equal(result, expected) end +function tester.test.error(fn, ...) + local passed = not pcall(fn, ...) + local info = debug.getinfo(2) + if passed then + dopass(info.short_src, info.currentline) + else + dofail(info.short_src, info.currentline) + printfailmsg("Expected an error to be raised") + end +end + + function tester.dotests(t) local keys = {} for k in pairs(t) do table.insert(keys, k) end