Skip to content

Commit

Permalink
Fix io.popen() with mode parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Oct 18, 2024
1 parent 38daac9 commit deb241b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/io.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function io.popen(prog: string, mode: facultative(string)) : (filestream, string
## if mode.type.is_niltype then
local mode: string = "r"
## else
assert(m.size == 1 and (m.data[0] == 'r' or m.data[0] == 'w') and m.data[1] == '\0', 'invalid mode')
assert(mode.size == 1 and (mode.data[0] == 'r'_b or mode.data[0] == 'w'_b) and mode.data[1] == 0, 'invalid mode')
## end
## if ccinfo.is_wasm then
return filestream{}, 'unsupported', -1
Expand Down
35 changes: 25 additions & 10 deletions tests/io_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ do -- basic io.open/io.isopen/io.close
end

do -- io.popen
local file = io.popen('echo test')
## if ccinfo.is_linux then
assert(file:isopen())
## end
if file:isopen() then
local s = file:read('a')
assert(s == 'test\n')
s:destroy()
file:close()
file:destroy()
do
local file = io.popen('echo test')
## if ccinfo.is_linux then
assert(file:isopen())
## end
if file:isopen() then
local s = file:read('a')
assert(s == 'test\n')
s:destroy()
file:close()
file:destroy()
end
end
do
local file = io.popen('echo test', 'r')
## if ccinfo.is_linux then
assert(file:isopen())
## end
if file:isopen() then
local s = file:read('a')
assert(s == 'test\n')
s:destroy()
file:close()
file:destroy()
end
end
end

Expand Down

0 comments on commit deb241b

Please sign in to comment.