Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 5, 2024
1 parent 1387b93 commit 822291d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if not lt.options.list then
print("DEBUG: ", platform.DEBUG)
end

--require 'test_lua'
--require "test_lua"
require "test_serialization"
require "test_filesystem"
require "test_thread"
Expand Down
16 changes: 8 additions & 8 deletions test/test_filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ function test_fs:test_relative()
relative(C.."a/b/c", C.."a", "b/c")
relative(C.."a/d/e", C.."a/b/c", "../../d/e")
if isWindows then
--relative(D..'a/b/c', C..'a', '')
--relative(D.."a/b/c", C.."a", "")
relative("a", C.."a/b/c", "")
relative(C.."a/b", "a/b/c", "")
relative(C.."a\\b\\c", C.."a", "b/c")
else
-- TODO
--relative(D..'a/b/c', C..'a', '')
--relative('a', C..'a/b/c', '')
--relative(C..'a/b', 'a/b/c', '')
--relative(D.."a/b/c", C.."a", "")
--relative("a", C.."a/b/c", "")
--relative(C.."a/b", "a/b/c", "")
end
end

Expand Down Expand Up @@ -760,7 +760,7 @@ end
-- while arg[i] ~= nil do
-- i = i - 1
-- end
-- return fs.path(arg[i + 1]):parent_path() / ('bee.' .. __EXT__)
-- return fs.path(arg[i + 1]):parent_path() / ("bee." .. __EXT__)
-- end
-- assertPathEquals(fs.dll_path(), fs.absolute(getdll()))
--end
Expand All @@ -778,11 +778,11 @@ if platform.os ~= "emscripten" then

