Skip to content

Commit 3d5bb53

Browse files
committed
Print string values such that they look like strings
1 parent 811b4fa commit 3d5bb53

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

rockspecs/mach-4.7-0.rockspec

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package = 'mach'
2+
version = '4.7-0'
3+
source = {
4+
url = 'https://github.com/ryanplusplus/mach.lua/archive/v4.7-0.tar.gz',
5+
dir = 'mach.lua-4.7-0/src'
6+
}
7+
description = {
8+
summary = 'Simple mocking framework for Lua inspired by CppUMock and designed for readability.',
9+
homepage = 'https://github.com/ryanplusplus/mach.lua/',
10+
license = 'MIT <http://opensource.org/licenses/MIT>'
11+
}
12+
dependencies = {
13+
'lua >= 5.1'
14+
}
15+
build = {
16+
type = 'builtin',
17+
modules = {
18+
['mach'] = 'mach.lua',
19+
['mach.Expectation'] = 'mach/Expectation.lua',
20+
['mach.ExpectedCall'] = 'mach/ExpectedCall.lua',
21+
['mach.CompletedCall'] = 'mach/CompletedCall.lua',
22+
['mach.unexpected_call_error'] = 'mach/unexpected_call_error.lua',
23+
['mach.unexpected_args_error'] = 'mach/unexpected_args_error.lua',
24+
['mach.out_of_order_call_error'] = 'mach/out_of_order_call_error.lua',
25+
['mach.not_all_calls_occurred_error'] ='mach/not_all_calls_occurred_error.lua',
26+
['mach.format_call_status'] = 'mach/format_call_status.lua',
27+
['mach.format_arguments'] = 'mach/format_arguments.lua',
28+
['mach.format_value'] = 'mach/format_value.lua',
29+
['mach.deep_compare_matcher'] = 'mach/deep_compare_matcher.lua',
30+
['mach.match'] = 'mach/match.lua',
31+
['mach.any'] = 'mach/any.lua',
32+
}
33+
}

rockspecs/mach-git-0.rockspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ build = {
2525
['mach.not_all_calls_occurred_error'] ='mach/not_all_calls_occurred_error.lua',
2626
['mach.format_call_status'] = 'mach/format_call_status.lua',
2727
['mach.format_arguments'] = 'mach/format_arguments.lua',
28+
['mach.format_value'] = 'mach/format_value.lua',
2829
['mach.deep_compare_matcher'] = 'mach/deep_compare_matcher.lua',
2930
['mach.match'] = 'mach/match.lua',
3031
['mach.any'] = 'mach/any.lua',

spec/mach_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ describe('The mach library', function()
485485
end)
486486

487487
it('should handle unexpected calls outside of an expectation', function()
488-
should_fail_with('Unexpected function call f(1, 2, 3)', function()
489-
mach.mock_function('f')(1, 2, 3)
488+
should_fail_with("Unexpected function call f(1, 2, '3')", function()
489+
mach.mock_function('f')(1, 2, '3')
490490
end)
491491
end)
492492

@@ -685,10 +685,10 @@ describe('The mach library', function()
685685
local expected_failure =
686686
'Unexpected arguments (4) provided to function f\n' ..
687687
'Incomplete calls:\n' ..
688-
'\tf(<mach.match(3)>)'
688+
"\tf(<mach.match('3')>)"
689689

690690
should_fail_with_exactly(expected_failure, function()
691-
f:should_be_called_with(mach.match(3)):when(function()
691+
f:should_be_called_with(mach.match('3')):when(function()
692692
f(4)
693693
end)
694694
end)

src/mach/format_arguments.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
local format_value = require 'mach.format_value'
2+
13
return function(args)
24
local arg_strings = {}
35
for i = 1, args.n do
4-
table.insert(arg_strings, tostring(args[i]))
6+
table.insert(arg_strings, format_value(args[i]))
57
end
68

79
return '(' .. table.concat(arg_strings, ', ') .. ')'

src/mach/format_value.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return function(v)
2+
if type(v) == 'string' then
3+
return "'" .. v .. "'"
4+
else
5+
return tostring(v)
6+
end
7+
end

src/mach/match.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
local format_value = require 'mach.format_value'
2+
13
return {
24
__tostring = function(o)
3-
return '<mach.match(' .. tostring(o.value) .. ')>'
5+
return '<mach.match(' .. format_value(o.value) .. ')>'
46
end
57
}

0 commit comments

Comments
 (0)