Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ env.PrependENVPath("PATH", os.getenv("PATH"))

opts = env.SetupOptions()

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

if env["run_ovdl_tests"]:
env["build_ovdl_tests"] = True

if env["build_ovdl_tests"]:
env["build_ovdl_library"] = True

if env["build_ovdl_library"]:
Expand Down Expand Up @@ -100,8 +104,11 @@ if env["build_ovdl_headless"]:
)
default_args += [headless_program]

if env["run_ovdl_tests"]:
SConscript("tests/SCsub", "env")
if env["build_ovdl_tests"]:
tests_env = SConscript("tests/SCsub", "env")

if env["run_ovdl_tests"]:
tests_env.RunUnitTest()

# Add compiledb if the option is set
if env.get("compiledb", False):
Expand Down
20 changes: 13 additions & 7 deletions tests/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ def UnitTestPostAction(target=None, source=None, env=None):
return subprocess.run([target[0].path]).returncode


def UnitTest(env, **kwargs):
def BuildUnitTest(env, **kwargs):
test = env.Program(**kwargs)
unit_test_action = env.Action(UnitTestPostAction, None)
test_post_action = env.AddPostAction(test, unit_test_action)
env.NoCache(test)
env.AlwaysBuild(test_post_action)
return test


SConsEnvironment.UnitTest = UnitTest
def RunUnitTest(env):
unit_test_action = env.Action(UnitTestPostAction, None)
test_post_action = env.AddPostAction(env.unit_test, unit_test_action)
env.AlwaysBuild(test_post_action)


SConsEnvironment.BuildUnitTest = BuildUnitTest
SConsEnvironment.RunUnitTest = RunUnitTest

Import("env")

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

tests_program = tests_env.UnitTest(
tests_env.unit_test = tests_env.BuildUnitTest(
source=tests_env.tests_sources, target=os.path.join(BINDIR, tests_name), PROGSUFFIX=".tests" + env["PROGSUFFIX"]
)
Default(tests_program)
Default(tests_env.unit_test)

Return("tests_env")