Skip to content

tests/lapi: add io tests #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

tests/lapi: add io tests #140

wants to merge 1 commit into from

Conversation

ligurio
Copy link
Owner

@ligurio ligurio commented Jul 3, 2025

The functions below are not covered:

  • io.close()
  • io.flush()
  • io.input()
  • io.open()
  • io.output()
  • io.tmpfile()
  • io.type()
  • io.write()
  • file:close()
  • file:flush()
  • file:lines()
  • file:read()
  • file:seek()
  • file:setvbuf()
  • file:write()

Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Sergey!
Thanks for the patch!
Please consider my comments below.

local function TestOneInput(buf)
local fdp = luzer.FuzzedDataProvider(buf)
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
local lua_chunk = ("io.write([[%s]])"):format(str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If str contains ]] this string becomes invalid.

local function TestOneInput(buf)
local fdp = luzer.FuzzedDataProvider(buf)
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
local lua_chunk = ("io.write([[%s]])"):format(str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If str contains ]] this string becomes invalid.

local cur_pos = fh:seek()
fh:seek("end")
fh:seek("set", cur_pos)
fh:read(mode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got the following return values for this read.

nil     Bad file descriptor     9


local READ_MODE = { "*n", "*a", "*l" }

local function TestOneInput(buf)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the idea of the following test, please add the comment.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is the following create IO object and make random operations with it (read, write, seek)

local function TestOneInput(buf)
local fdp = luzer.FuzzedDataProvider(buf)
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
local lua_cmd = ("%s -e '%s'"):format(test_lib.luabin(arg), str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected behaviour if returned string str == "abc".

local fdp = luzer.FuzzedDataProvider(buf)
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
local lua_cmd = ("%s -e '%s'"):format(test_lib.luabin(arg), str)
local fh = io.popen(lua_cmd, "w")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use "w" mode if we read data from that program?

@Buristan Buristan assigned ligurio and unassigned Buristan Jul 17, 2025
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-io branch from 51b71db to b000c92 Compare July 22, 2025 14:45
The functions below are not covered:
`io.close()`, `io.flush()`, `io.input()`, `io.open()`,
`io.output()`, `io.tmpfile()`, `io.type()`, `io.write()`,
`file:close()`, `file:flush()`, `file:lines()`, `file:read()`,
`file:seek()`, `file:setvbuf()`, `file:write()`.
@ligurio ligurio force-pushed the ligurio/gh-xxxx-lapi-io branch from b000c92 to eb56c5e Compare July 28, 2025 13:26
@ligurio ligurio marked this pull request as draft July 30, 2025 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants