|
17 | 17 | os.chdir(cwd) |
18 | 18 | end |
19 | 19 |
|
| 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 |
20 | 43 |
|
21 | 44 | -- |
22 | 45 | -- os.findlib() tests |
|
50 | 73 | test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere")) |
51 | 74 | end |
52 | 75 |
|
| 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 | + |
53 | 90 | function suite.findheader_stdheaders() |
54 | 91 | if not os.istarget("windows") and not os.istarget("macosx") then |
55 | 92 | test.istrue(os.findheader("stdlib.h")) |
|
60 | 97 | test.isfalse(os.findheader("Knights/who/say/Ni.hpp")) |
61 | 98 | end |
62 | 99 |
|
| 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 |
63 | 122 |
|
64 | 123 | -- |
65 | 124 | -- os.isfile() tests |
|
0 commit comments