Skip to content

Commit deb241b

Browse files
committed
Fix io.popen() with mode parameter
1 parent 38daac9 commit deb241b

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/io.nelua

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function io.popen(prog: string, mode: facultative(string)) : (filestream, string
9797
## if mode.type.is_niltype then
9898
local mode: string = "r"
9999
## else
100-
assert(m.size == 1 and (m.data[0] == 'r' or m.data[0] == 'w') and m.data[1] == '\0', 'invalid mode')
100+
assert(mode.size == 1 and (mode.data[0] == 'r'_b or mode.data[0] == 'w'_b) and mode.data[1] == 0, 'invalid mode')
101101
## end
102102
## if ccinfo.is_wasm then
103103
return filestream{}, 'unsupported', -1

tests/io_test.nelua

+25-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,31 @@ do -- basic io.open/io.isopen/io.close
4242
end
4343

4444
do -- io.popen
45-
local file = io.popen('echo test')
46-
## if ccinfo.is_linux then
47-
assert(file:isopen())
48-
## end
49-
if file:isopen() then
50-
local s = file:read('a')
51-
assert(s == 'test\n')
52-
s:destroy()
53-
file:close()
54-
file:destroy()
45+
do
46+
local file = io.popen('echo test')
47+
## if ccinfo.is_linux then
48+
assert(file:isopen())
49+
## end
50+
if file:isopen() then
51+
local s = file:read('a')
52+
assert(s == 'test\n')
53+
s:destroy()
54+
file:close()
55+
file:destroy()
56+
end
57+
end
58+
do
59+
local file = io.popen('echo test', 'r')
60+
## if ccinfo.is_linux then
61+
assert(file:isopen())
62+
## end
63+
if file:isopen() then
64+
local s = file:read('a')
65+
assert(s == 'test\n')
66+
s:destroy()
67+
file:close()
68+
file:destroy()
69+
end
5570
end
5671
end
5772

0 commit comments

Comments
 (0)