Skip to content

Commit

Permalink
Merge pull request #77 from n1tehawk/contrib
Browse files Browse the repository at this point in the history
Some minor changes and fixups
  • Loading branch information
bluebird75 committed Nov 4, 2016
2 parents 9d00f65 + 978d4a6 commit 4732946
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .appveyor/install-lua.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REM It is intended to be run as "install" step from within AppVeyor.
REM version numbers and file names for binaries from http://sf.net/p/luabinaries/
set VER_51=5.1.5
set VER_52=5.2.4
set VER_53=5.3.2
set VER_53=5.3.3
set ZIP_51=lua-%VER_51%_Win32_bin.zip
set ZIP_52=lua-%VER_52%_Win32_bin.zip
set ZIP_53=lua-%VER_53%_Win32_bin.zip
Expand Down
73 changes: 42 additions & 31 deletions luaunit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,34 @@ M.private = {}
M.VERSION='3.2'
M._VERSION=M.VERSION -- For LuaUnit v2 compatibility

--[[ Some people like assertEquals( actual, expected ) and some people prefer
--[[ Some people like assertEquals( actual, expected ) and some people prefer
assertEquals( expected, actual ).
]]--
M.ORDER_ACTUAL_EXPECTED = true
M.PRINT_TABLE_REF_IN_ERROR_MSG = false
M.TABLE_EQUALS_KEYBYCONTENT = true
M.LINE_LENGTH=80
M.LINE_LENGTH = 80

--[[ M.EPSILON is meant to help with Lua's floating point math in simple corner
cases like almostEquals(1.1-0.1, 1), which may not work as-is (e.g. on numbers
with rational binary representation) if the user doesn't provide some explicit
error margin.
The default margin used by almostEquals() in such cases is M.EPSILON; and since
Lua may be compiled with different numeric precisions (single vs. double), we
try to select a useful default for it dynamically. Note: If the initial value
is not acceptable, it can be changed by the user to better suit specific needs.
See also: https://en.wikipedia.org/wiki/Machine_epsilon
]]
M.EPSILON = 2^-52 -- = machine epsilon for "double", ~2.22E-16
if math.abs(1.1 - 1 - 0.1) > M.EPSILON then
-- rounding error is above EPSILON, assume single precision
M.EPSILON = 2^-23 -- = machine epsilon for "float", ~1.19E-07
end

-- set this to false to debug luaunit
local STRIP_LUAUNIT_FROM_STACKTRACE=true
local STRIP_LUAUNIT_FROM_STACKTRACE = true

M.VERBOSITY_DEFAULT = 10
M.VERBOSITY_LOW = 1
Expand Down Expand Up @@ -191,7 +209,7 @@ local function randomizeTable( t )
end
end
M.private.randomizeTable = randomizeTable

local function strsplit(delimiter, text)
-- Split text into a list consisting of the strings in text, separated
-- by strings matching delimiter (which may _NOT_ be a pattern).
Expand Down Expand Up @@ -680,16 +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 Expand Up @@ -836,15 +848,6 @@ function M.assertEquals(actual, expected)
end
end

-- Help Lua in corner cases like almostEquals(1.1, 1.0, 0.1), which by default
-- may not work. We need to give margin a small boost; EPSILON defines the
-- default value to use for this. Since Lua may be compiled with different
-- numeric precisions (single vs. double), we try to select a useful default:
local EPSILON = math.exp(-51 * math.log(2)) -- 2 * (2^-52, machine epsilon for "double") ~4.44E-16
if math.abs(1.1 - 1 - 0.1) > EPSILON then
-- rounding error is above EPSILON, assume single precision
EPSILON = math.exp(-22 * math.log(2)) -- 2 * (2^-23, machine epsilon for "float") ~2.38E-07
end
function M.almostEquals( actual, expected, margin, margin_boost )
if type(actual) ~= 'number' or type(expected) ~= 'number' or type(margin) ~= 'number' then
error_fmt(3, 'almostEquals: must supply only number arguments.\nArguments supplied: %s, %s, %s',
Expand All @@ -853,7 +856,7 @@ function M.almostEquals( actual, expected, margin, margin_boost )
if margin < 0 then
error('almostEquals: margin must not be negative, current value is ' .. margin, 3)
end
local realmargin = margin + (margin_boost or EPSILON)
local realmargin = margin + (margin_boost or M.EPSILON)
return math.abs(expected - actual) <= realmargin
end

Expand Down Expand Up @@ -1434,7 +1437,7 @@ then OK or FAILED (failures=1, error=1)
Started
.
Finished in 0.002695 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
-- Ruby:
Expand All @@ -1443,13 +1446,13 @@ Loaded suite tc_simple_number2
Started
F..
Finished in 0.038617 seconds.
1) Failure:
test_failure(TestSimpleNumber) [tc_simple_number2.rb:16]:
Adding doesn't work.
<3> expected but was
<4>.
3 tests, 4 assertions, 1 failures, 0 errors
-- Java Junit
Expand All @@ -1473,18 +1476,18 @@ Tests run: 8, Failures: 1, Errors: 0
T E S T S
-------------------------------------------------------
Running math.AdditionTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed:
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed:
0.03 sec <<< FAILURE!
Results :
Failed tests:
Failed tests:
testLireSymbole(math.AdditionTest)
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
-- LuaUnit
-- LuaUnit
---- non verbose
* display . or F or E when running tests
---- verbose
Expand Down Expand Up @@ -1625,7 +1628,9 @@ end

function M.LuaUnit.asFunction(aObject)
-- return "aObject" if it is a function, and nil otherwise
if 'function' == type(aObject) then return aObject end
if 'function' == type(aObject) then
return aObject
end
end

function M.LuaUnit.splitClassMethod(someName)
Expand Down Expand Up @@ -1967,7 +1972,9 @@ end

function M.LuaUnit:addStatus( err )
-- "err" is expected to be a table / result from protectedCall()
if err.status == NodeStatus.PASS then return end
if err.status == NodeStatus.PASS then
return
end

local node = self.result.currentNode

Expand All @@ -1982,7 +1989,9 @@ end
]]

-- if the node is already in failure/error, just don't report the new error (see above)
if node.status ~= NodeStatus.PASS then return end
if node.status ~= NodeStatus.PASS then
return
end

if err.status == NodeStatus.FAIL then
node:fail( err.msg, err.trace )
Expand Down Expand Up @@ -2279,7 +2288,9 @@ end
assert(methodInstance ~= nil)
self:execOneFunction( className, methodName, instance, methodInstance )
end
if self.result.aborted then break end -- "--error" or "--failure" option triggered
if self.result.aborted then
break -- "--error" or "--failure" option triggered
end
end

if self.lastClassName ~= nil then
Expand Down

0 comments on commit 4732946

Please sign in to comment.