Skip to content

Commit fc0cec9

Browse files
authored
Merge pull request #73 from OpenVicProject/seperate/build-and-run-tests
Separate test build and test run
2 parents 4f05dc7 + 2d8ba8c commit fc0cec9

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

SConstruct

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ env.PrependENVPath("PATH", os.getenv("PATH"))
1010

1111
opts = env.SetupOptions()
1212

13-
opts.Add(BoolVariable("run_ovdl_tests", "Build and run the openvic dataloader tests", env.is_standalone))
13+
opts.Add(BoolVariable("build_ovdl_tests", "Build and run the openvic dataloader tests", env.is_standalone))
14+
opts.Add(BoolVariable("run_ovdl_tests", "Run the openvic dataloader tests", False))
1415
opts.Add(
1516
BoolVariable(
1617
"build_ovdl_library",
@@ -68,6 +69,9 @@ library_name = "libopenvic-dataloader{}{}".format(suffix, env["LIBSUFFIX"])
6869
default_args = []
6970

7071
if env["run_ovdl_tests"]:
72+
env["build_ovdl_tests"] = True
73+
74+
if env["build_ovdl_tests"]:
7175
env["build_ovdl_library"] = True
7276

7377
if env["build_ovdl_library"]:
@@ -100,8 +104,11 @@ if env["build_ovdl_headless"]:
100104
)
101105
default_args += [headless_program]
102106

103-
if env["run_ovdl_tests"]:
104-
SConscript("tests/SCsub", "env")
107+
if env["build_ovdl_tests"]:
108+
tests_env = SConscript("tests/SCsub", "env")
109+
110+
if env["run_ovdl_tests"]:
111+
tests_env.RunUnitTest()
105112

106113
# Add compiledb if the option is set
107114
if env.get("compiledb", False):

tests/SCsub

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ def UnitTestPostAction(target=None, source=None, env=None):
1010
return subprocess.run([target[0].path]).returncode
1111

1212

13-
def UnitTest(env, **kwargs):
13+
def BuildUnitTest(env, **kwargs):
1414
test = env.Program(**kwargs)
15-
unit_test_action = env.Action(UnitTestPostAction, None)
16-
test_post_action = env.AddPostAction(test, unit_test_action)
1715
env.NoCache(test)
18-
env.AlwaysBuild(test_post_action)
1916
return test
2017

2118

22-
SConsEnvironment.UnitTest = UnitTest
19+
def RunUnitTest(env):
20+
unit_test_action = env.Action(UnitTestPostAction, None)
21+
test_post_action = env.AddPostAction(env.unit_test, unit_test_action)
22+
env.AlwaysBuild(test_post_action)
23+
24+
25+
SConsEnvironment.BuildUnitTest = BuildUnitTest
26+
SConsEnvironment.RunUnitTest = RunUnitTest
2327

2428
Import("env")
2529

@@ -51,7 +55,9 @@ SConscript("deps/SCsub", {"env": tests_env})
5155
if env["ubuntu_gcc_invalid_char_hang_bug"]:
5256
tests_env.Append(CPPDEFINES=["_OVDL_TEST_UBUNTU_GCC_12_BUG_"])
5357

54-
tests_program = tests_env.UnitTest(
58+
tests_env.unit_test = tests_env.BuildUnitTest(
5559
source=tests_env.tests_sources, target=os.path.join(BINDIR, tests_name), PROGSUFFIX=".tests" + env["PROGSUFFIX"]
5660
)
57-
Default(tests_program)
61+
Default(tests_env.unit_test)
62+
63+
Return("tests_env")

0 commit comments

Comments
 (0)