From 8a8dd882a507d4bca1376bdb4aaeafbe85f1ed8d Mon Sep 17 00:00:00 2001 From: Philippe F Date: Wed, 9 Nov 2016 21:31:15 +0100 Subject: [PATCH 01/14] Rename string_sub to string_gsub --- run_functional_tests.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/run_functional_tests.lua b/run_functional_tests.lua index 230f4637..20c474e8 100755 --- a/run_functional_tests.lua +++ b/run_functional_tests.lua @@ -25,15 +25,17 @@ local function escape_lua_pattern(s) return s:gsub(LUA_MAGIC_CHARS, "%%%1") -- substitute with '%' + matched char end -local function string_sub(s, orig, repl) +local function string_gsub(s, orig, repl) -- replace occurrence of string orig by string repl -- just like string.gsub, but with no pattern matching + -- print( 'gsub_input '..s..' '..orig..' '..repl) return s:gsub( escape_lua_pattern(orig), repl ) end function testStringSub() - lu.assertEquals( string_sub('aa a % b cc', 'a % b', 'a + b'), 'aa a + b cc' ) - lu.assertEquals( string_sub('aa: ?cc', ': ?', 'xx?'), 'aaxx?cc' ) + lu.assertEquals( string_gsub('aa a % b cc', 'a % b', 'a + b'), 'aa a + b cc' ) + lu.assertEquals( string_gsub('aa: ?cc', ': ?', 'xx?'), 'aaxx?cc' ) + lu.assertEquals( string_gsub('aa b: cc b: ee', 'b:', 'xx'), 'aa xx cc xx ee' ) end local function osExec( ... ) @@ -146,11 +148,11 @@ local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) if verbose then print('Modifying line: '..line ) end - line = string_sub(line, dest, source) + line = string_gsub(line, dest, source) -- line = line:sub(1,idxStart-1)..source..line:sub(idxEnd+1) -- string.gsub( line, dest, source ) if verbose then - print('Result: '..line ) + print('Result : '..line ) end end table.insert( linesOut, line ) From 5fbd4c6dc658ef31c583ec2727a9497909c1bdcb Mon Sep 17 00:00:00 2001 From: Philippe F Date: Wed, 9 Nov 2016 21:32:47 +0100 Subject: [PATCH 02/14] Implement improved list difference analysis --- .gitignore | 1 + .luacheckrc | 3 + luaunit.lua | 350 ++++++++++++++++++++++++++++++++++++++- run_functional_tests.lua | 21 ++- 4 files changed, 367 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f4df9b74..4884d0f6 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ test/legacyExampleError.txt test/compat_luaunit_v2x.txt test/errFailPass*.txt test/errFailPass*.xml +test/some_lists_comparisons.txt *.diff diff --git a/.luacheckrc b/.luacheckrc index 2dde62b0..e444d013 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -31,5 +31,8 @@ files = { }, ["test/test_with_xml.lua"] = { ignore = {"Test%w+"} + }, + ["test/some_lists_comparisons.lua"] = { + ignore = {"Test%w+"} } } diff --git a/luaunit.lua b/luaunit.lua index 75d27fd7..35c486a9 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -24,7 +24,9 @@ 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.TABLE_DIFF_ANALYSIS_THRESHOLD = 10 -- display deep analysis for more than 10 items +M.LIST_DIFF_ANALYSIS_THRESHOLD = 10 -- display deep analysis for more than 10 items -- set this to false to debug luaunit local STRIP_LUAUNIT_FROM_STACKTRACE=true @@ -33,6 +35,9 @@ M.VERBOSITY_DEFAULT = 10 M.VERBOSITY_LOW = 1 M.VERBOSITY_QUIET = 0 M.VERBOSITY_VERBOSE = 20 +M.DEFAULT_DEEP_ANALYSIS = nil +M.FORCE_DEEP_ANALYSIS = true +M.DISABLE_DEEP_ANALYSIS = false -- set EXPORT_ASSERT_TO_GLOBALS to have all asserts visible as global values -- EXPORT_ASSERT_TO_GLOBALS = true @@ -419,7 +424,329 @@ local function prettystr( v, keeponeline ) end M.prettystr = prettystr -local function prettystrPadded(value1, value2, suffix_a, suffix_b) +local function tryMismatchFormatting( ta, tb, doDeepAnalysis ) + --[[ + Prepares a nice error message when comparing tables, performing a deeper + analysis. + + Arguments: + * ta, tb: tables to be compared + * doDeepAnalysis: + M.DEFAULT_DEEP_ANALYSIS: (the default if not specified) perform deep analysis only for big lists and big dictionnaries + M.FORCE_DEEP_ANALYSIS : always perform deep analysis + M.DISABLE_DEEP_ANALYSIS: never perform deep analysis + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + local isPureList + + -- check if ta & tb are suitable for deep analysis + if type(ta) ~= 'table' or type(tb) ~= 'table' then + return false + end + + if doDeepAnalysis == M.DISABLE_DEEP_ANALYSIS then + return false + end + + local k1, k2, v1, v2, lv1, lv2 + lv1 = #ta + lv2 = #tb + isPureList = true + + for k1, v1 in pairs(ta) do + if type(k1) ~= 'number' or k1 > lv1 then + -- this table a mapping + isPureList = false + break + end + end + + for k2, v2 in pairs(tb) do + if not isPureList or type(k2) ~= 'number' or k2 > lv2 then + -- this table a mapping + isPureList = false + break + end + end + + if isPureList and math.min(lv1, lv2) < M.LIST_DIFF_ANALYSIS_THRESHOLD then + if not (doDeepAnalysis == M.FORCE_DEEP_ANALYSIS) then + return false + end + end + + if isPureList then + return M.private.mismatchFormattingPureList( ta, tb ) + else + -- only work on mapping for the moment + -- return M.private.mismatchFormattingMapping( ta, tb, doDeepAnalysis ) + return false + end +end +M.private.tryMismatchFormatting = tryMismatchFormatting + +local function getTaTbDesc() + local descta, desctb + descta, desctb = 'actual', 'expected' + if not M.ORDER_ACTUAL_EXPECTED then + descta, desctb = desctb, descta + end + return descta, desctb +end + +local function is_eq( a, b ) + if type(a) == 'table' and type(b) == 'table' then + return M.private._is_table_equals(a,b) + end + return a == b +end + +local function extendWithStrFmt( res, ... ) + table.insert( res, string.format( ... ) ) +end + +local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) + --[[ + Prepares a nice error message when comparing tables which are not pure lists, performing a deeper + analysis. + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + local result = {} + local descta, desctb = getTaTbDesc() + + local keysCommon = {} + local keysOnlyTa = {} + local keysOnlyTb = {} + local keysDiffTaTb = {} + + local k, v + + for k,v in pairs( ta ) do + if is_eq( v, tb[k] ) then + table.insert( keysCommon, k ) + else + if tb[k] == nil then + table.insert( keysOnlyTa, k ) + else + table.insert( keysDiffTaTb, k ) + end + end + end + + for k,v in pairs( tb ) do + if not is_eq( v, ta[k] ) and ta[k] == nil then + table.insert( keysOnlyTb, k ) + end + end + + local lta = #keysCommon + #keysDiffTaTb + #keysOnlyTa + local ltb = #keysCommon + #keysDiffTaTb + #keysOnlyTb + local limited_display = (lta < 5 or ltb < 5) + + if math.min(lta, ltb) < M.TABLE_DIFF_ANALYSIS_THRESHOLD then + return false + end + + if not limited_display then + if lta == ltb then + extendWithStrFmt( result, 'Table A (%s) and B (%s) both have %d items', descta, desctb, lta ) + else + extendWithStrFmt( result, 'Table A (%s) has %d items and table B (%s) has %d items', descta, lta, desctb, ltb ) + end + + if #keysCommon == 0 and #keysDiffTaTb == 0 then + table.insert( result, 'Table A and B have no keys in common, they are totally different') + else + local s_other = 'other ' + if #keysCommon then + extendWithStrFmt( result, 'Table A and B have %d identical items', #keysCommon ) + else + table.insert( result, 'Table A and B have no identical items' ) + s_other = '' + end + + if #keysDiffTaTb ~= 0 then + result[#result] = string.format( '%s and %d items differing present in both tables', result[#result], #keysDiffTaTb) + else + result[#result] = string.format( '%s and no %sitems differing present in both tables', result[#result], s_other, #keysDiffTaTb) + end + end + + extendWithStrFmt( result, 'Table A has %d keys not present in table B and table B has %d keys not present in table A', #keysOnlyTa, #keysOnlyTb ) + end + + local function keytostring(k) + if "string" == type(k) and k:match("^[_%a][_%w]*$") then + return k + end + return prettystr(k) + end + + if #keysDiffTaTb ~= 0 then + table.insert( result, 'Items differing in A and B:') + for k,v in sortedPairs( keysDiffTaTb ) do + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(ta[v]) ) + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(tb[v]) ) + end + end + + if #keysOnlyTa ~= 0 then + table.insert( result, 'Items only in table A:' ) + for k,v in sortedPairs( keysOnlyTa ) do + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(ta[v]) ) + end + end + + if #keysOnlyTb ~= 0 then + table.insert( result, 'Items only in table B:' ) + for k,v in sortedPairs( keysOnlyTb ) do + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(tb[v]) ) + end + end + + if #keysCommon ~= 0 then + table.insert( result, 'Items common to A and B:') + for k,v in sortedPairs( keysCommon ) do + extendWithStrFmt( result, ' = A and B [%s]: %s', keytostring(v), prettystr(ta[v]) ) + end + end + + return true, table.concat( result, '\n') +end +M.private.mismatchFormattingMapping = mismatchFormattingMapping + +local function mismatchFormattingPureList( ta, tb ) + --[[ + Prepares a nice error message when comparing tables which are lists, performing a deeper + analysis. + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + local result = {} + local descta, desctb = getTaTbDesc() + + local lta = #ta + local ltb = #tb + local i + local longest = math.max(lta, ltb) + local shortest = math.min(lta, ltb) + local deltalv = longest - shortest + local commonUntil, commonBackTo + + i = 1 + while i <= longest do + if not is_eq(ta[i], tb[i]) then + break + end + + i = i+1 + end + commonUntil = i-1 + + i = 0 + while i > -shortest do + if not is_eq(ta[lta+i], tb[ltb+i]) then + break + end + i = i - 1 + end + commonBackTo = i+1 + + + local refa, refb = '', '' + if M.PRINT_TABLE_REF_IN_ERROR_MSG then + refa, refb = string.format( '<%s> ', tostring(ta)), string.format('<%s> ', tostring(tb) ) + end + + table.insert( result, 'List difference analysis:' ) + if lta == ltb then + -- TODO: handle expected/actual naming + extendWithStrFmt( result, '* lists %sA (%s) and %sB (%s) have the same size', refa, descta, refb, desctb ) + else + extendWithStrFmt( result, '* size of lists differ: list %sA (%s) has %d items, list %sB (%s) has %d items', refa, descta, lta, refb, desctb, ltb ) + end + + i = 1 + extendWithStrFmt( result, '* lists A and B start differing at index %d', commonUntil+1 ) + if commonBackTo < 1 then + if deltalv > 0 then + extendWithStrFmt( result, '* lists A and B are equals again from index %d for A, %d for B', lta+commonBackTo, ltb+commonBackTo ) + else + extendWithStrFmt( result, '* lists A and B are equals again from index %d', lta+commonBackTo ) + end + end + + local function insertABValue(i, bi) + bi = bi or i + if is_eq( ta[i], tb[bi]) then + return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) ) + else + extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i])) + extendWithStrFmt( result, ' + B[%d]: %s', bi, prettystr(tb[bi])) + end + end + + -- common parts to list A & B, at the beginning + if i <= commonUntil then + table.insert( result, '* Common parts:' ) + end + while i <= commonUntil do + insertABValue( i ) + i = i + 1 + end + + -- diffing parts to list A & B + if i < shortest + commonBackTo then + table.insert( result, '* Differing parts:' ) + end + while i < shortest + commonBackTo do + insertABValue( i ) + i = i + 1 + end + + -- display indexes of one list, with no match on other list + if i < longest + commonBackTo then + table.insert( result, '* Present only in one list:' ) + end + while i < longest + commonBackTo do + if lta > ltb then + extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i]) ) + -- table.insert( result, '+ (no matching B index)') + else + -- table.insert( result, '- no matching A index') + extendWithStrFmt( result, ' + B[%d]: %s', i, prettystr(tb[i]) ) + end + i = i + 1 + end + + -- common parts to list A & B, at the end + if i <= longest then + table.insert( result, '* Common parts at the end of the lists' ) + end + while i <= longest do + if lta > ltb then + insertABValue( i, i-deltalv ) + else + insertABValue( i-deltalv, i ) + end + i = i + 1 + end + + return true, table.concat( result, '\n') +end +M.private.mismatchFormattingPureList = mismatchFormattingPureList + local function prettystrPairs(value1, value2, suffix_a, suffix_b) --[[ This function helps with the recurring task of constructing the "expected @@ -734,13 +1061,22 @@ end -- ---------------------------------------------------------------- -local function errorMsgEquality(actual, expected) +local function errorMsgEquality(actual, expected, doDeepAnalysis) + if not M.ORDER_ACTUAL_EXPECTED then expected, actual = actual, expected end if type(expected) == 'string' or type(expected) == 'table' then - expected, actual = prettystrPadded(expected, actual) - return string.format("expected: %s\nactual: %s", expected, actual) + local strExpected, strActual = prettystrPairs(expected, actual) + local result = string.format("expected: %s\nactual: %s", strExpected, strActual) + + -- extend with mismatch analysis if possible: + local success, mismatchResult + success, mismatchResult = tryMismatchFormatting( actual, expected, doDeepAnalysis ) + if success then + result = table.concat( { result, mismatchResult }, '\n' ) + end + return result end return string.format("expected: %s, actual: %s", prettystr(expected), prettystr(actual)) @@ -826,10 +1162,10 @@ function M.assertNotIsInf(value) end end -function M.assertEquals(actual, expected) +function M.assertEquals(actual, expected, doDeepAnalysis) if type(actual) == 'table' and type(expected) == 'table' then if not _is_table_equals(actual, expected) then - failure( errorMsgEquality(actual, expected), 2 ) + failure( errorMsgEquality(actual, expected, doDeepAnalysis), 2 ) end elseif type(actual) ~= type(expected) then failure( errorMsgEquality(actual, expected), 2 ) diff --git a/run_functional_tests.lua b/run_functional_tests.lua index 20c474e8..ad91b9dd 100755 --- a/run_functional_tests.lua +++ b/run_functional_tests.lua @@ -143,7 +143,7 @@ local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) local dest, linesOut = nil, {} for line in io.lines(fileOut) do idxStart, idxEnd, capture = line:find( pattern ) - if idxStart ~= nil then + while idxStart ~= nil do dest = capture if verbose then print('Modifying line: '..line ) @@ -154,6 +154,7 @@ local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) if verbose then print('Result : '..line ) end + idxStart, idxEnd, capture = line:find( pattern, idxEnd ) end table.insert( linesOut, line ) end @@ -197,6 +198,10 @@ local function check_text_output( fileToRun, options, output, refOutput, refExit adjustFile( output, refOutput, 'Started on (.*)') end adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) + adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) + adjustFile( output, refOutput, 'thread: (0?x?[%x]+)', true ) + adjustFile( output, refOutput, 'function: (0?x?[%x]+)', true ) + adjustFile( output, refOutput, '', true, false ) -- For Lua 5.3: stack trace uses "method" instead of "function" adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) @@ -493,6 +498,14 @@ function testTestWithXmlQuiet() 'test/testWithXmlLintQuiet.txt', 'test/ref/testWithXmlQuiet.txt', 'test/ref/testWithXmlQuiet.xml', 2 ) ) end +function testListComparison() + -- run test/some_lists_comparisons and check exit status + lu.assertEquals( 0, + check_text_output('test/some_lists_comparisons.lua', '--verbose', + 'test/some_lists_comparisons.txt', + 'test/ref/some_lists_comparisons.txt', 11 ) ) +end + function testLegacyLuaunitUsage() -- run test/legacy_example_usage and check exit status (expecting 12 failures) osExpectedCodeExec(12, '%s %s --output text > %s', LUA, @@ -633,6 +646,11 @@ local filesToGenerateStopOnError = { 'test/ref/errFailPassTextStopOnError-4.txt'}, } +local filesToGenerateListsComp = { + { 'test/some_lists_comparisons.lua', '', '--output text --verbose', + 'test/ref/some_lists_comparisons.txt'}, +} + local filesSetIndex = { ErrFailPassText=filesToGenerateErrFailPassText, ErrFailPassTap=filesToGenerateErrFailPassTap, @@ -643,6 +661,7 @@ local filesSetIndex = { ExampleXml=filesToGenerateExampleXml, TestXml=filesToGenerateTestXml, StopOnError=filesToGenerateStopOnError, + ListsComp=filesToGenerateListsComp, } local function updateRefFiles( filesToGenerate ) From e4b54c04bb52f14895767d66acc67949e08e00ed Mon Sep 17 00:00:00 2001 From: Philippe F Date: Wed, 9 Nov 2016 21:58:28 +0100 Subject: [PATCH 03/14] No need to add new function for equality comparison --- luaunit.lua | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/luaunit.lua b/luaunit.lua index 35c486a9..96088513 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -498,13 +498,6 @@ local function getTaTbDesc() return descta, desctb end -local function is_eq( a, b ) - if type(a) == 'table' and type(b) == 'table' then - return M.private._is_table_equals(a,b) - end - return a == b -end - local function extendWithStrFmt( res, ... ) table.insert( res, string.format( ... ) ) end @@ -530,7 +523,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) local k, v for k,v in pairs( ta ) do - if is_eq( v, tb[k] ) then + if is_equals( v, tb[k] ) then table.insert( keysCommon, k ) else if tb[k] == nil then @@ -542,7 +535,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) end for k,v in pairs( tb ) do - if not is_eq( v, ta[k] ) and ta[k] == nil then + if not is_equals( v, ta[k] ) and ta[k] == nil then table.insert( keysOnlyTb, k ) end end @@ -646,7 +639,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 1 while i <= longest do - if not is_eq(ta[i], tb[i]) then + if not is_equals(ta[i], tb[i]) then break end @@ -656,7 +649,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 0 while i > -shortest do - if not is_eq(ta[lta+i], tb[ltb+i]) then + if not is_equals(ta[lta+i], tb[ltb+i]) then break end i = i - 1 @@ -689,7 +682,7 @@ local function mismatchFormattingPureList( ta, tb ) local function insertABValue(i, bi) bi = bi or i - if is_eq( ta[i], tb[bi]) then + if is_equals( ta[i], tb[bi]) then return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) ) else extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i])) @@ -1036,6 +1029,7 @@ local function _is_table_equals(actual, expected, recursions) return true end M.private._is_table_equals = _is_table_equals +local is_equals = _is_table_equals local function failure(msg, level) -- raise an error indicating a test failure From 9d354333d4e9a4d96717c72f92170e6b5d685b87 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Wed, 9 Nov 2016 22:13:31 +0100 Subject: [PATCH 04/14] Fix functional and unit-tests --- test/ref/some_lists_comparisons.txt | 844 ++++++++++++++++++++++++++++ test/some_lists_comparisons.lua | 146 +++++ test/test_luaunit.lua | 52 +- 3 files changed, 1041 insertions(+), 1 deletion(-) create mode 100644 test/ref/some_lists_comparisons.txt create mode 100644 test/some_lists_comparisons.lua diff --git a/test/ref/some_lists_comparisons.txt b/test/ref/some_lists_comparisons.txt new file mode 100644 index 00000000..047c84ad --- /dev/null +++ b/test/ref/some_lists_comparisons.txt @@ -0,0 +1,844 @@ +Started on 11/08/16 21:28:53 + TestListCompare.test1 ... FAIL +test/some_lists_comparisons.lua:22: expected: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12121221, + 122122212, + 111221212121 +} +actual: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12211221, + 122122212, + 111221212121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 9 +* lists A and B are equals again from index 10 +* Common parts: + = A[1], B[1]: 1212212 + = A[2], B[2]: 12221122 + = A[3], B[3]: 1212212 + = A[4], B[4]: 12221122 + = A[5], B[5]: 1212212 + = A[6], B[6]: 12221122 + = A[7], B[7]: 1212212 + = A[8], B[8]: 12221122 +* Differing parts: + - A[9]: 12211221 + + B[9]: 12121221 +* Common parts at the end of the lists + = A[10], B[10]: 122122212 + = A[11], B[11]: 111221212121 + TestListCompare.test1b ... FAIL +test/some_lists_comparisons.lua:28: expected: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12121221 +} +actual: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12211221 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 11 +* Common parts: + = A[1], B[1]: 1212212 + = A[2], B[2]: 12221122 + = A[3], B[3]: 1212212 + = A[4], B[4]: 12221122 + = A[5], B[5]: 1212212 + = A[6], B[6]: 12221122 + = A[7], B[7]: 1212212 + = A[8], B[8]: 12221122 + = A[9], B[9]: 1212212 + = A[10], B[10]: 12221122 +* Differing parts: + - A[11]: 12211221 + + B[11]: 12121221 + TestListCompare.test1c ... FAIL +test/some_lists_comparisons.lua:34: expected: +{ + 12121221, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121 +} +actual: +{ + 12211221, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 1 +* lists A and B are equals again from index 2 +* Differing parts: + - A[1]: 12211221 + + B[1]: 12121221 +* Common parts at the end of the lists + = A[2], B[2]: 122122212 + = A[3], B[3]: 111221212121 + = A[4], B[4]: 122122212 + = A[5], B[5]: 111221212121 + = A[6], B[6]: 122122212 + = A[7], B[7]: 111221212121 + = A[8], B[8]: 122122212 + = A[9], B[9]: 111221212121 + = A[10], B[10]: 122122212 + = A[11], B[11]: 111221212121 + TestListCompare.test2 ... FAIL +test/some_lists_comparisons.lua:43: expected: {1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 7 +* lists A and B are equals again from index 9 +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Differing parts: + - A[7]: 7 + + B[7]: 8 + - A[8]: 8 + + B[8]: 7 +* Common parts at the end of the lists + = A[9], B[9]: 9 + = A[10], B[10]: 10 + = A[11], B[11]: 11 + = A[12], B[12]: 12 + = A[13], B[13]: 13 + = A[14], B[14]: 14 + = A[15], B[15]: 15 + = A[16], B[16]: 16 + = A[17], B[17]: 17 + = A[18], B[18]: 18 + = A[19], B[19]: 19 + = A[20], B[20]: 20 + TestListCompare.test3 ... FAIL +test/some_lists_comparisons.lua:57: expected: {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 20 items, list B (expected) has 19 items +* lists A and B start differing at index 7 +* lists A and B are equals again from index 8 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 +* Common parts at the end of the lists + = A[8], B[7]: 8 + = A[9], B[8]: 9 + = A[10], B[9]: 10 + = A[11], B[10]: 11 + = A[12], B[11]: 12 + = A[13], B[12]: 13 + = A[14], B[13]: 14 + = A[15], B[14]: 15 + = A[16], B[15]: 16 + = A[17], B[16]: 17 + = A[18], B[17]: 18 + = A[19], B[18]: 19 + = A[20], B[19]: 20 + TestListCompare.test4 ... FAIL +test/some_lists_comparisons.lua:74: expected: {1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 20 items, list B (expected) has 17 items +* lists A and B start differing at index 7 +* lists A and B are equals again from index 10 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 + - A[8]: 8 + - A[9]: 9 +* Common parts at the end of the lists + = A[10], B[7]: 10 + = A[11], B[8]: 11 + = A[12], B[9]: 12 + = A[13], B[10]: 13 + = A[14], B[11]: 14 + = A[15], B[12]: 15 + = A[16], B[13]: 16 + = A[17], B[14]: 17 + = A[18], B[15]: 18 + = A[19], B[16]: 19 + = A[20], B[17]: 20 + TestListCompare.test5a ... FAIL +test/some_lists_comparisons.lua:98: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (expected) has 17 items, list B (actual) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test5b ... FAIL +test/some_lists_comparisons.lua:103: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test5c ... FAIL +test/some_lists_comparisons.lua:109: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test6 ... FAIL +test/some_lists_comparisons.lua:117: expected: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1, + 2, + 8=true, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +actual: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1, + 2, + 8=false, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 8 +* lists A and B are equals again from index 9 +* Common parts: + = A[1], B[1]: "aaa" + = A[2], B[2]: "bbb" + = A[3], B[3]: "ccc" + = A[4], B[4]: function: 00E70160 + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: nil +* Differing parts: + - A[8]: false + + B[8]: true +* Common parts at the end of the lists + = A[9], B[9]: false + = A[10], B[10]: thread: 00E35480 + = A[11], B[11]: thread: 00E35480 + = A[12], B[12]: thread: 00E35480 + TestListCompare.test7 ... FAIL +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 3 +* lists A and B are equals again from index 5 +* Common parts: + = A[1], B[1]: {1, 2, 3} + = A[2], B[2]: {1, 2} +* Differing parts: + - A[3]: {{2}, {2}} + + B[3]: {{1}, {2}} + - A[4]: {"aa", "bb"} + + B[4]: {"aa", "cc"} +* Common parts at the end of the lists + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: 1.33 + = A[8], B[8]: 1.#INF + = A[9], B[9]: {a=1} + = A[10], B[10]: {} +========================================================= +Failed tests: +------------- +1) TestListCompare.test1 +test/some_lists_comparisons.lua:22: expected: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12121221, + 122122212, + 111221212121 +} +actual: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12211221, + 122122212, + 111221212121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 9 +* lists A and B are equals again from index 10 +* Common parts: + = A[1], B[1]: 1212212 + = A[2], B[2]: 12221122 + = A[3], B[3]: 1212212 + = A[4], B[4]: 12221122 + = A[5], B[5]: 1212212 + = A[6], B[6]: 12221122 + = A[7], B[7]: 1212212 + = A[8], B[8]: 12221122 +* Differing parts: + - A[9]: 12211221 + + B[9]: 12121221 +* Common parts at the end of the lists + = A[10], B[10]: 122122212 + = A[11], B[11]: 111221212121 +stack traceback: + test/some_lists_comparisons.lua:22: in function 'TestListCompare.test1' + +2) TestListCompare.test1b +test/some_lists_comparisons.lua:28: expected: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12121221 +} +actual: +{ + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 1212212, + 12221122, + 12211221 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 11 +* Common parts: + = A[1], B[1]: 1212212 + = A[2], B[2]: 12221122 + = A[3], B[3]: 1212212 + = A[4], B[4]: 12221122 + = A[5], B[5]: 1212212 + = A[6], B[6]: 12221122 + = A[7], B[7]: 1212212 + = A[8], B[8]: 12221122 + = A[9], B[9]: 1212212 + = A[10], B[10]: 12221122 +* Differing parts: + - A[11]: 12211221 + + B[11]: 12121221 +stack traceback: + test/some_lists_comparisons.lua:28: in function 'TestListCompare.test1b' + +3) TestListCompare.test1c +test/some_lists_comparisons.lua:34: expected: +{ + 12121221, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121 +} +actual: +{ + 12211221, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121, + 122122212, + 111221212121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 1 +* lists A and B are equals again from index 2 +* Differing parts: + - A[1]: 12211221 + + B[1]: 12121221 +* Common parts at the end of the lists + = A[2], B[2]: 122122212 + = A[3], B[3]: 111221212121 + = A[4], B[4]: 122122212 + = A[5], B[5]: 111221212121 + = A[6], B[6]: 122122212 + = A[7], B[7]: 111221212121 + = A[8], B[8]: 122122212 + = A[9], B[9]: 111221212121 + = A[10], B[10]: 122122212 + = A[11], B[11]: 111221212121 +stack traceback: + test/some_lists_comparisons.lua:34: in function 'TestListCompare.test1c' + +4) TestListCompare.test2 +test/some_lists_comparisons.lua:43: expected: {1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 7 +* lists A and B are equals again from index 9 +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Differing parts: + - A[7]: 7 + + B[7]: 8 + - A[8]: 8 + + B[8]: 7 +* Common parts at the end of the lists + = A[9], B[9]: 9 + = A[10], B[10]: 10 + = A[11], B[11]: 11 + = A[12], B[12]: 12 + = A[13], B[13]: 13 + = A[14], B[14]: 14 + = A[15], B[15]: 15 + = A[16], B[16]: 16 + = A[17], B[17]: 17 + = A[18], B[18]: 18 + = A[19], B[19]: 19 + = A[20], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:43: in function 'TestListCompare.test2' + +5) TestListCompare.test3 +test/some_lists_comparisons.lua:57: expected: {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 20 items, list B (expected) has 19 items +* lists A and B start differing at index 7 +* lists A and B are equals again from index 8 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 +* Common parts at the end of the lists + = A[8], B[7]: 8 + = A[9], B[8]: 9 + = A[10], B[9]: 10 + = A[11], B[10]: 11 + = A[12], B[11]: 12 + = A[13], B[12]: 13 + = A[14], B[13]: 14 + = A[15], B[14]: 15 + = A[16], B[15]: 16 + = A[17], B[16]: 17 + = A[18], B[17]: 18 + = A[19], B[18]: 19 + = A[20], B[19]: 20 +stack traceback: + test/some_lists_comparisons.lua:57: in function 'TestListCompare.test3' + +6) TestListCompare.test4 +test/some_lists_comparisons.lua:74: expected: {1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 20 items, list B (expected) has 17 items +* lists A and B start differing at index 7 +* lists A and B are equals again from index 10 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 + - A[8]: 8 + - A[9]: 9 +* Common parts at the end of the lists + = A[10], B[7]: 10 + = A[11], B[8]: 11 + = A[12], B[9]: 12 + = A[13], B[10]: 13 + = A[14], B[11]: 14 + = A[15], B[12]: 15 + = A[16], B[13]: 16 + = A[17], B[14]: 17 + = A[18], B[15]: 18 + = A[19], B[16]: 19 + = A[20], B[17]: 20 +stack traceback: + test/some_lists_comparisons.lua:74: in function 'TestListCompare.test4' + +7) TestListCompare.test5a +test/some_lists_comparisons.lua:98: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (expected) has 17 items, list B (actual) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:98: in function 'TestListCompare.test5a' + +8) TestListCompare.test5b +test/some_lists_comparisons.lua:103: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:103: in function 'TestListCompare.test5b' + +9) TestListCompare.test5c +test/some_lists_comparisons.lua:109: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* size of lists differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equals again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:109: in function 'TestListCompare.test5c' + +10) TestListCompare.test6 +test/some_lists_comparisons.lua:117: expected: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1, + 2, + 8=true, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +actual: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1, + 2, + 8=false, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 8 +* lists A and B are equals again from index 9 +* Common parts: + = A[1], B[1]: "aaa" + = A[2], B[2]: "bbb" + = A[3], B[3]: "ccc" + = A[4], B[4]: function: 00E70160 + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: nil +* Differing parts: + - A[8]: false + + B[8]: true +* Common parts at the end of the lists + = A[9], B[9]: false + = A[10], B[10]: thread: 00E35480 + = A[11], B[11]: thread: 00E35480 + = A[12], B[12]: thread: 00E35480 +stack traceback: + test/some_lists_comparisons.lua:117: in function 'TestListCompare.test6' + +11) TestListCompare.test7 +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 3 +* lists A and B are equals again from index 5 +* Common parts: + = A[1], B[1]: {1, 2, 3} + = A[2], B[2]: {1, 2} +* Differing parts: + - A[3]: {{2}, {2}} + + B[3]: {{1}, {2}} + - A[4]: {"aa", "bb"} + + B[4]: {"aa", "cc"} +* Common parts at the end of the lists + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: 1.33 + = A[8], B[8]: 1.#INF + = A[9], B[9]: {a=1} + = A[10], B[10]: {} +stack traceback: + test/some_lists_comparisons.lua:123: in function 'TestListCompare.test7' + +Ran 11 tests in 0.005 seconds, 0 successes, 11 failures diff --git a/test/some_lists_comparisons.lua b/test/some_lists_comparisons.lua new file mode 100644 index 00000000..ae78c6ae --- /dev/null +++ b/test/some_lists_comparisons.lua @@ -0,0 +1,146 @@ + +local lu = require('luaunit') + +local function range(start, stop) + -- return list of { start ... stop } + local i + local ret = {} + i=start + while i <= stop do + table.insert(ret, i) + i = i + 1 + end + return ret +end + + +TestListCompare = {} + + function TestListCompare:test1() + local A = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12211221, 122122212, 111221212121 } + local B = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12121221, 122122212, 111221212121 } + lu.assertEquals( A, B ) + end + + function TestListCompare:test1b() + local A = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12211221 } + local B = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12121221 } + lu.assertEquals( A, B ) + end + + function TestListCompare:test1c() + local A = { 12211221, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121 } + local B = { 12121221, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121 } + lu.assertEquals( A, B ) + end + + + -- long list of numbers, same size, swapped values + function TestListCompare:test2() + local x=7 + local A, B = range(1,20), range(1,20) + B[x], B[x+1] = B[x+1], B[x] + lu.assertEquals( A, B ) + end + + -- long list of numbers, one hole + function TestListCompare:test3() + local x=7 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x then + table.insert( B, A[i] ) + end + i = i + 1 + end + lu.assertEquals( A, B ) + end + + + -- long list of numbers, one bigger hole + function TestListCompare:test4() + local x=7 + local x2=8 + local x3=9 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x and i ~= x2 and i ~= x3 then + table.insert( B, A[i] ) + end + i = i + 1 + end + lu.assertEquals( A, B ) + end + + -- long list, difference + big hole + function TestListCompare:sub_test5() + local x=7 + local x2=8 + local x3=9 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x and i ~= x2 and i ~= x3 then + table.insert( B, A[i] ) + end + i = i + 1 + end + x = 5 + B[x], B[x+1] = B[x+1], B[x] + return A, B + end + + function TestListCompare:test5a() + local A, B = self:sub_test5() + lu.ORDER_ACTUAL_EXPECTED = false + lu.assertEquals( A, B ) + end + + function TestListCompare:test5b() + local A, B = self:sub_test5() + lu.assertEquals( B, A ) + end + + function TestListCompare:test5c() + local A, B = self :sub_test5() + lu.PRINT_TABLE_REF_IN_ERROR_MSG = true + lu.assertEquals( B, A ) + end + + function TestListCompare:test6() + local f1 = function () return nil end + local t1 = coroutine.create( function(v) local y=v+1 end ) + local A = { 'aaa', 'bbb', 'ccc', f1, 1.0, 2.0, nil, true, false, t1, t1, t1 } + local B = { 'aaa', 'bbb', 'ccc', f1, 1.0, 2.0, nil, false, false, t1, t1, t1 } + lu.assertEquals( B, A ) + end + + function TestListCompare:test7() + local A = { {1,2,3}, {1,2}, { {1}, {2} }, { 'aa', 'cc'}, 1, 2, 1.33, 1/0, { a=1 }, {} } + local B = { {1,2,3}, {1,2}, { {2}, {2} }, { 'aa', 'bb'}, 1, 2, 1.33, 1/0, { a=1 }, {} } + lu.assertEquals( B, A ) + end + + function TestListCompare:tearDown() + -- cancel effect of test5a + lu.ORDER_ACTUAL_EXPECTED = true + -- cancel effect of test5c + lu.PRINT_TABLE_REF_IN_ERROR_MSG = false + end +-- end TestListCompare + + +XTestDictCompare = {} + function XTestDictCompare:test1() + lu.assertEquals( {one=1,two=2, three=3}, {one=1,two=1, three=3} ) + end + + function XTestDictCompare:test2() + lu.assertEquals( {one=1,two=2, three=3, four=4, five=5}, {one=1,two=1, three=3, four=4, five=5} ) + end +-- end TestDictCompare + + +os.exit( lu.run() ) \ No newline at end of file diff --git a/test/test_luaunit.lua b/test/test_luaunit.lua index 94d00ae1..1f7b67dd 100644 --- a/test/test_luaunit.lua +++ b/test/test_luaunit.lua @@ -15,6 +15,19 @@ end -- This is a bit tricky since the test uses the features that it tests. +local function range(start, stop) + -- return list of { start ... stop } + local i + local ret = {} + i=start + while i <= stop do + table.insert(ret, i) + i = i + 1 + end + return ret +end + + local lu = require('luaunit') local Mock = { __class__ = 'Mock' } @@ -212,6 +225,40 @@ TestLuaUnitUtilities = { __class__ = 'TestLuaUnitUtilities' } lu.assertEquals( A, A ) end + function TestLuaUnitUtilities:test_suitableForMismatchFormatting() + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2}, {2,1} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( nil, { 1,2,3} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3}, {} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( "123", "123" ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( "123", "123" ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {'a','b','c'}, {'c', 'b', 'a'} )) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3, toto='titi'}, {1,2,3, toto='tata', tutu="bloup" } ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3, [5]=1000}, {1,2,3} ) ) + + local i=0 + local l1, l2={}, {} + while i <= lu.LIST_DIFF_ANALYSIS_THRESHOLD+1 do + i = i + 1 + table.insert( l1, i ) + table.insert( l2, i+1 ) + end + + lu.assertTrue( lu.private.tryMismatchFormatting( l1, l2 ) ) + end + + + function TestLuaUnitUtilities:test_diffAnalysisThreshold() + local threshold = lu.LIST_DIFF_ANALYSIS_THRESHOLD + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.DEFAULT_DEEP_ANALYSIS ) ) + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.DEFAULT_DEEP_ANALYSIS ) ) + + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.DISABLE_DEEP_ANALYSIS ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.DISABLE_DEEP_ANALYSIS ) ) + + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.FORCE_DEEP_ANALYSIS ) ) + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.FORCE_DEEP_ANALYSIS ) ) + end + function TestLuaUnitUtilities:test_prettystr() lu.assertEquals( lu.prettystr( 1 ), "1" ) lu.assertEquals( lu.prettystr( 1.1 ), "1.1" ) @@ -1885,8 +1932,11 @@ TestLuaUnitErrorMsg = { __class__ = 'TestLuaUnitErrorMsg' } assertFailureMatches('Contents of the tables are not identical:\nExpected: {one=2, two=3}\nActual: {1, 2}' , lu.assertItemsEquals, {1,2}, {one=2, two=3} ) assertFailureMatches( 'expected: {1, 2}\nactual: {2, 1}', lu.assertEquals, {2,1}, {1,2} ) -- trigger multiline prettystr - assertFailureMatches( 'expected: {1, 2, 3, 4}\nactual: {3, 2, 1, 4}', lu.assertEquals, {3,2,1,4}, {1,2,3,4} ) assertFailureMatches( 'expected: {one=1, two=2}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {one=1,two=2} ) + -- trigger mismatch formatting + lu.assertErrorMsgContains( [[lists Date: Wed, 9 Nov 2016 22:14:02 +0100 Subject: [PATCH 05/14] Use private function, not working with local function --- luaunit.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/luaunit.lua b/luaunit.lua index 96088513..35b1d277 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -523,7 +523,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) local k, v for k,v in pairs( ta ) do - if is_equals( v, tb[k] ) then + if M.private.is_equals( v, tb[k] ) then table.insert( keysCommon, k ) else if tb[k] == nil then @@ -535,7 +535,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) end for k,v in pairs( tb ) do - if not is_equals( v, ta[k] ) and ta[k] == nil then + if not M.private.is_equals( v, ta[k] ) and ta[k] == nil then table.insert( keysOnlyTb, k ) end end @@ -639,7 +639,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 1 while i <= longest do - if not is_equals(ta[i], tb[i]) then + if not M.private.is_equals(ta[i], tb[i]) then break end @@ -649,7 +649,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 0 while i > -shortest do - if not is_equals(ta[lta+i], tb[ltb+i]) then + if not M.private.is_equals(ta[lta+i], tb[ltb+i]) then break end i = i - 1 @@ -682,7 +682,7 @@ local function mismatchFormattingPureList( ta, tb ) local function insertABValue(i, bi) bi = bi or i - if is_equals( ta[i], tb[bi]) then + if M.private.is_equals( ta[i], tb[bi]) then return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) ) else extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i])) @@ -1029,7 +1029,7 @@ local function _is_table_equals(actual, expected, recursions) return true end M.private._is_table_equals = _is_table_equals -local is_equals = _is_table_equals +M.private.is_equals = _is_table_equals local function failure(msg, level) -- raise an error indicating a test failure From e612a73019ce867b85729666f5085cf78150479a Mon Sep 17 00:00:00 2001 From: Philippe F Date: Thu, 10 Nov 2016 22:33:07 +0100 Subject: [PATCH 06/14] Avoid values where lua 5.2 and 5.3 differ --- test/ref/some_lists_comparisons.txt | 24 ++++++++++++------------ test/some_lists_comparisons.lua | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/ref/some_lists_comparisons.txt b/test/ref/some_lists_comparisons.txt index 047c84ad..a9594635 100644 --- a/test/ref/some_lists_comparisons.txt +++ b/test/ref/some_lists_comparisons.txt @@ -338,8 +338,8 @@ test/some_lists_comparisons.lua:117: expected: "bbb", "ccc", function: 00E70160, - 1, - 2, + 1.1, + 2.1, 8=true, 9=false, 10=thread: 00E35480, @@ -352,8 +352,8 @@ actual: "bbb", "ccc", function: 00E70160, - 1, - 2, + 1.1, + 2.1, 8=false, 9=false, 10=thread: 00E35480, @@ -369,8 +369,8 @@ List difference analysis: = A[2], B[2]: "bbb" = A[3], B[3]: "ccc" = A[4], B[4]: function: 00E70160 - = A[5], B[5]: 1 - = A[6], B[6]: 2 + = A[5], B[5]: 1.1 + = A[6], B[6]: 2.1 = A[7], B[7]: nil * Differing parts: - A[8]: false @@ -771,8 +771,8 @@ test/some_lists_comparisons.lua:117: expected: "bbb", "ccc", function: 00E70160, - 1, - 2, + 1.1, + 2.1, 8=true, 9=false, 10=thread: 00E35480, @@ -785,8 +785,8 @@ actual: "bbb", "ccc", function: 00E70160, - 1, - 2, + 1.1, + 2.1, 8=false, 9=false, 10=thread: 00E35480, @@ -802,8 +802,8 @@ List difference analysis: = A[2], B[2]: "bbb" = A[3], B[3]: "ccc" = A[4], B[4]: function: 00E70160 - = A[5], B[5]: 1 - = A[6], B[6]: 2 + = A[5], B[5]: 1.1 + = A[6], B[6]: 2.1 = A[7], B[7]: nil * Differing parts: - A[8]: false diff --git a/test/some_lists_comparisons.lua b/test/some_lists_comparisons.lua index ae78c6ae..1c3fded0 100644 --- a/test/some_lists_comparisons.lua +++ b/test/some_lists_comparisons.lua @@ -112,8 +112,8 @@ TestListCompare = {} function TestListCompare:test6() local f1 = function () return nil end local t1 = coroutine.create( function(v) local y=v+1 end ) - local A = { 'aaa', 'bbb', 'ccc', f1, 1.0, 2.0, nil, true, false, t1, t1, t1 } - local B = { 'aaa', 'bbb', 'ccc', f1, 1.0, 2.0, nil, false, false, t1, t1, t1 } + local A = { 'aaa', 'bbb', 'ccc', f1, 1.1, 2.1, nil, true, false, t1, t1, t1 } + local B = { 'aaa', 'bbb', 'ccc', f1, 1.1, 2.1, nil, false, false, t1, t1, t1 } lu.assertEquals( B, A ) end From 177659ed4fb2a72b1e9ec59554e928d4bad9f0ac Mon Sep 17 00:00:00 2001 From: Philippe F Date: Thu, 10 Nov 2016 22:33:45 +0100 Subject: [PATCH 07/14] Adjust representation of inf for lua 5.3 and add guards for lua 5.3 --- run_functional_tests.lua | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/run_functional_tests.lua b/run_functional_tests.lua index ad91b9dd..781ba563 100755 --- a/run_functional_tests.lua +++ b/run_functional_tests.lua @@ -107,16 +107,19 @@ do os.remove(xmllint_output_fname) end -local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) +local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, pattern2, verbose ) --[[ Adjust the content of fileOut by copying lines matching pattern from fileIn fileIn lines are read and the first line matching pattern is analysed. The first pattern capture is memorized. - fileOut lines are then read, and the first line matching pattern is modified, by applying + fileOut lines are then read, and the first line matching pattern2 is modified, by applying the first capture of fileIn. fileOut is then rewritten. + + In most cases, pattern2 may be nil in which case, pattern is used when matching in fileout. ]] local source = nil + local pattern2 = pattern2 or pattern local idxStart, idxEnd, capture for line in io.lines(fileIn) do idxStart, idxEnd, capture = line:find( pattern ) @@ -142,8 +145,11 @@ local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) local dest, linesOut = nil, {} for line in io.lines(fileOut) do - idxStart, idxEnd, capture = line:find( pattern ) + idxStart, idxEnd, capture = line:find( pattern2 ) while idxStart ~= nil do + if capture == nil then + print('missing pattern for outfile!') + end dest = capture if verbose then print('Modifying line: '..line ) @@ -154,7 +160,7 @@ local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) if verbose then print('Result : '..line ) end - idxStart, idxEnd, capture = line:find( pattern, idxEnd ) + idxStart, idxEnd, capture = line:find( pattern2, idxEnd ) end table.insert( linesOut, line ) end @@ -178,8 +184,10 @@ local function check_tap_output( fileToRun, options, output, refOutput, refExitC adjustFile( output, refOutput, '# Started on (.*)') adjustFile( output, refOutput, '# Ran %d+ tests in (%d+.%d*).*') - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + end if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then error('TAP Output mismatch for file : '..output) @@ -201,9 +209,15 @@ local function check_text_output( fileToRun, options, output, refOutput, refExit adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) adjustFile( output, refOutput, 'thread: (0?x?[%x]+)', true ) adjustFile( output, refOutput, 'function: (0?x?[%x]+)', true ) - adjustFile( output, refOutput, '', true, false ) - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) + adjustFile( output, refOutput, '', true ) + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + -- For Lua 5.3: different output for floats which are ints + adjustFile( output, output, '(%d)%.0' ) + -- For Lua 5.3: different output for inf + adjustFile( output, refOutput, '(1%.#INF)', true, '(inf)', false ) + end if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then error('Text Output mismatch for file : '..output) @@ -238,10 +252,12 @@ local function check_xml_output( fileToRun, options, output, xmlOutput, xmlLintO adjustFile( xmlOutput, refXmlOutput, '.*') - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) - adjustFile( xmlOutput, refXmlOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + adjustFile( xmlOutput, refXmlOutput, '.*%.lua:%d+: in (%S*) .*', true ) + end if HAS_XMLLINT then -- General xmllint validation From aeab493e731d7c65e39b73bbfaa79e67e5f6b553 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 22:05:13 +0100 Subject: [PATCH 08/14] Rename is_equals to is_equal and define it as a local function --- luaunit.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/luaunit.lua b/luaunit.lua index 6d245f3a..86cc3373 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -88,6 +88,8 @@ Options: TestClass or TestClass.testMethod ]] +local is_equal -- defined here to allow calling from mismatchFormattingPureList + ---------------------------------------------------------------- -- -- general utility functions @@ -541,7 +543,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) local k, v for k,v in pairs( ta ) do - if M.private.is_equals( v, tb[k] ) then + if is_equal( v, tb[k] ) then table.insert( keysCommon, k ) else if tb[k] == nil then @@ -553,7 +555,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) end for k,v in pairs( tb ) do - if not M.private.is_equals( v, ta[k] ) and ta[k] == nil then + if not is_equal( v, ta[k] ) and ta[k] == nil then table.insert( keysOnlyTb, k ) end end @@ -657,7 +659,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 1 while i <= longest do - if not M.private.is_equals(ta[i], tb[i]) then + if not is_equal(ta[i], tb[i]) then break end @@ -667,7 +669,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 0 while i > -shortest do - if not M.private.is_equals(ta[lta+i], tb[ltb+i]) then + if not is_equal(ta[lta+i], tb[ltb+i]) then break end i = i - 1 @@ -700,7 +702,7 @@ local function mismatchFormattingPureList( ta, tb ) local function insertABValue(i, bi) bi = bi or i - if M.private.is_equals( ta[i], tb[bi]) then + if is_equal( ta[i], tb[bi]) then return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) ) else extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i])) @@ -1041,7 +1043,7 @@ local function _is_table_equals(actual, expected, recursions) return true end M.private._is_table_equals = _is_table_equals -M.private.is_equals = _is_table_equals +is_equal = _is_table_equals local function failure(msg, level) -- raise an error indicating a test failure From aec57a23d243abd25f186c0a3ba1a38d4bae17a7 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 22:21:22 +0100 Subject: [PATCH 09/14] Rename variables for more readability --- luaunit.lua | 122 ++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/luaunit.lua b/luaunit.lua index 86cc3373..6cfd3972 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -444,13 +444,13 @@ local function prettystr( v, keeponeline ) end M.prettystr = prettystr -local function tryMismatchFormatting( ta, tb, doDeepAnalysis ) +local function tryMismatchFormatting( table_a, table_b, doDeepAnalysis ) --[[ Prepares a nice error message when comparing tables, performing a deeper analysis. Arguments: - * ta, tb: tables to be compared + * table_a, table_b: tables to be compared * doDeepAnalysis: M.DEFAULT_DEEP_ANALYSIS: (the default if not specified) perform deep analysis only for big lists and big dictionnaries M.FORCE_DEEP_ANALYSIS : always perform deep analysis @@ -463,8 +463,8 @@ local function tryMismatchFormatting( ta, tb, doDeepAnalysis ) ]] local isPureList - -- check if ta & tb are suitable for deep analysis - if type(ta) ~= 'table' or type(tb) ~= 'table' then + -- check if table_a & table_b are suitable for deep analysis + if type(table_a) ~= 'table' or type(table_b) ~= 'table' then return false end @@ -472,57 +472,57 @@ local function tryMismatchFormatting( ta, tb, doDeepAnalysis ) return false end - local k1, k2, v1, v2, lv1, lv2 - lv1 = #ta - lv2 = #tb + local k1, k2, v1, v2, len_a, len_b + len_a = #table_a + len_b = #table_b isPureList = true - for k1, v1 in pairs(ta) do - if type(k1) ~= 'number' or k1 > lv1 then + for k1, v1 in pairs(table_a) do + if type(k1) ~= 'number' or k1 > len_a then -- this table a mapping isPureList = false break end end - for k2, v2 in pairs(tb) do - if not isPureList or type(k2) ~= 'number' or k2 > lv2 then + for k2, v2 in pairs(table_b) do + if not isPureList or type(k2) ~= 'number' or k2 > len_b then -- this table a mapping isPureList = false break end end - if isPureList and math.min(lv1, lv2) < M.LIST_DIFF_ANALYSIS_THRESHOLD then + if isPureList and math.min(len_a, len_b) < M.LIST_DIFF_ANALYSIS_THRESHOLD then if not (doDeepAnalysis == M.FORCE_DEEP_ANALYSIS) then return false end end if isPureList then - return M.private.mismatchFormattingPureList( ta, tb ) + return M.private.mismatchFormattingPureList( table_a, table_b ) else -- only work on mapping for the moment - -- return M.private.mismatchFormattingMapping( ta, tb, doDeepAnalysis ) + -- return M.private.mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) return false end end M.private.tryMismatchFormatting = tryMismatchFormatting -local function getTaTbDesc() - local descta, desctb - descta, desctb = 'actual', 'expected' +local function getTaTbDescr() + local descrTa, descrTb + descrTa, descrTb = 'actual', 'expected' if not M.ORDER_ACTUAL_EXPECTED then - descta, desctb = desctb, descta + descrTa, descrTb = descrTb, descrTa end - return descta, desctb + return descrTa, descrTb end local function extendWithStrFmt( res, ... ) table.insert( res, string.format( ... ) ) end -local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) +local function mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) --[[ Prepares a nice error message when comparing tables which are not pure lists, performing a deeper analysis. @@ -533,7 +533,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) * result: if success is true, a multi-line string with deep analysis of the two lists ]] local result = {} - local descta, desctb = getTaTbDesc() + local descrTa, descrTb = getTaTbDescr() local keysCommon = {} local keysOnlyTa = {} @@ -542,11 +542,11 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) local k, v - for k,v in pairs( ta ) do - if is_equal( v, tb[k] ) then + for k,v in pairs( table_a ) do + if is_equal( v, table_b[k] ) then table.insert( keysCommon, k ) else - if tb[k] == nil then + if table_b[k] == nil then table.insert( keysOnlyTa, k ) else table.insert( keysDiffTaTb, k ) @@ -554,26 +554,26 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) end end - for k,v in pairs( tb ) do - if not is_equal( v, ta[k] ) and ta[k] == nil then + for k,v in pairs( table_b ) do + if not is_equal( v, table_a[k] ) and table_a[k] == nil then table.insert( keysOnlyTb, k ) end end - local lta = #keysCommon + #keysDiffTaTb + #keysOnlyTa - local ltb = #keysCommon + #keysDiffTaTb + #keysOnlyTb - local limited_display = (lta < 5 or ltb < 5) + local len_a = #keysCommon + #keysDiffTaTb + #keysOnlyTa + local len_b = #keysCommon + #keysDiffTaTb + #keysOnlyTb + local limited_display = (len_a < 5 or len_b < 5) - if math.min(lta, ltb) < M.TABLE_DIFF_ANALYSIS_THRESHOLD then + if math.min(len_a, len_b) < M.TABLE_DIFF_ANALYSIS_THRESHOLD then return false end if not limited_display then - if lta == ltb then - extendWithStrFmt( result, 'Table A (%s) and B (%s) both have %d items', descta, desctb, lta ) + if len_a == len_b then + extendWithStrFmt( result, 'Table A (%s) and B (%s) both have %d items', descrTa, descrTb, len_a ) else - extendWithStrFmt( result, 'Table A (%s) has %d items and table B (%s) has %d items', descta, lta, desctb, ltb ) - end + extendWithStrFmt( result, 'Table A (%s) has %d items and table B (%s) has %d items', descrTa, len_a, descrTb, len_b ) + end if #keysCommon == 0 and #keysDiffTaTb == 0 then table.insert( result, 'Table A and B have no keys in common, they are totally different') @@ -606,29 +606,29 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) if #keysDiffTaTb ~= 0 then table.insert( result, 'Items differing in A and B:') for k,v in sortedPairs( keysDiffTaTb ) do - extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(ta[v]) ) - extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(tb[v]) ) + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(table_a[v]) ) + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(table_b[v]) ) end end if #keysOnlyTa ~= 0 then table.insert( result, 'Items only in table A:' ) for k,v in sortedPairs( keysOnlyTa ) do - extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(ta[v]) ) + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(table_a[v]) ) end end if #keysOnlyTb ~= 0 then table.insert( result, 'Items only in table B:' ) for k,v in sortedPairs( keysOnlyTb ) do - extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(tb[v]) ) + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(table_b[v]) ) end end if #keysCommon ~= 0 then table.insert( result, 'Items common to A and B:') for k,v in sortedPairs( keysCommon ) do - extendWithStrFmt( result, ' = A and B [%s]: %s', keytostring(v), prettystr(ta[v]) ) + extendWithStrFmt( result, ' = A and B [%s]: %s', keytostring(v), prettystr(table_a[v]) ) end end @@ -636,7 +636,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis ) end M.private.mismatchFormattingMapping = mismatchFormattingMapping -local function mismatchFormattingPureList( ta, tb ) +local function mismatchFormattingPureList( table_a, table_b ) --[[ Prepares a nice error message when comparing tables which are lists, performing a deeper analysis. @@ -647,19 +647,19 @@ local function mismatchFormattingPureList( ta, tb ) * result: if success is true, a multi-line string with deep analysis of the two lists ]] local result = {} - local descta, desctb = getTaTbDesc() + local descrTa, descrTb = getTaTbDescr() - local lta = #ta - local ltb = #tb + local len_a = #table_a + local len_b = #table_b local i - local longest = math.max(lta, ltb) - local shortest = math.min(lta, ltb) + local longest = math.max(len_a, len_b) + local shortest = math.min(len_a, len_b) local deltalv = longest - shortest local commonUntil, commonBackTo i = 1 while i <= longest do - if not is_equal(ta[i], tb[i]) then + if not is_equal(table_a[i], table_b[i]) then break end @@ -669,7 +669,7 @@ local function mismatchFormattingPureList( ta, tb ) i = 0 while i > -shortest do - if not is_equal(ta[lta+i], tb[ltb+i]) then + if not is_equal(table_a[len_a+i], table_b[len_b+i]) then break end i = i - 1 @@ -679,34 +679,34 @@ local function mismatchFormattingPureList( ta, tb ) local refa, refb = '', '' if M.PRINT_TABLE_REF_IN_ERROR_MSG then - refa, refb = string.format( '<%s> ', tostring(ta)), string.format('<%s> ', tostring(tb) ) + refa, refb = string.format( '<%s> ', tostring(table_a)), string.format('<%s> ', tostring(table_b) ) end table.insert( result, 'List difference analysis:' ) - if lta == ltb then + if len_a == len_b then -- TODO: handle expected/actual naming - extendWithStrFmt( result, '* lists %sA (%s) and %sB (%s) have the same size', refa, descta, refb, desctb ) + extendWithStrFmt( result, '* lists %sA (%s) and %sB (%s) have the same size', refa, descrTa, refb, descrTb ) else - extendWithStrFmt( result, '* size of lists differ: list %sA (%s) has %d items, list %sB (%s) has %d items', refa, descta, lta, refb, desctb, ltb ) + extendWithStrFmt( result, '* size of lists differ: list %sA (%s) has %d items, list %sB (%s) has %d items', refa, descrTa, len_a, refb, descrTb, len_b ) end i = 1 extendWithStrFmt( result, '* lists A and B start differing at index %d', commonUntil+1 ) if commonBackTo < 1 then if deltalv > 0 then - extendWithStrFmt( result, '* lists A and B are equals again from index %d for A, %d for B', lta+commonBackTo, ltb+commonBackTo ) + extendWithStrFmt( result, '* lists A and B are equals again from index %d for A, %d for B', len_a+commonBackTo, len_b+commonBackTo ) else - extendWithStrFmt( result, '* lists A and B are equals again from index %d', lta+commonBackTo ) + extendWithStrFmt( result, '* lists A and B are equals again from index %d', len_a+commonBackTo ) end end local function insertABValue(i, bi) bi = bi or i - if is_equal( ta[i], tb[bi]) then - return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) ) + if is_equal( table_a[i], table_b[bi]) then + return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(table_a[i]) ) else - extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i])) - extendWithStrFmt( result, ' + B[%d]: %s', bi, prettystr(tb[bi])) + extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(table_a[i])) + extendWithStrFmt( result, ' + B[%d]: %s', bi, prettystr(table_b[bi])) end end @@ -733,12 +733,12 @@ local function mismatchFormattingPureList( ta, tb ) table.insert( result, '* Present only in one list:' ) end while i < longest + commonBackTo do - if lta > ltb then - extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i]) ) + if len_a > len_b then + extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(table_a[i]) ) -- table.insert( result, '+ (no matching B index)') else -- table.insert( result, '- no matching A index') - extendWithStrFmt( result, ' + B[%d]: %s', i, prettystr(tb[i]) ) + extendWithStrFmt( result, ' + B[%d]: %s', i, prettystr(table_b[i]) ) end i = i + 1 end @@ -748,7 +748,7 @@ local function mismatchFormattingPureList( ta, tb ) table.insert( result, '* Common parts at the end of the lists' ) end while i <= longest do - if lta > ltb then + if len_a > len_b then insertABValue( i, i-deltalv ) else insertABValue( i-deltalv, i ) From e32387d2c64e4eec8d5effd91ba76723b988f584 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 22:23:14 +0100 Subject: [PATCH 10/14] Avoid luacheck warning --- test/some_lists_comparisons.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/some_lists_comparisons.lua b/test/some_lists_comparisons.lua index 1c3fded0..ee5cf3ef 100644 --- a/test/some_lists_comparisons.lua +++ b/test/some_lists_comparisons.lua @@ -131,8 +131,8 @@ TestListCompare = {} end -- end TestListCompare - -XTestDictCompare = {} +--[[ +TestDictCompare = {} function XTestDictCompare:test1() lu.assertEquals( {one=1,two=2, three=3}, {one=1,two=1, three=3} ) end @@ -141,6 +141,7 @@ XTestDictCompare = {} lu.assertEquals( {one=1,two=2, three=3, four=4, five=5}, {one=1,two=1, three=3, four=4, five=5} ) end -- end TestDictCompare +]] os.exit( lu.run() ) \ No newline at end of file From 14095c7131137f293a1f75053f7ab41cc8a211d0 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 22:34:15 +0100 Subject: [PATCH 11/14] Use the canonical form "inf" for reference text file and adjust output when the alternate form "1.#INF" is used. --- run_functional_tests.lua | 4 ++-- test/ref/some_lists_comparisons.txt | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/run_functional_tests.lua b/run_functional_tests.lua index 781ba563..c689d6e1 100755 --- a/run_functional_tests.lua +++ b/run_functional_tests.lua @@ -210,13 +210,13 @@ local function check_text_output( fileToRun, options, output, refOutput, refExit adjustFile( output, refOutput, 'thread: (0?x?[%x]+)', true ) adjustFile( output, refOutput, 'function: (0?x?[%x]+)', true ) adjustFile( output, refOutput, '', true ) + -- number infinite displayed as "1.#INF" on Windows, lua 5.1 and 5.2, displayed "inf" on Windows lua 5.3 and linux + adjustFile( output, refOutput, '(inf)', true, '(1%.#INF)', false ) if _VERSION == 'Lua 5.3' then -- For Lua 5.3: stack trace uses "method" instead of "function" adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) -- For Lua 5.3: different output for floats which are ints adjustFile( output, output, '(%d)%.0' ) - -- For Lua 5.3: different output for inf - adjustFile( output, refOutput, '(1%.#INF)', true, '(inf)', false ) end if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then diff --git a/test/ref/some_lists_comparisons.txt b/test/ref/some_lists_comparisons.txt index a9594635..821cd3ef 100644 --- a/test/ref/some_lists_comparisons.txt +++ b/test/ref/some_lists_comparisons.txt @@ -381,8 +381,8 @@ List difference analysis: = A[11], B[11]: thread: 00E35480 = A[12], B[12]: thread: 00E35480 TestListCompare.test7 ... FAIL -test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} -actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, inf, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, inf, {a=1}, {}} List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 3 @@ -399,7 +399,7 @@ List difference analysis: = A[5], B[5]: 1 = A[6], B[6]: 2 = A[7], B[7]: 1.33 - = A[8], B[8]: 1.#INF + = A[8], B[8]: inf = A[9], B[9]: {a=1} = A[10], B[10]: {} ========================================================= @@ -817,8 +817,8 @@ stack traceback: test/some_lists_comparisons.lua:117: in function 'TestListCompare.test6' 11) TestListCompare.test7 -test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} -actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, 1.#INF, {a=1}, {}} +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, inf, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, inf, {a=1}, {}} List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 3 @@ -835,7 +835,7 @@ List difference analysis: = A[5], B[5]: 1 = A[6], B[6]: 2 = A[7], B[7]: 1.33 - = A[8], B[8]: 1.#INF + = A[8], B[8]: inf = A[9], B[9]: {a=1} = A[10], B[10]: {} stack traceback: From 9c9e3d7831ba106b1e2af934d54c28659c3582c4 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 22:46:59 +0100 Subject: [PATCH 12/14] Use smaller number to avoid triggering printing with exponentiation on lua compiled with integer as a single precision float (as opposed to default double precision) --- test/ref/some_lists_comparisons.txt | 408 ++++++++++++++-------------- test/some_lists_comparisons.lua | 12 +- 2 files changed, 210 insertions(+), 210 deletions(-) diff --git a/test/ref/some_lists_comparisons.txt b/test/ref/some_lists_comparisons.txt index 821cd3ef..f835bb25 100644 --- a/test/ref/some_lists_comparisons.txt +++ b/test/ref/some_lists_comparisons.txt @@ -2,144 +2,144 @@ Started on 11/08/16 21:28:53 TestListCompare.test1 ... FAIL test/some_lists_comparisons.lua:22: expected: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12121221, - 122122212, - 111221212121 + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 121221, + 121212, + 122121 } actual: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12211221, - 122122212, - 111221212121 + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 122121, + 121212, + 122121 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 9 * lists A and B are equals again from index 10 * Common parts: - = A[1], B[1]: 1212212 - = A[2], B[2]: 12221122 - = A[3], B[3]: 1212212 - = A[4], B[4]: 12221122 - = A[5], B[5]: 1212212 - = A[6], B[6]: 12221122 - = A[7], B[7]: 1212212 - = A[8], B[8]: 12221122 + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 * Differing parts: - - A[9]: 12211221 - + B[9]: 12121221 + - A[9]: 122121 + + B[9]: 121221 * Common parts at the end of the lists - = A[10], B[10]: 122122212 - = A[11], B[11]: 111221212121 + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 TestListCompare.test1b ... FAIL test/some_lists_comparisons.lua:28: expected: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12121221 + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 121212 } actual: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12211221 + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 122112 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 11 * Common parts: - = A[1], B[1]: 1212212 - = A[2], B[2]: 12221122 - = A[3], B[3]: 1212212 - = A[4], B[4]: 12221122 - = A[5], B[5]: 1212212 - = A[6], B[6]: 12221122 - = A[7], B[7]: 1212212 - = A[8], B[8]: 12221122 - = A[9], B[9]: 1212212 - = A[10], B[10]: 12221122 + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122112 + = A[5], B[5]: 121212 + = A[6], B[6]: 121122 + = A[7], B[7]: 121212 + = A[8], B[8]: 122122 + = A[9], B[9]: 121212 + = A[10], B[10]: 122112 * Differing parts: - - A[11]: 12211221 - + B[11]: 12121221 + - A[11]: 122112 + + B[11]: 121212 TestListCompare.test1c ... FAIL test/some_lists_comparisons.lua:34: expected: { - 12121221, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121 + 121212, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 } actual: { - 12211221, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121 + 122112, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 1 * lists A and B are equals again from index 2 * Differing parts: - - A[1]: 12211221 - + B[1]: 12121221 + - A[1]: 122112 + + B[1]: 121212 * Common parts at the end of the lists - = A[2], B[2]: 122122212 - = A[3], B[3]: 111221212121 - = A[4], B[4]: 122122212 - = A[5], B[5]: 111221212121 - = A[6], B[6]: 122122212 - = A[7], B[7]: 111221212121 - = A[8], B[8]: 122122212 - = A[9], B[9]: 111221212121 - = A[10], B[10]: 122122212 - = A[11], B[11]: 111221212121 + = A[2], B[2]: 122121 + = A[3], B[3]: 111212 + = A[4], B[4]: 122121 + = A[5], B[5]: 122121 + = A[6], B[6]: 121212 + = A[7], B[7]: 121121 + = A[8], B[8]: 121212 + = A[9], B[9]: 121221 + = A[10], B[10]: 122212 + = A[11], B[11]: 112121 TestListCompare.test2 ... FAIL test/some_lists_comparisons.lua:43: expected: {1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} @@ -408,150 +408,150 @@ Failed tests: 1) TestListCompare.test1 test/some_lists_comparisons.lua:22: expected: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12121221, - 122122212, - 111221212121 + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 121221, + 121212, + 122121 } actual: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12211221, - 122122212, - 111221212121 + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 122121, + 121212, + 122121 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 9 * lists A and B are equals again from index 10 * Common parts: - = A[1], B[1]: 1212212 - = A[2], B[2]: 12221122 - = A[3], B[3]: 1212212 - = A[4], B[4]: 12221122 - = A[5], B[5]: 1212212 - = A[6], B[6]: 12221122 - = A[7], B[7]: 1212212 - = A[8], B[8]: 12221122 + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 * Differing parts: - - A[9]: 12211221 - + B[9]: 12121221 + - A[9]: 122121 + + B[9]: 121221 * Common parts at the end of the lists - = A[10], B[10]: 122122212 - = A[11], B[11]: 111221212121 + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 stack traceback: test/some_lists_comparisons.lua:22: in function 'TestListCompare.test1' 2) TestListCompare.test1b test/some_lists_comparisons.lua:28: expected: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12121221 + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 121212 } actual: { - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 1212212, - 12221122, - 12211221 + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 122112 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 11 * Common parts: - = A[1], B[1]: 1212212 - = A[2], B[2]: 12221122 - = A[3], B[3]: 1212212 - = A[4], B[4]: 12221122 - = A[5], B[5]: 1212212 - = A[6], B[6]: 12221122 - = A[7], B[7]: 1212212 - = A[8], B[8]: 12221122 - = A[9], B[9]: 1212212 - = A[10], B[10]: 12221122 + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122112 + = A[5], B[5]: 121212 + = A[6], B[6]: 121122 + = A[7], B[7]: 121212 + = A[8], B[8]: 122122 + = A[9], B[9]: 121212 + = A[10], B[10]: 122112 * Differing parts: - - A[11]: 12211221 - + B[11]: 12121221 + - A[11]: 122112 + + B[11]: 121212 stack traceback: test/some_lists_comparisons.lua:28: in function 'TestListCompare.test1b' 3) TestListCompare.test1c test/some_lists_comparisons.lua:34: expected: { - 12121221, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121 + 121212, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 } actual: { - 12211221, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121, - 122122212, - 111221212121 + 122112, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 } List difference analysis: * lists A (actual) and B (expected) have the same size * lists A and B start differing at index 1 * lists A and B are equals again from index 2 * Differing parts: - - A[1]: 12211221 - + B[1]: 12121221 + - A[1]: 122112 + + B[1]: 121212 * Common parts at the end of the lists - = A[2], B[2]: 122122212 - = A[3], B[3]: 111221212121 - = A[4], B[4]: 122122212 - = A[5], B[5]: 111221212121 - = A[6], B[6]: 122122212 - = A[7], B[7]: 111221212121 - = A[8], B[8]: 122122212 - = A[9], B[9]: 111221212121 - = A[10], B[10]: 122122212 - = A[11], B[11]: 111221212121 + = A[2], B[2]: 122121 + = A[3], B[3]: 111212 + = A[4], B[4]: 122121 + = A[5], B[5]: 122121 + = A[6], B[6]: 121212 + = A[7], B[7]: 121121 + = A[8], B[8]: 121212 + = A[9], B[9]: 121221 + = A[10], B[10]: 122212 + = A[11], B[11]: 112121 stack traceback: test/some_lists_comparisons.lua:34: in function 'TestListCompare.test1c' diff --git a/test/some_lists_comparisons.lua b/test/some_lists_comparisons.lua index ee5cf3ef..329190a4 100644 --- a/test/some_lists_comparisons.lua +++ b/test/some_lists_comparisons.lua @@ -17,20 +17,20 @@ end TestListCompare = {} function TestListCompare:test1() - local A = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12211221, 122122212, 111221212121 } - local B = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12121221, 122122212, 111221212121 } + local A = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 122121, 121212, 122121 } + local B = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 121221, 121212, 122121 } lu.assertEquals( A, B ) end function TestListCompare:test1b() - local A = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12211221 } - local B = { 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 1212212, 12221122, 12121221 } + local A = { 121221, 122211, 121221, 122112, 121212, 121122, 121212, 122122, 121212, 122112, 122112 } + local B = { 121221, 122211, 121221, 122112, 121212, 121122, 121212, 122122, 121212, 122112, 121212 } lu.assertEquals( A, B ) end function TestListCompare:test1c() - local A = { 12211221, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121 } - local B = { 12121221, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121, 122122212, 111221212121 } + local A = { 122112, 122121, 111212, 122121, 122121, 121212, 121121, 121212, 121221, 122212, 112121 } + local B = { 121212, 122121, 111212, 122121, 122121, 121212, 121121, 121212, 121221, 122212, 112121 } lu.assertEquals( A, B ) end From 514906583283261495d1bed7357a0dd7f8f33311 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sat, 12 Nov 2016 23:09:04 +0100 Subject: [PATCH 13/14] No longer need to explicitly ignore test names file by file, the global default already takes care of it --- .luacheckrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 5e7bc729..405c9229 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -22,8 +22,5 @@ files = { }, ["test/test_luaunit.lua"] = { ignore = {"TestMock", "TestLuaUnit%a+", "MyTest%w+", "v", "y" } - }, - ["test/some_lists_comparisons.lua"] = { - ignore = {"Test%w+"} } } From f304be6e8cea44581bc9bf4fc27255eae14ddde3 Mon Sep 17 00:00:00 2001 From: Philippe F Date: Sun, 13 Nov 2016 21:03:25 +0100 Subject: [PATCH 14/14] Disable unused code to keep code coverage high --- luaunit.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/luaunit.lua b/luaunit.lua index 454e2007..6c68d902 100755 --- a/luaunit.lua +++ b/luaunit.lua @@ -532,6 +532,9 @@ local function mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) in this case, just use standard assertion message * result: if success is true, a multi-line string with deep analysis of the two lists ]] + + -- disable for the moment + --[[ local result = {} local descrTa, descrTb = getTaTbDescr() @@ -633,6 +636,7 @@ local function mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) end return true, table.concat( result, '\n') + ]] end M.private.mismatchFormattingMapping = mismatchFormattingMapping