lunarmodules / luassert

Assertion library for Lua
MIT License
206 stars 77 forks source link

Added formatting for assert arguments #5

Closed Tieske closed 12 years ago

Tieske commented 12 years ago

...rguments to be compared meaningful. Eg. for a function, the address, source line and source file are added, for tables does a simple 'pretty-print'

Tieske commented 12 years ago

example output:

Failure: ... projects\lua_cliargs\specs\cliargs_methods_spec.lua @ 131
tests add_opt() with short + expanded-key
... projects\lua_cliargs\specs\cliargs_methods_spec.lua:140: Expected objects to be equal. Passed in:
(string) 'default'
Expected:
(boolean) false
Failure: ... projects\lua_cliargs\specs\cliargs_methods_spec.lua @ 183
tests add_opt() with expanded-key, no reference
... projects\lua_cliargs\specs\cliargs_methods_spec.lua:187: Expected objects to be equal. Passed in:
(string) 'i'
Expected:
(string) 'insert'
Failure: ... projects\lua_cliargs\specs\cliargs_parsing_spec.lua @ 33
tests a table assertion
... projects\lua_cliargs\specs\cliargs_parsing_spec.lua:35: Expected objects to be the same. Passed in:
(table): {
  [1] = {
    [1] = '├®├®n' }
  [hello] = 'hallo'
  [we are] = 'zijn we'
  [here] = 'hier'
  [world] = 'wereld' }
Expected:
(table): { }
Failure: ... projects\lua_cliargs\specs\cliargs_parsing_spec.lua @ 38
tests a function assertion
... projects\lua_cliargs\specs\cliargs_parsing_spec.lua:39: Expected objects to be the same. Passed in:
function: 0044B5D8 @ line 89 in @C:\Users\Public\Lua\5.1\lua\luassert\assert.lua
Expected:
function: 005A9948 @ line -1 in =[C]
ajacksified commented 12 years ago

Looks great! I aspire to have this someday (for large strings and tables): http://visionmedia.github.com/mocha/#string diffs

That would help out if we're comparing huge tables and only care about the differences.

ajacksified commented 12 years ago

Oh, before we merge this, we should add some tests in spec/.

Tieske commented 12 years ago

yes, needs to be done. Just added another commit fixing an issue with non-existing modifiers/assertions. Sorry about mixing up, I'm still working on my git skills

Tieske commented 12 years ago

Added several tests, let me know if you require more.

ajacksified commented 12 years ago

looks good - just need to fix a couple failing tests; I'll work on that unless you get to it first.

Tieske commented 12 years ago

Seems to me the test output isn't right.

This is what I get;

C:\Users\Thijs\Dropbox\Lua projects\busted\luassert>busted spec
++++++++++++++++++
18 successes, 0 failures, and 0 pending in 0 seconds.
C:\Users\Thijs\Dropbox\Lua projects\busted\luassert>busted -o TAP spec
1..18
ok 1 - Checks to see if tables 1 and 2 are the same
ok 2 - Checks same() assertion to handle nils properly
ok 3 - Checks to see if tables 1 and 2 are equal
ok 4 - Checks equals() assertion to handle nils properly
ok 5 - Checks to see if table1 only contains unique elements
ok 6 - Ensures the is operator doesn't change the behavior of equals
ok 7 - Ensures the not operator does change the behavior of equals
ok 8 - Ensures that error only throws an error when the first argument function does not throw an error
ok 9 - Checks to see if var is truthy
ok 10 - Checks to see if var is falsy
ok 11 - Checks to see if types are returned as strings
ok 12 - Checks to see if empty table is returned empty
ok 13 - Checks to see if table containing nils is returned with same number of entries
ok 14 - makes sure we're returning the same table
ok 15 - makes sure function calls are spies
ok 16 - makes sure function calls are stubs when specified
ok 17 - checks to see if spy keeps track of arguments
ok 18 - checks to see if spy keeps track of number of calls
C:\Users\Thijs\Dropbox\Lua projects\busted\luassert>

The problem is probably that the comitted version of luassert is tested using the latest rockspec version, whilst it should be tested using itself.

ajacksified commented 12 years ago

I get the failures locally on your master:

