Skip to content

Commit 0447514

Browse files
committed
Recover subject name when called with pcall to get proper error messages
1 parent 72f29bf commit 0447514

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

lua/gluatest/expectations/negative.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ return function( subject, ... )
178178
function expectations.succeed()
179179
assert( TypeID( subject ) == TYPE_FUNCTION, ".succeed expects a function" )
180180

181+
jit.off( subject, false )
181182
local success = pcall( subject, unpack( args ) )
182183

183184
if success ~= false then
@@ -189,6 +190,7 @@ return function( subject, ... )
189190
function expectations.err()
190191
assert( TypeID( subject ) == TYPE_FUNCTION, ".err expects a function" )
191192

193+
jit.off( subject, false )
192194
local success = pcall( subject, unpack( args ) )
193195

194196
if success ~= true then
@@ -202,6 +204,7 @@ return function( subject, ... )
202204
assert( TypeID( subject ) == TYPE_FUNCTION, ".errWith expects a function" )
203205
assert( isstring( comparison ), "errWith expects a string" )
204206

207+
jit.off( subject, false )
205208
local success, err = pcall( subject, unpack( args ) )
206209

207210
if success == true then

lua/gluatest/expectations/positive.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ return function( subject, ... )
177177
function expectations.succeed()
178178
assert( TypeID( subject ) == TYPE_FUNCTION, ".succeed expects a function" )
179179

180+
jit.off( subject, false )
180181
local success, err = pcall( subject, unpack( args ) )
181182

182183
if success == false then
@@ -188,6 +189,7 @@ return function( subject, ... )
188189
function expectations.err()
189190
assert( TypeID( subject ) == TYPE_FUNCTION, ".err expects a function" )
190191

192+
jit.off( subject, false )
191193
local success = pcall( subject, unpack( args ) )
192194

193195
if success == true then
@@ -201,6 +203,7 @@ return function( subject, ... )
201203
assert( TypeID( subject ) == TYPE_FUNCTION, ".errWith expects a function" )
202204
assert( TypeID( comparison ) == TYPE_STRING, ".errWith expects a string" )
203205

206+
jit.off( subject, false )
204207
local success, err = pcall( subject, unpack( args ) )
205208

206209
if success == true then
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---@diagnostic disable: param-type-mismatch
2+
return {
3+
groupName = "callerRecovery",
4+
cases = {
5+
{
6+
name = "Called function name is included in error message",
7+
func = function()
8+
-- This never worked, instead of 'Left' it had given '?'
9+
expect( string.Left, nil ).to.errWith( "bad argument #1 to 'Left' (string expected, got nil)" )
10+
11+
-- This is how it always had worked fine
12+
local testFunc = function() string.Left( nil, nil ) end
13+
expect( testFunc ).to.errWith( "bad argument #1 to 'Left' (string expected, got nil)" )
14+
end
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)