-
-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathtest_include.lua
More file actions
118 lines (95 loc) · 3.35 KB
/
test_include.lua
File metadata and controls
118 lines (95 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--
-- tests/base/test_include.lua
-- Test the include() function, for including external scripts
-- Copyright (c) 2011-2014 Jess Perkins and the Premake project
--
local p = premake
local suite = test.declare("include")
--
-- Setup and teardown
--
function suite.teardown()
-- clear the list of included files after each run
io._includedFiles = { }
end
--
-- Tests
--
function suite.include_findsPremakeFile_onFolderNameOnly()
include (_TESTS_DIR .. "/folder")
test.isequal("ok", p.captured())
end
function suite.include_onExactFilename()
include (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("ok", p.captured())
end
function suite.include_runsOnlyOnce_onMultipleIncludes()
include (_TESTS_DIR .. "/folder/premake5.lua")
include (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("ok", p.captured())
end
function suite.include_runsOnlyOnce_onMultipleIncludesWithDifferentPaths()
include (_TESTS_DIR .. "/folder/premake5.lua")
include (_TESTS_DIR .. "/../tests/folder/premake5.lua")
test.isequal("ok", p.captured())
end
function suite.includeexternal_runs()
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("ok", p.captured())
end
function suite.includeexternal_runsAfterInclude()
include (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("okok", p.captured())
end
function suite.includeexternal_runsTwiceAfterInclude()
include (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
includeexternal (_TESTS_DIR .. "/folder/premake5.lua")
test.isequal("okokok", p.captured())
end
--
-- Tests for local-first search priority (fix for issue #1783):
-- Local files must be found before identically-named files in premake.path.
--
-- Helper: run fn with CWD and premake.path temporarily overridden.
local function withLocalPriority(cwd, searchPath, fn)
local savedPath = premake.path
local savedCwd = os.getcwd()
premake.path = searchPath
os.chdir(cwd)
local ok, err = pcall(fn)
os.chdir(savedCwd)
premake.path = savedPath
if not ok then error(err, 2) end
end
-- A local "name/premake5.lua" must be preferred over a plain file named
-- "name" that lives only in a premake.path search directory.
function suite.findProjectScript_prefersLocalSubdir_overPathDecoy()
local folder = _TESTS_DIR .. "/folder"
withLocalPriority(folder, folder .. "/subfolder", function()
local res, _ = premake.findProjectScript("shadowlib")
test.isequal(
path.normalize(folder .. "/shadowlib/premake5.lua"),
path.normalize(res))
end)
end
-- A local "name.lua" must be preferred over a plain file named "name"
-- (no extension) that lives only in a premake.path search directory.
function suite.findProjectScript_prefersLocalLuaFile_overPathDecoy()
local folder = _TESTS_DIR .. "/folder"
withLocalPriority(folder, folder .. "/subfolder", function()
local res, _ = premake.findProjectScript("ok")
test.isequal(
path.normalize(folder .. "/ok.lua"),
path.normalize(res))
end)
end
-- Verify the full include() call for the subdir-priority scenario.
function suite.include_prefersLocalSubdir_overPathDecoy()
local folder = _TESTS_DIR .. "/folder"
withLocalPriority(folder, folder .. "/subfolder", function()
include("shadowlib")
end)
test.isequal("shadowlocal", p.captured())
end