You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
Plaintext

local file = require("pl.file")
local path = require("pl.path")
local type Busted = record
publish: function
end
local type Info = record
traceback: string
short_src: string
end
local teal_available, tl = pcall(require, 'tl')
local rewrite_filename = function(filename: string): string
return filename:match('string "(.+)"') or filename
end
local rewriteMessage = function(_filename: string, message: string): string
local fname, line, msg = message:match('^([^\n]-):(%d+): (.*)')
if not fname then
return message
end
fname = rewrite_filename(fname)
return fname .. ':' .. tostring(line) .. ': ' .. msg
end
local getTrace = function(_filename: string, info: Info): Info
local index = info.traceback:find('\n%s*%[C]')
info.traceback = info.traceback:sub(1, index)
info.short_src = rewrite_filename(info.short_src)
return info
end
local record ret
end
function ret.match(_busted: Busted, filename: string): boolean
return teal_available and path.extension(filename) == '.tl'
end
function ret.load(busted: Busted, filename: string): function, function, function
local content = file.read(filename)
local program, err = tl.load(content, filename)
if not program then
busted.publish({ 'error', 'file' }, { descriptor = 'file', name = filename }, nil, err, {})
end
return program, getTrace, rewriteMessage
end
return ret