Closed appgurueu closed 2 years ago
Thx for the report.
Since the pattern is %s
is expects a string anyway. So just wrapping the expected
variable in a tostring()
should be good enough.
Mind sending a PR?
Turns out this gets rather tricky: First of all, the formatting isn't done by busted, but by luassert
, which in turn uses say
. While luassert
will happily format & forward the arguments it gets to say
, it doesn't know how many arguments to expect. So for this to be fixed:
say
must provide an API to count the expected %s
;luassert
must format missing arguments as nothing
(note that "no argument" is not exactly the same as nil
)Of course, luassert
assertions could store how many arguments they expect. This will effectively be redundant though (it's exactly the same as the count of %s
in the format strings).
luassert must format missing arguments as nothing (note that "no argument" is not exactly the same as nil)
technically true, but Luassert will already in many places report 'nil'
Fails:
$ lua -e "assert = require('luassert'); assert.truthy()"
lua: (command line):1: Expected to be truthy, but value was:
%s
Works:
$ lua -e "assert = require('luassert'); assert.truthy(nil)"
lua: (command line):1: Expected to be truthy, but value was:
(nil)
Compare to equal
behaviour:
$ lua -e "assert = require('luassert'); assert.equal(true, nil)"
lua: (command line):1: Expected objects to be equal.
Passed in:
(nil)
Expected:
(boolean) true
But if not specifying it throws an error;
$ lua -e "assert = require('luassert'); assert.equal(true)"
lua: .../1.19.3.2/luarocks/share/lua/5.1/luassert/assertions.lua:115: the 'equals' function requires a minimum of 2 arguments, got: 1
So I guess the fix should be to throw an error if nothing is passed in.
This is because busted uses
string.format("... %s ... ", expected)
, which does nothing if expected is nothing.Trivially reproducible using
assert.truthy()
.