Skip to content

Commit c9d2c47

Browse files
committed
Use consistent working directory for running the tests.
This changes the test suite to always be run from a consistent working directory, avoiding having per-test workarounds like done on the PCH tests.
1 parent 28ac93d commit c9d2c47

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

modules/gmake/tests/cpp/test_make_pch.lua

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
local wks, prj
1919
function suite.setup()
20-
os.chdir(_TESTS_DIR)
2120
wks, prj = test.createWorkspace()
2221
end
2322

@@ -71,15 +70,32 @@
7170

7271

7372
--
74-
-- The PCH can be specified relative the an includes search path.
73+
-- The PCH can be specified relative to the includes search path.
7574
--
7675

77-
function suite.pch_searchesIncludeDirs()
76+
function suite.pch_searchesIncludeDirs_location()
7877
pchheader "premake.h"
79-
includedirs { "../../../src/host" }
78+
includedirs { "src/host" }
8079
prepareVars()
8180
test.capture [[
82-
PCH = ../../../src/host/premake.h
81+
PCH = src/host/premake.h
82+
]]
83+
end
84+
85+
86+
--
87+
-- The PCH can be specified relative to the includes search path.
88+
-- Due to the location being different from _MAIN_SCRIPT_DIR,
89+
-- the specified PCH path should be relative to the location.
90+
91+
92+
function suite.findsPCH_onIncludeDirs()
93+
location "MyProject"
94+
pchheader "premake.h"
95+
includedirs { "src/host" }
96+
prepareVars()
97+
test.capture [[
98+
PCH = ../src/host/premake.h
8399
]]
84100
end
85101

@@ -123,20 +139,3 @@ $(OBJECTS): | $(OBJDIR)
123139
endif
124140
]]
125141
end
126-
127-
128-
129-
--
130-
-- If the header is located on one of the include file
131-
-- search directories, it should get found automatically.
132-
--
133-
134-
function suite.findsPCH_onIncludeDirs()
135-
location "MyProject"
136-
pchheader "premake.h"
137-
includedirs { "../../../src/host" }
138-
prepareVars()
139-
test.capture [[
140-
PCH = ../../../../src/host/premake.h
141-
]]
142-
end

modules/gmake2/tests/test_gmake2_pch.lua

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
local wks, prj
2222
function suite.setup()
23-
os.chdir(_TESTS_DIR)
2423
gmake2.cpp.initialize()
2524
wks, prj = test.createWorkspace()
2625
end
@@ -95,15 +94,30 @@ GCH = $(PCH_PLACEHOLDER).gch
9594

9695

9796
--
98-
-- The PCH can be specified relative the an includes search path.
97+
-- The PCH can be specified relative to the includes search path.
9998
--
10099

101100
function suite.pch_searchesIncludeDirs()
102101
pchheader "premake.h"
103-
includedirs { "../../../src/host" }
102+
includedirs { "src/host" }
104103
prepareVars()
105104
test.capture [[
106-
PCH = ../../../src/host/premake.h
105+
PCH = src/host/premake.h
106+
]]
107+
end
108+
109+
--
110+
-- The PCH can be specified relative to the includes search path.
111+
-- Due to the location being different from _MAIN_SCRIPT_DIR,
112+
-- the specified PCH path should be relative to the location.
113+
114+
function suite.pch_searchesIncludeDirs_location()
115+
location "MyProject"
116+
pchheader "premake.h"
117+
includedirs { "src/host" }
118+
prepareVars()
119+
test.capture [[
120+
PCH = ../src/host/premake.h
107121
]]
108122
end
109123

@@ -160,23 +174,6 @@ endif
160174
]]
161175
end
162176

163-
164-
165-
--
166-
-- If the header is located on one of the include file
167-
-- search directories, it should get found automatically.
168-
--
169-
170-
function suite.findsPCH_onIncludeDirs()
171-
location "MyProject"
172-
pchheader "premake.h"
173-
includedirs { "../../../src/host" }
174-
prepareVars()
175-
test.capture [[
176-
PCH = ../../../../src/host/premake.h
177-
]]
178-
end
179-
180177
--
181178
-- If the header is located on one of the include file
182179
-- search directories, it should get found automatically.

modules/self-test/test_runner.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484

8585
function _.runTest(test)
8686
_.log(term.lightGreen, "[ RUN ]", string.format(" %s.%s", test.suiteName, test.testName))
87+
88+
-- Provide a consistent working directory to the tests.
89+
os.chdir(_MAIN_SCRIPT_DIR)
90+
8791
local startTime = os.clock()
8892
local cwd = os.getcwd()
8993
local hooks = _.installTestingHooks()
@@ -105,7 +109,6 @@
105109
err = err or terr
106110

107111
_.removeTestingHooks(hooks)
108-
os.chdir(cwd)
109112

110113
if ok then
111114
_.log(term.lightGreen, "[ OK ]", string.format(" %s.%s (%.0f ms)", test.suiteName, test.testName, (os.clock() - startTime) * 1000))

0 commit comments

Comments
 (0)