Skip to content

Commit

Permalink
naming convention in tests
Browse files Browse the repository at this point in the history
cryi committed Jan 2, 2025
1 parent d4f3970 commit 655dbc8
Showing 18 changed files with 1,016 additions and 1,005 deletions.
8 changes: 4 additions & 4 deletions lib/eli/fs.lua
Original file line number Diff line number Diff line change
@@ -593,7 +593,7 @@ local ELI_DIR_LOCK_ID = "ELI_DIR_LOCK"
---Locks access to directory
---@param path string
---@param lock_file_name string?
---@return EliDirLock|nil, string?
---@return EliDirLock?, string?
function fs.lock_directory(path, lock_file_name)
check_efs_available"lock_dir"
return fs_extra.lock_dir(path, lock_file_name)
@@ -603,7 +603,7 @@ end
---
---Unlocks access to directory
---@param fs_lock EliDirLock
---@return boolean|nil, string?
---@return EliDirLock?, string?
function fs.unlock_directory(fs_lock)
if type(fs_lock) == ELI_DIR_LOCK_ID or (type(fs_lock) == "userdata" and fs_lock.__type --[[@as string]] == ELI_DIR_LOCK_ID) then
return fs_lock --[[@as EliDirLock]]:unlock()
@@ -617,7 +617,7 @@ end
---
---returns type of file
---@param path string
---@return boolean|nil, string
---@return string
function fs.file_type(path)
local last_character = path:sub(#path, #path)
if table_extensions.includes({ "/", "\\" }, last_character) then
@@ -630,7 +630,7 @@ end
---
---returns type of file
---@param path_or_file string|file*
---@return boolean|nil, string
---@return table
function fs.file_info(path_or_file)
if type(path_or_file) == "string" then
local last_character = path_or_file:sub(#path_or_file, #path_or_file)
6 changes: 3 additions & 3 deletions lib/tests/all.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST = require"u-test"
local _test = TEST
local test = TEST
require"t_hjson"
require"t_bigint"
require"t_base64"
@@ -32,5 +32,5 @@ require"internals.util"
]]
require"elify"

local _ntests, _nfailed = _test.result()
_test.summary()
local ntests, nfailed = test.result()
test.summary()
26 changes: 13 additions & 13 deletions lib/tests/cli.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
local _test = TEST or require "u-test"
local _ok, _eliCli = pcall(require, "eli.cli")
local test = TEST or require"u-test"
local ok, eli_cli = pcall(require, "eli.cli")

if not _ok then
_test["eli.cli available"] = function()
_test.assert(false, "eli.cli not available")
if not ok then
test["eli.cli available"] = function ()
test.assert(false, "eli.cli not available")
end
if not TEST then
_test.summary()
test.summary()
os.exit()
else
return
end
end

_test["eli.cli available"] = function()
_test.assert(true)
test["eli.cli available"] = function ()
test.assert(true)
end

_test["parse args"] = function()
test["parse args"] = function ()
arg = {
[-1] = "",
[0] = "",
[1] = "-q"
[1] = "-q",
}

print(require"hjson".stringify(_eliCli.parse_args()))
_test.assert(true)
print(require"hjson".stringify(eli_cli.parse_args()))
test.assert(true)
end

if not TEST then
_test.summary()
test.summary()
end
26 changes: 13 additions & 13 deletions lib/tests/elify.lua
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@ test["zip"] = function ()
end

test["os"] = function ()
local _eliOs = require"eli.os"
test.assert(os ~= _eliOs)
for k, v in pairs(_eliOs) do
local eli_os = require"eli.os"
test.assert(os ~= eli_os)
for k, v in pairs(eli_os) do
test.assert(os[k] == v)
end
end
@@ -54,29 +54,29 @@ test["etype"] = function ()
test.assert(etype(nil) == "nil")
test.assert(etype(0) == "number")
test.assert(etype{} == "table")
local _t = { __type = "test" }
setmetatable(_t, _t)
test.assert(etype(_t) == "test")
local t = { __type = "test" }
setmetatable(t, t)
test.assert(etype(t) == "test")
end

test["get_overriden_values"] = function ()
local _overriden = require"eli.elify".get_overriden_values()
test.assert(_overriden.os == require"os")
test.assert(_overriden.type ~= type)
local overriden = require"eli.elify".get_overriden_values()
test.assert(overriden.os == require"os")
test.assert(overriden.type ~= type)
end