jlawson:luassert:master ⇰ busted spec --output=plain_terminal
joined value: /Users/jlawson/Projects/luassert/
joined value: plain_terminal

+x+x++++++xxx+++++ 
13 successes, 5 failures, and 0 pending in 0.000464 seconds.

Failure: /Users/jlawson/Projects/luassert/spec/assertions_spec.lua @ 8
Checks same() assertion to handle nils properly
/Users/jlawson/Projects/luassert/spec/assertions_spec.lua:9: Expected error to be thrown.

Failure: /Users/jlawson/Projects/luassert/spec/assertions_spec.lua @ 21
Checks equals() assertion to handle nils properly
/Users/jlawson/Projects/luassert/spec/assertions_spec.lua:22: Expected error to be thrown.

Failure: /Users/jlawson/Projects/luassert/spec/formatters_spec.lua @ 10
Checks to see if types are returned as strings
/usr/local/share/lua/5.1/luassert/assert.lua:39: attempt to index a nil value

Failure: /Users/jlawson/Projects/luassert/spec/formatters_spec.lua @ 18
Checks to see if empty table is returned empty
/usr/local/share/lua/5.1/luassert/assert.lua:39: attempt to index a nil value

Failure: /Users/jlawson/Projects/luassert/spec/formatters_spec.lua @ 25
Checks to see if table containing nils is returned with same number of entries
/usr/local/share/lua/5.1/luassert/assert.lua:39: attempt to index a nil value

I'll try and take a look this evening.

Tieske commented 12 years ago

I get the same result when I install the last rock and then test the updated version.

C:\Users\Thijs\Dropbox\Lua projects\busted\luassert>busted -o TAP spec
1..18
ok 1 - Checks to see if tables 1 and 2 are the same
not ok 2 - Checks same() assertion to handle nils properly
ok 3 - Checks to see if tables 1 and 2 are equal
not ok 4 - Checks equals() assertion to handle nils properly
ok 5 - Checks to see if table1 only contains unique elements
ok 6 - Ensures the is operator doesn't change the behavior of equals
ok 7 - Ensures the not operator does change the behavior of equals
ok 8 - Ensures that error only throws an error when the first argument function does not throw an error
ok 9 - Checks to see if var is truthy
ok 10 - Checks to see if var is falsy
not ok 11 - Checks to see if types are returned as strings
not ok 12 - Checks to see if empty table is returned empty
not ok 13 - Checks to see if table containing nils is returned with same number of entries
ok 14 - makes sure we're returning the same table
ok 15 - makes sure function calls are spies
ok 16 - makes sure function calls are stubs when specified
ok 17 - checks to see if spy keeps track of arguments
ok 18 - checks to see if spy keeps track of number of calls
C:\Users\Thijs\Dropbox\Lua projects\busted\luassert>

As mentioned, the updated version must be tested against itself.

So first remove luassert from your system (older version), then install the last committed version. Only then test the last comitted version.

ajacksified commented 12 years ago

Looks good. Wonder why Travis hates it.

I was running luarocks make, but that only apparently overwrites sometimes - I had to manually remove and add again.

Tieske commented 12 years ago

Looks good. Wonder why Travis hates it.

I think you should explicitly have LuaRocks uninstall luassert, and then do a luarocks make form the test target directory to reinstall the correct version

ajacksified commented 12 years ago

@Tieske I actually had two failing specs once I was on your branch, which I fixed in my lates.

Tieske commented 12 years ago

I meant this;

branches:
  only:
    - master
install:
  - sudo apt-get install luajit
  - sudo apt-get install luarocks
  - sudo luarocks install luafilesystem
  - git clone git://github.com/Olivine-Labs/say.git
  - cd say
  - sudo luarocks make
  - cd ../
  - git clone git://github.com/Olivine-Labs/luassert.git
  - cd luassert
  - sudo luarocks make
  - cd ../
  - git clone git://github.com/Olivine-Labs/busted.git
  - cd busted
  - sudo luarocks make
  - cd ../
script: "busted spec"

Seems you're pulling everything from master, so don't pull luassert from master or explcitly uninstall it later. I don't know when travis pulls the target code to be tested. But after that a 'sudo luarocks make' in the target directory should install the proper version I would guess.

ajacksified commented 12 years ago

Oh, right. I'll look into that.