Skip to content

Commit 240a878

Browse files
committed
[UT] Add unit tests for os.findlib/os.findheader
1 parent 0cd4e34 commit 240a878

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

tests/base/test_os.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@
1717
os.chdir(cwd)
1818
end
1919

20+
local function create_mock_os_getenv(map)
21+
return function (key) return map[key] end
22+
end
23+
24+
local function get_LD_PATH_variable_name()
25+
if os.istarget("windows") then
26+
return 'PATH'
27+
elseif os.istarget("haiku") then
28+
return 'LIBRARY_PATH'
29+
elseif os.istarget("darwin") then
30+
return 'DYLD_LIBRARY_PATH'
31+
else
32+
return 'LD_LIBRARY_PATH'
33+
end
34+
end
35+
36+
local function get_surrounded_env_path(dir)
37+
if os.istarget("windows") then
38+
return "c:\\anyPath;" .. path.getabsolute(dir) .. ";c:\\otherpath"
39+
else
40+
return "/any_path:" .. path.getabsolute(dir) .. ":/other_path"
41+
end
42+
end
2043

2144
--
2245
-- os.findlib() tests
@@ -50,6 +73,20 @@
5073
test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere"))
5174
end
5275

76+
function suite.findlib_provided()
77+
test.isequal(path.getabsolute("folder/subfolder/lib"),
78+
os.findlib("test", path.getabsolute("folder/subfolder/lib")))
79+
end
80+
81+
function suite.findlib_frompath()
82+
local os_getenv = os.getenv
83+
os.getenv = create_mock_os_getenv({ [get_LD_PATH_variable_name()] = get_surrounded_env_path("folder/subfolder/lib") })
84+
85+
test.isequal(path.getabsolute("folder/subfolder/lib"), os.findlib("test"))
86+
87+
os.getenv = os_getenv
88+
end
89+
5390
function suite.findheader_stdheaders()
5491
if not os.istarget("windows") and not os.istarget("macosx") then
5592
test.istrue(os.findheader("stdlib.h"))
@@ -60,6 +97,28 @@
6097
test.isfalse(os.findheader("Knights/who/say/Ni.hpp"))
6198
end
6299

100+
function suite.findheader_provided()
101+
test.isequal(path.getabsolute("folder/subfolder/include"),
102+
os.findheader("test.h", path.getabsolute("folder/subfolder/include")))
103+
end
104+
105+
function suite.findheader_frompath_lib()
106+
local os_getenv = os.getenv
107+
os.getenv = create_mock_os_getenv({ [get_LD_PATH_variable_name()] = get_surrounded_env_path("folder/subfolder/lib") })
108+
109+
test.isequal(path.getabsolute("folder/subfolder/include"), os.findheader("test.h"))
110+
111+
os.getenv = os_getenv
112+
end
113+
114+
function suite.findheader_frompath_bin()
115+
local os_getenv = os.getenv
116+
os.getenv = create_mock_os_getenv({ [get_LD_PATH_variable_name()] = get_surrounded_env_path("folder/subfolder/bin") })
117+
118+
test.isequal(path.getabsolute("folder/subfolder/include"), os.findheader("test.h"))
119+
120+
os.getenv = os_getenv
121+
end
63122

64123
--
65124
-- os.isfile() tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Only used for presence in tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only used for presence in tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only used for presence in tests

tests/folder/subfolder/lib/test.so

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only used for presence in tests

0 commit comments

Comments
 (0)