@@ -18,13 +18,14 @@ local function with_input(input_data, test_func)
18
18
input_file :close ()
19
19
end
20
20
21
- local function with_output (expected_output , test_func )
21
+ local function with_output (test_func )
22
22
local output_file = io.tmpfile ()
23
23
test_func (output_file )
24
24
output_file :flush ()
25
25
output_file :seek " set"
26
- assert ( output_file :read " *a" == expected_output )
26
+ output = output_file :read " *a"
27
27
output_file :close ()
28
+ return output
28
29
end
29
30
30
31
test (" read sanity" , function ()
@@ -34,9 +35,10 @@ test("read sanity", function()
34
35
end )
35
36
36
37
test (" write sanity" , function ()
37
- with_output ( " 12:hello world!, " , function (stream )
38
+ local output = with_output ( function (stream )
38
39
netstring .write (stream , " hello world!" )
39
40
end )
41
+ assert (output == " 12:hello world!," )
40
42
end )
41
43
42
44
test (" read empty" , function ()
@@ -53,10 +55,11 @@ test("multiple reads", function()
53
55
end )
54
56
55
57
test (" multiple writes" , function ()
56
- with_output (" 5:hello,5:world, " , function (stream )
58
+ local output = with_output (function (stream )
57
59
netstring .write (stream , " hello" )
58
60
netstring .write (stream , " world" )
59
61
end )
62
+ assert (output == " 5:hello,5:world," )
60
63
end )
61
64
62
65
test (" half read" , function ()
@@ -73,7 +76,8 @@ test("max length read", function()
73
76
end )
74
77
75
78
test (" max length write" , function ()
76
- with_output (" " , function (stream )
79
+ local output = with_output (function (stream )
77
80
assert (netstring .write (stream , " hello world!" , 5 ) == nil )
78
81
end )
82
+ assert (output == " " )
79
83
end )
0 commit comments