From 7ef8929a8ef9abed1877d31e5e9426af512b0dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Wed, 17 Jul 2019 19:03:45 +0000 Subject: tests: readme: improve error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- test/readme.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'test/readme.lua') diff --git a/test/readme.lua b/test/readme.lua index 6f63276..35d934e 100644 --- a/test/readme.lua +++ b/test/readme.lua @@ -48,17 +48,24 @@ local env = { require = require, } +local function run_error(code, err) + print() + print('code:', code) + print('error:', err) + print() + return { true, nil, n=3 } +end + local function run(name, code) - local f = assert(load(code, name, 't', env)) + local f, err = load(code, name, 't', env) + if not f then + return run_error(code, err) + end local ret = pack(pcall(f)) if ret[1] then return ret else - print() - print('code:', code) - print('error:', ret[2]) - print() - return { true, nil, n=3 } + return run_error(code, ret[2]) end end -- cgit v1.2.1