Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing assertion message to include asserted values properly (with ... #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/assertions_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('assertions', function()
local M = require 'telescope'

it('should correctly print arguments asserions', function()
local res, err = pcall(function() assert_equal(1, 2) end)
assert(res == false)
assert(err[1] == "Assert failed: expected '1' to be equal to '2'")
end)
end)
14 changes: 7 additions & 7 deletions telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ local function make_assertion(name, message, func)
local a = {}
local args = {...}
local nargs = select('#', ...)
if nargs > num_vars then
if nargs > num_vars then
local userErrorMessage = args[num_vars+1]
if type(userErrorMessage) == "string" then
return(assertion_message_prefix .. userErrorMessage)
else
error(string.format('assert_%s expected %d arguments but got %d', name, num_vars, #args))
end
end
for i = 1, nargs do a[i] = tostring(v) end
for i = 1, nargs do a[i] = tostring(args[i]) end
for i = nargs+1, num_vars do a[i] = 'nil' end
return (assertion_message_prefix .. message):format(unpack(a))
end
Expand Down Expand Up @@ -443,12 +443,12 @@ local function run(contexts, callbacks, test_filter)
table.sort(ancestors)
-- this "before" is the test callback passed into the runner
invoke_callback("before", result)

-- run all the "before" blocks/functions
for _, a in ipairs(ancestors) do
if contexts[a].before then
if contexts[a].before then
setfenv(contexts[a].before, env)
contexts[a].before()
contexts[a].before()
end
end

Expand All @@ -465,9 +465,9 @@ local function run(contexts, callbacks, test_filter)
-- Run all the "after" blocks/functions
table.reverse(ancestors)
for _, a in ipairs(ancestors) do
if contexts[a].after then
if contexts[a].after then
setfenv(contexts[a].after, env)
contexts[a].after()
contexts[a].after()
end
end

Expand Down