Skip to content

Commit 1496832

Browse files
committed
Change with_output Test Utility
with_output now returns the recorded output
1 parent 6572e3f commit 1496832

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

test/test.lua

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ local function with_input(input_data, test_func)
1818
input_file:close()
1919
end
2020

21-
local function with_output(expected_output, test_func)
21+
local function with_output(test_func)
2222
local output_file = io.tmpfile()
2323
test_func(output_file)
2424
output_file:flush()
2525
output_file:seek"set"
26-
assert(output_file:read"*a" == expected_output)
26+
output = output_file:read"*a"
2727
output_file:close()
28+
return output
2829
end
2930

3031
test("read sanity", function()
@@ -34,9 +35,10 @@ test("read sanity", function()
3435
end)
3536

3637
test("write sanity", function()
37-
with_output("12:hello world!,", function(stream)
38+
local output = with_output(function(stream)
3839
netstring.write(stream, "hello world!")
3940
end)
41+
assert(output == "12:hello world!,")
4042
end)
4143

4244
test("read empty", function()
@@ -53,10 +55,11 @@ test("multiple reads", function()
5355
end)
5456

5557
test("multiple writes", function()
56-
with_output("5:hello,5:world,", function(stream)
58+
local output = with_output(function(stream)
5759
netstring.write(stream, "hello")
5860
netstring.write(stream, "world")
5961
end)
62+
assert(output == "5:hello,5:world,")
6063
end)
6164

6265
test("half read", function()
@@ -73,7 +76,8 @@ test("max length read", function()
7376
end)
7477

7578
test("max length write", function()
76-
with_output("", function(stream)
79+
local output = with_output(function(stream)
7780
assert(netstring.write(stream, "hello world!", 5) == nil)
7881
end)
82+
assert(output == "")
7983
end)

0 commit comments

Comments
 (0)