Skip to content

Commit ba5c59f

Browse files
committed
tests/lapi: os tests
The patch adds tests for the functions in os library except the following functions: `os.tmpname`, `os.rename`, `os.remove`, `os.execute`, `os.clock`.
1 parent bfac9d7 commit ba5c59f

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

tests/lapi/os_date_test.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--[=[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
LuaJIT 2.1 VM out of memory for `os.date`,
9+
https://github.com/LuaJIT/LuaJIT/issues/463
10+
11+
Checking a format for os.date may read pass the format string,
12+
https://www.lua.org/bugs.html#5.3.3-2
13+
14+
os.date throws an error when result is the empty string,
15+
https://www.lua.org/bugs.html#5.1.1-4
16+
17+
Synopsis: os.date([format [, time]])
18+
]]=]
19+
20+
local luzer = require("luzer")
21+
local test_lib = require("lib")
22+
23+
local function TestOneInput(buf)
24+
local fdp = luzer.FuzzedDataProvider(buf)
25+
os.setlocale(test_lib.random_locale(fdp), "all")
26+
local format = fdp:consume_string(test_lib.MAX_STR_LEN)
27+
local time = fdp:consume_number(test_lib.MIN_INT, test_lib.MAX_INT)
28+
os.date(format, time)
29+
end
30+
31+
local args = {
32+
artifact_prefix = "os_date_",
33+
}
34+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_difftime_test.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.difftime(t2, t1)
9+
]]
10+
11+
local luzer = require("luzer")
12+
local test_lib = require("lib")
13+
local MIN_INT = test_lib.MIN_INT64
14+
local MAX_INT = test_lib.MAX_INT64
15+
16+
local function TestOneInput(buf)
17+
local fdp = luzer.FuzzedDataProvider(buf)
18+
local t1 = fdp:consume_number(MIN_INT, MAX_INT)
19+
local t2 = fdp:consume_number(MIN_INT, MAX_INT)
20+
local res = os.difftime(t1, t2)
21+
assert(type(res) == "number")
22+
end
23+
24+
local args = {
25+
artifact_prefix = "os_difftime_",
26+
}
27+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_getenv_test.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.getenv(varname)
9+
]]
10+
11+
12+
local luzer = require("luzer")
13+
14+
local function TestOneInput(buf)
15+
os.getenv(buf)
16+
end
17+
18+
local args = {
19+
artifact_prefix = "os_getenv_",
20+
}
21+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_setlocale_test.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.setlocale(locale [, category])
9+
]]
10+
11+
local luzer = require("luzer")
12+
13+
local function TestOneInput(buf)
14+
os.setlocale(buf)
15+
end
16+
17+
local args = {
18+
artifact_prefix = "os_setlocale_",
19+
}
20+
luzer.Fuzz(TestOneInput, nil, args)

tests/lapi/os_time_test.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--[[
2+
SPDX-License-Identifier: ISC
3+
Copyright (c) 2023-2025, Sergey Bronnikov.
4+
5+
6.9 – Operating System Facilities
6+
https://www.lua.org/manual/5.3/manual.html#6.9
7+
8+
Synopsis: os.time([table])
9+
]]
10+
11+
local luzer = require("luzer")
12+
local test_lib = require("lib")
13+
local MAX_INT64 = test_lib.MAX_INT64
14+
15+
local function TestOneInput(buf)
16+
local fdp = luzer.FuzzedDataProvider(buf)
17+
os.setlocale(test_lib.random_locale(fdp), "all")
18+
local time = {
19+
isdst = fdp:consume_boolean(),
20+
sec = fdp:consume_number(0, MAX_INT64),
21+
min = fdp:consume_number(0, MAX_INT64),
22+
hour = fdp:consume_number(0, MAX_INT64),
23+
day = fdp:consume_number(0, MAX_INT64),
24+
month = fdp:consume_number(0, MAX_INT64),
25+
year = fdp:consume_number(0, MAX_INT64),
26+
}
27+
os.time(time)
28+
end
29+
30+
local args = {
31+
artifact_prefix = "os_time_",
32+
}
33+
luzer.Fuzz(TestOneInput, nil, args)

0 commit comments

Comments
 (0)