function test_fs:test_filelock_2()
local process = shell:runlua([[
local fs = require 'bee.filesystem'
local fs = require "bee.filesystem"
fs.filelock(fs.path("temp.lock"))
io.stdout:write 'ok'
io.stdout:write "ok"
io.stdout:flush()
io.read 'a'
io.read "a"
]], { stdin = true, stdout = true, stderr = true })
lt.assertEquals(process.stdout:read(2), "ok")
lt.assertEquals(fs.filelock(fs.path("temp.lock")), nil)
Expand Down
4 changes: 2 additions & 2 deletions test/test_socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ local function createEchoThread(name, ...)
return thread.thread(([[
-- %s
local protocol, address, port = ...
local socket = require 'bee.socket'
local socket = require "bee.socket"
local select = require "bee.select"
local function simple_select(fd, mode)
local s <close> = select.create()
Expand All @@ -238,7 +238,7 @@ local function createEchoThread(name, ...)
client:connect(address, port)
simple_select(client, "w")
assert(client:status())
local queue = ''
local queue = ""
while true do
local event = simple_select(client, "rw")
if event & select.SELECT_READ then
Expand Down
40 changes: 20 additions & 20 deletions test/test_subprocess.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function test_subprocess:test_wait()
end

function test_subprocess:test_is_running()
local process = shell:runlua('io.read "a"', { stdin = true })
local process = shell:runlua([[io.read "a"]], { stdin = true })
lt.assertEquals(process:is_running(), true)
lt.assertIsUserdata(process.stdin)
process.stdin:close()
Expand All @@ -86,7 +86,7 @@ function test_subprocess:test_is_running()
end

function test_subprocess:test_is_running_2()
local process = shell:runlua('io.read "a";os.exit(13)', { stdin = true })
local process = shell:runlua([[io.read "a";os.exit(13)]], { stdin = true })
lt.assertEquals(process:is_running(), true)
lt.assertIsUserdata(process.stdin)
process.stdin:close()
Expand All @@ -98,14 +98,14 @@ function test_subprocess:test_is_running_2()
end

function test_subprocess:test_kill()
local process = shell:runlua('io.read "a"', { stdin = true })
local process = shell:runlua([[io.read "a"]], { stdin = true })
lt.assertEquals(process:is_running(), true)
lt.assertEquals(process:kill(), true)
lt.assertEquals(process:wait(), 0x0F00)
lt.assertEquals(process:is_running(), false)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('io.read "a"', { stdin = true })
local process = shell:runlua([[io.read "a"]], { stdin = true })
lt.assertEquals(process:is_running(), true)
lt.assertEquals(process:kill(0), true)
lt.assertEquals(process:is_running(), true)
Expand All @@ -118,21 +118,21 @@ function test_subprocess:test_kill()
end

function test_subprocess:test_stdio_1()
local process = shell:runlua('io.stdout:write("ok")', { stdout = true })
local process = shell:runlua([[io.stdout:write("ok")]], { stdout = true })
lt.assertEquals(process:wait(), 0)
lt.assertIsUserdata(process.stdout)
lt.assertEquals(process.stdout:read(2), "ok")
lt.assertEquals(process.stdout:read(2), nil)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('io.stderr:write("ok")', { stderr = true })
local process = shell:runlua([[io.stderr:write("ok")]], { stderr = true })
lt.assertEquals(process:wait(), 0)
lt.assertIsUserdata(process.stderr)
lt.assertEquals(process.stderr:read(2), "ok")
lt.assertEquals(process.stderr:read(2), nil)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('io.write(io.read "a")', { stdin = true, stdout = true, stderr = true })
local process = shell:runlua([[io.write(io.read "a")]], { stdin = true, stdout = true, stderr = true })
lt.assertIsUserdata(process.stdin)
lt.assertIsUserdata(process.stdout)
lt.assertIsUserdata(process.stderr)
Expand All @@ -144,7 +144,7 @@ function test_subprocess:test_stdio_1()
lt.assertEquals(process.stdout:read(2), nil)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('error "Test subprocess error."', { stderr = true })
local process = shell:runlua([[error "Test subprocess error."]], { stderr = true })
lt.assertEquals(process:wait(), 1)
local found = not not string.find(process.stderr:read "a", "Test subprocess error.", nil, true)
lt.assertEquals(found, true)
Expand All @@ -155,7 +155,7 @@ function test_subprocess:test_stdio_2()
fs.remove "temp.txt"
local f = lt.assertIsUserdata(io.open("temp.txt", "w"))
---@cast f file*
local process = shell:runlua('io.write "ok"', { stdout = f })
local process = shell:runlua([[io.write "ok"]], { stdout = f })
lt.assertEquals(process.stdout, f)
f:close()
safe_exit(process)
Expand All @@ -171,16 +171,16 @@ function test_subprocess:test_stdio_2()
lt.assertIsUserdata(rd)
---@cast wr file*
---@cast rd file*
local process = shell:runlua('io.write "ok"', { stdout = wr })
local process = shell:runlua([[io.write "ok"]], { stdout = wr })
wr:close()
lt.assertEquals(process.stdout, wr)
safe_exit(process)
lt.assertEquals(rd:read "a", "ok")
rd:close()
fs.remove "temp.txt"

local process1 = shell:runlua('io.write "ok"', { stdout = true })
local process2 = shell:runlua('io.write(io.read "a")', { stdin = process1.stdout, stdout = true })
local process1 = shell:runlua([[io.write "ok"]], { stdout = true })
local process2 = shell:runlua([[io.write(io.read "a")]], { stdin = process1.stdout, stdout = true })
safe_exit(process1)
lt.assertEquals(process2:wait(), 0)
lt.assertEquals(process2.stdout:read "a", "ok")
Expand Down Expand Up @@ -230,7 +230,7 @@ function test_subprocess:test_stdio_4()
end

function test_subprocess:test_peek()
local process = shell:runlua('io.write "ok"', { stdout = true })
local process = shell:runlua([[io.write "ok"]], { stdout = true })
lt.assertEquals(process:wait(), 0)
lt.assertIsUserdata(process.stdout)
lt.assertEquals(subprocess.peek(process.stdout), 2)
Expand All @@ -239,7 +239,7 @@ function test_subprocess:test_peek()
lt.assertEquals(subprocess.peek(process.stdout), nil)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('io.write "ok"', { stdout = true })
local process = shell:runlua([[io.write "ok"]], { stdout = true })
lt.assertEquals(process:wait(), 0)
lt.assertIsUserdata(process.stdout)
lt.assertEquals(subprocess.peek(process.stdout), 2)
Expand All @@ -248,7 +248,7 @@ function test_subprocess:test_peek()
lt.assertEquals(subprocess.peek(process.stdout), nil)
lt.assertEquals(process:detach(), true)

local process = shell:runlua('io.stdout:setvbuf "no" io.write "start" io.write(io.read "a")', { stdin = true, stdout = true })
local process = shell:runlua([[io.stdout:setvbuf "no" io.write "start" io.write(io.read "a")]], { stdin = true, stdout = true })
lt.assertIsUserdata(process.stdin)
lt.assertIsUserdata(process.stdout)
lt.assertEquals(process:is_running(), true)
Expand Down Expand Up @@ -280,7 +280,7 @@ if platform.os == "windows" then
lt.assertEquals(process:detach(), true)
local process = shell:runlua([[
local windows = require "bee.windows"
windows.filemode(io.stdin, 'b')
windows.filemode(io.stdin, "b")
assert(io.read "a" == "\r\n")
]], { stdin = true, stderr = true })
process.stdin:write "\r\n"
Expand All @@ -300,13 +300,13 @@ function test_subprocess:test_env()
)
safe_exit(process)
end
test_env('os.getenv "BEE_TEST" == nil', {})
test_env('os.getenv "BEE_TEST" == "ok"', { BEE_TEST = "ok" })
test_env([[os.getenv "BEE_TEST" == nil]], {})
test_env([[os.getenv "BEE_TEST" == "ok"]], { BEE_TEST = "ok" })

subprocess.setenv("BEE_TEST_ENV_1", "OK")
lt.assertEquals(os.getenv "BEE_TEST_ENV_1", "OK")
test_env('os.getenv "BEE_TEST_ENV_1" == "OK"', {})
test_env('os.getenv "BEE_TEST_ENV_1" == nil', { BEE_TEST_ENV_1 = false })
test_env([[os.getenv "BEE_TEST_ENV_1" == "OK"]], {})
test_env([[os.getenv "BEE_TEST_ENV_1" == nil]], { BEE_TEST_ENV_1 = false })
end

function test_subprocess:test_args()
Expand Down
18 changes: 9 additions & 9 deletions test/test_thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function test_thread:test_thread_1()
fs.remove("temp.txt")
lt.assertEquals(file_exists("temp.txt"), false)
local thd = createThread [[
io.open('temp.txt', 'w'):close()
io.open("temp.txt", "w"):close()
]]
thread.wait(thd)
lt.assertEquals(file_exists("temp.txt"), true)
Expand Down Expand Up @@ -62,7 +62,7 @@ end
function test_thread:test_thread_3()
assertNotThreadError()
local thd = createThread [[
error 'Test thread error.'
error "Test thread error."
]]
thread.wait(thd)
assertHasThreadError("Test thread error.")
Expand Down Expand Up @@ -221,10 +221,10 @@ function test_thread:test_thread_bpop()
thread.newchannel "testRes"
local thd = createThread [[
local thread = require "bee.thread"
local req = thread.channel 'testReq'
local res = thread.channel 'testRes'
local req = thread.channel "testReq"
local res = thread.channel "testRes"
local function dispatch(what, ...)
if what == 'exit' then
if what == "exit" then
return true
end
res:push(what, ...)
Expand All @@ -251,14 +251,14 @@ function test_thread:test_thread_pop()
thread.newchannel "testRes"
local thd = createThread [[
local thread = require "bee.thread"
local req = thread.channel 'testReq'
local res = thread.channel 'testRes'
local req = thread.channel "testReq"
local res = thread.channel "testRes"
local function dispatch(ok, what, ...)
if not ok then
thread.sleep(0)
return
end
if what == 'exit' then
if what == "exit" then
return true
end
res:push(what, ...)
Expand Down Expand Up @@ -297,7 +297,7 @@ function test_thread:test_rpc()
thread.newchannel "test"
local thd = createThread [[
local thread = require "bee.thread"
local c = thread.channel 'test'
local c = thread.channel "test"
local quit
local cmd = {}
function cmd.add(a, b)
Expand Down

0 comments on commit 822291d

Please sign in to comment.