Skip to content

Commit add3e80

Browse files
authored
chore(luassert): bump to v1.9.0 (#413)
1 parent 905090a commit add3e80

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

lua/luassert/assert.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ local __state_meta = {
4242
local arguments = util.make_arglist(...)
4343
local val, retargs = assertion.callback(self, arguments, util.errorlevel())
4444

45-
if not val == self.mod then
45+
if (not val) == self.mod then
4646
local message = assertion.positive_message
4747
if not self.mod then
4848
message = assertion.negative_message

lua/luassert/assertions.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ local function error_matches(state, arguments, level)
238238
end
239239

240240
-- err_actual must be (convertible to) a string
241-
if util.hastostring(err_actual) then
241+
if util.hastostring(err_actual) or
242+
type(err_actual) == "number" or
243+
type(err_actual) == "boolean" then
242244
err_actual = tostring(err_actual)
243245
retargs[1] = err_actual
244246
end

lua/luassert/formatters/init.lua

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@ local assert = require('luassert.assert')
33
local match = require('luassert.match')
44
local util = require('luassert.util')
55

6-
local colors = setmetatable({
7-
none = function(c) return c end
8-
},{ __index = function(self, key)
6+
local isatty, colors do
97
local ok, term = pcall(require, 'term')
10-
local isatty = io.type(io.stdout) == 'file' and ok and term.isatty(io.stdout)
11-
if not ok or not isatty or not term.colors then
12-
return function(c) return c end
8+
isatty = io.type(io.stdout) == 'file' and ok and term.isatty(io.stdout)
9+
if not isatty then
10+
local isWindows = package.config:sub(1,1) == '\\'
11+
if isWindows and os.getenv("ANSICON") then
12+
isatty = true
13+
end
1314
end
14-
return function(c)
15-
for token in key:gmatch("[^%.]+") do
16-
c = term.colors[token](c)
15+
16+
colors = setmetatable({
17+
none = function(c) return c end
18+
},{ __index = function(self, key)
19+
return function(c)
20+
for token in key:gmatch("[^%.]+") do
21+
c = term.colors[token](c)
22+
end
23+
return c
1724
end
18-
return c
1925
end
26+
})
2027
end
21-
})
2228

2329
local function fmt_string(arg)
2430
if type(arg) == "string" then
@@ -122,7 +128,7 @@ local function fmt_table(arg, fmtargs)
122128
local tmax = assert:get_parameter("TableFormatLevel")
123129
local showrec = assert:get_parameter("TableFormatShowRecursion")
124130
local errchar = assert:get_parameter("TableErrorHighlightCharacter") or ""
125-
local errcolor = assert:get_parameter("TableErrorHighlightColor") or "none"
131+
local errcolor = assert:get_parameter("TableErrorHighlightColor")
126132
local crumbs = fmtargs and fmtargs.crumbs or {}
127133
local cache = {}
128134
local type_desc
@@ -246,4 +252,4 @@ assert:add_formatter(fmt_arglist)
246252
assert:set_parameter("TableFormatLevel", 3)
247253
assert:set_parameter("TableFormatShowRecursion", false)
248254
assert:set_parameter("TableErrorHighlightCharacter", "*")
249-
assert:set_parameter("TableErrorHighlightColor", "none")
255+
assert:set_parameter("TableErrorHighlightColor", isatty and "red" or "none")

lua/luassert/languages/en.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ s:set("assertion.called_at_most.positive", "Expected to be called at most %s tim
3434
s:set("assertion.called_more_than.positive", "Expected to be called more than %s time(s), but was called %s time(s)")
3535
s:set("assertion.called_less_than.positive", "Expected to be called less than %s time(s), but was called %s time(s)")
3636

37-
s:set("assertion.called_with.positive", "Function was not called with the arguments")
38-
s:set("assertion.called_with.negative", "Function was called with the arguments")
37+
s:set("assertion.called_with.positive", "Function was never called with matching arguments.\nCalled with (last call if any):\n%s\nExpected:\n%s")
38+
s:set("assertion.called_with.negative", "Function was called with matching arguments at least once.\nCalled with (last matching call):\n%s\nDid not expect:\n%s")
3939

40-
s:set("assertion.returned_with.positive", "Function was not returned with the arguments")
41-
s:set("assertion.returned_with.negative", "Function was returned with the arguments")
40+
s:set("assertion.returned_with.positive", "Function never returned matching arguments.\nReturned (last call if any):\n%s\nExpected:\n%s")
41+
s:set("assertion.returned_with.negative", "Function returned matching arguments at least once.\nReturned (last matching call):\n%s\nDid not expect:\n%s")
4242

4343
s:set("assertion.returned_arguments.positive", "Expected to be called with %s argument(s), but was called with %s")
4444
s:set("assertion.returned_arguments.negative", "Expected not to be called with %s argument(s), but was called with %s")

lua/luassert/util.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function util.deepcopy(t, deepmt, cache)
8989
copy[k] = (spy.is_spy(v) and v or util.deepcopy(v, deepmt, cache))
9090
end
9191
if deepmt then
92-
debug.setmetatable(copy, util.deepcopy(debug.getmetatable(t, nil, cache)))
92+
debug.setmetatable(copy, util.deepcopy(debug.getmetatable(t), false, cache))
9393
else
9494
debug.setmetatable(copy, debug.getmetatable(t))
9595
end
@@ -274,6 +274,7 @@ end
274274
function util.callable(object)
275275
return type(object) == "function" or type((debug.getmetatable(object) or {}).__call) == "function"
276276
end
277+
277278
-----------------------------------------------
278279
-- Checks an element has tostring.
279280
-- The type must either be a string or have a metatable

0 commit comments

Comments
 (0)