Skip to content

Commit f654cf2

Browse files
committed
Introduce a _BASE_DIR to fix _SCRIPT_DIR inconsistent usage in test suite.
1 parent 2435407 commit f654cf2

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

modules/self-test/test_runner.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@
8989
local hooks = _.installTestingHooks()
9090

9191
_TESTS_DIR = test.suite._TESTS_DIR
92+
_SCRIPT_DIR = test.suite._SCRIPT_DIR
93+
9294
-- Currently the test suite paths are tested against as if all tests are
93-
-- running with the repository root as their working directory.
94-
_SCRIPT_DIR = _MAIN_SCRIPT_DIR
95+
-- running with the repository root as their base working directory.
96+
_BASE_DIR = _MAIN_SCRIPT_DIR
9597

9698
m.suiteName = test.suiteName
9799
m.testName = test.testName

src/base/api.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
-- if I have an existing instance, create a new configuration
149149
-- block for it so I don't pick up an old filter
150150
if instance then
151-
configset.addFilter(instance, {}, _SCRIPT_DIR)
151+
configset.addFilter(instance, {}, api.scope.current.basedir)
152152
end
153153

154154
-- otherwise, a new instance
@@ -716,7 +716,7 @@
716716
table.remove(api.scope.global.blocks, i)
717717
end
718718

719-
configset.addFilter(api.scope.current, {}, _SCRIPT_DIR)
719+
configset.addFilter(api.scope.current, {}, api.scope.current.basedir)
720720
end
721721

722722

@@ -1087,7 +1087,7 @@
10871087
premake.field.kind("path", {
10881088
paths = true,
10891089
store = function(field, current, value, processor)
1090-
return path.deferredjoin(_SCRIPT_DIR, value)
1090+
return path.deferredjoin(api.scope.current.basedir, value)
10911091
end,
10921092
compare = function(field, a, b, processor)
10931093
return (a == b)
@@ -1152,7 +1152,7 @@
11521152
if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or (terms == "*") then
11531153
terms = nil
11541154
end
1155-
local ok, err = configset.addFilter(api.scope.current, {terms}, _SCRIPT_DIR)
1155+
local ok, err = configset.addFilter(api.scope.current, {terms}, api.scope.current.basedir)
11561156
if not ok then
11571157
error(err, 2)
11581158
end

src/base/container.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
self.name = name
7979
self.filename = name
8080
self.script = _SCRIPT
81-
self.basedir = _SCRIPT_DIR
81+
self.scriptdir = _SCRIPT_DIR
82+
self.basedir = _BASE_DIR or _SCRIPT_DIR
8283
self.external = false
8384

8485
for childClass in container.eachChildClass(class) do

tests/api/test_path_kind.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434

3535
function suite.convertsToAbsolute()
3636
testapi "self/local.h"
37-
test.isequal(_SCRIPT_DIR .. "/self/local.h", api.scope.project.testapi)
37+
test.isequal(_BASE_DIR .. "/self/local.h", api.scope.project.testapi)
3838
end

tests/config/test_linkinfo.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
function suite.directoryIsTargetDir_onTargetDir()
3636
targetdir "../bin"
3737
i = prepare()
38-
test.isequal("../bin", path.getrelative(_SCRIPT_DIR, i.directory))
38+
test.isequal("../bin", path.getrelative(_BASE_DIR, i.directory))
3939
end
4040

4141

@@ -48,7 +48,7 @@
4848
targetdir "../bin"
4949
implibdir "../lib"
5050
i = prepare()
51-
test.isequal("../lib", path.getrelative(_SCRIPT_DIR, i.directory))
51+
test.isequal("../lib", path.getrelative(_BASE_DIR, i.directory))
5252
end
5353

5454

tests/test_lua.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
--
1212

1313
function suite.loadfile()
14-
local file = path.join(_TESTS_DIR, "test_lua_loaded_noenv.lua")
14+
local file = path.join(_SCRIPT_DIR, "test_lua_loaded_noenv.lua")
1515
local fn = assert(loadfile(file, nil))
1616
local ret, value = pcall(fn)
1717
test.isequal(10, value)
@@ -25,7 +25,7 @@ end
2525
--
2626

2727
function suite.loadfile_with_env()
28-
local file = path.join(_TESTS_DIR, "test_lua_loaded.lua")
28+
local file = path.join(_SCRIPT_DIR, "test_lua_loaded.lua")
2929
local value = 0
3030
local env = {
3131
["foobar"] = function(n) value = n end

0 commit comments

Comments
 (0)