Skip to content

Commit

Permalink
Remove some unreachable code lines from _is_table_equals()
Browse files Browse the repository at this point in the history
Coverage analysis indicates that the test for an "empty"
actualKeysMatched table always succeeds, and the enclosed
return statement never gets executed.

This is to be expected, as for any given (non table-type)
key `k` that is present in `actual` but not in `expected`,
our earlier value-based test would already fail. We compare
actual[k] against (expected[k] == nil), which won't pass.

Fixed this by removing the unnecessary code.
  • Loading branch information
n1tehawk committed Oct 21, 2016
1 parent 2de59ba commit 4a26cfa
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions luaunit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,10 @@ local function _is_table_equals(actual, expected, recursions)
-- Found a key that we did not see in "actual" -> mismatch
return false
end
-- Otherwise we know that actual[k] was already matched
-- against v = expected[k]. Remove k from the table again.
actualKeysMatched[k] = nil
-- Otherwise actual[k] was already matched against v = expected[k].
end
end

-- If we have any keys left in the actualKeysMatched table, then those
-- were missing from "expected", meaning the tables are different.
if next(actualKeysMatched) then
return false
end

if next(actualTableKeys) then
-- If there is any key left in actualTableKeys, then that is
-- a table-type key in actual with no matching counterpart
Expand Down

0 comments on commit 4a26cfa

Please sign in to comment.