test["extensions.string"] = function ()
local _esx = require"eli.extensions.string"
for k, v in pairs(_esx) do
local string_extensions = require"eli.extensions.string"
for k, v in pairs(string_extensions) do
if k ~= "globalize" then
test.assert(string[k] == v)
end
end
end

test["extensions.table"] = function ()
local _etx = require"eli.extensions.table"
for k, v in pairs(_etx) do
local table_extensions = require"eli.extensions.table"
for k, v in pairs(table_extensions) do
if k ~= "globalize" then
test.assert(table[k] == v)
end
52 changes: 26 additions & 26 deletions lib/tests/elios.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
local _test = TEST or require"u-test"
local _ok, _elios = pcall(require, "eli.os")
local test = TEST or require"u-test"
local ok, eli_os = pcall(require, "eli.os")

if not _ok then
_test["eli.os available"] = function ()
_test.assert(false, "eli.os not available")
if not ok then
test["eli.os available"] = function ()
test.assert(false, "eli.os not available")
end
if not TEST then
_test.summary()
test.summary()
os.exit()
else
return
end
end

_test["eli.os available"] = function ()
_test.assert(true)
test["eli.os available"] = function ()
test.assert(true)
end

if not _elios.EOS then
if not eli_os.EOS then
if not TEST then
_test.summary()
test.summary()
print"EOS not detected, only basic tests executed..."
os.exit()
else
@@ -28,25 +28,25 @@ if not _elios.EOS then
end
end

_test["sleep"] = function ()
local _referencePoint = os.date"%S"
_elios.sleep(10)
local _afterSleep = os.date"%S"
local _diff = _afterSleep - _referencePoint
if _diff < 0 then _diff = _diff + 60 end
_test.assert(_diff > 6 and _diff < 14)
test["sleep"] = function ()
local reference_point = os.date"%S"
eli_os.sleep(10)
local after_sleep = os.date"%S"
local diff = after_sleep - reference_point
if diff < 0 then diff = diff + 60 end
test.assert(diff > 6 and diff < 14)
end

_test["chdir & cwd"] = function ()
local _cwd = _elios.cwd()
_elios.chdir"tmp"
local _newCwd = _elios.cwd()
_test.assert(_cwd ~= _newCwd)
_elios.chdir(_cwd)
_newCwd = _elios.cwd()
_test.assert(_cwd == _newCwd)
test["chdir & cwd"] = function ()
local cwd = eli_os.cwd()
eli_os.chdir"tmp"
local new_cwd = eli_os.cwd()
test.assert(cwd ~= new_cwd)
eli_os.chdir(cwd)
new_cwd = eli_os.cwd()
test.assert(cwd == new_cwd)
end

if not TEST then
_test.summary()
test.summary()
end
61 changes: 30 additions & 31 deletions lib/tests/env.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@

local _test = TEST or require 'u-test'
local _ok, _eliEnv = pcall(require, "eli.env")
local test = TEST or require"u-test"
local ok, eli_env = pcall(require, "eli.env")

if not _ok then
_test["eli.env available"] = function ()
_test.assert(false, "eli.env not available")
if not ok then
test["eli.env available"] = function ()
test.assert(false, "eli.env not available")
end
if not TEST then
_test.summary()
if not TEST then
test.summary()
os.exit()
else
return
else
return
end
end

_test["eli.env available"] = function ()
_test.assert(true)
test["eli.env available"] = function ()
test.assert(true)
end

_test["get_env"] = function ()
local _path = _eliEnv.get_env("PATH")
_test.assert(type(_path) == 'string')
test["get_env"] = function ()
local path = eli_env.get_env"PATH"
test.assert(type(path) == "string")
end

if not _eliEnv.EENV then
if not TEST then
_test.summary()
if not eli_env.EENV then
if not TEST then
test.summary()
print"EENV not detected, only basic tests executed..."
os.exit()
else
else
print"EENV not detected, only basic tests executed..."
return
return
end
end

_test["set_env"] = function ()
local _ok = _eliEnv.set_env("t", "test_value")
_test.assert(_ok)
local _t = _eliEnv.get_env("t")
_test.assert(_t == 'test_value')
test["set_env"] = function ()
local ok = eli_env.set_env("t", "test_value")
test.assert(ok)
local t = eli_env.get_env"t"
test.assert(t == "test_value")
end

_test["environment"] = function ()
local _env = _eliEnv.environment()
_test.assert(type(_env) == 'table')
test["environment"] = function ()
local env = eli_env.environment()
test.assert(type(env) == "table")
end

if not TEST then
_test.summary()
end
if not TEST then
test.summary()
end
Loading

0 comments on commit 655dbc8

Please sign in to comment.