aboutsummaryrefslogtreecommitdiff
path: root/tests/SCsub
blob: 0a187771adb4312e2a6f99e4ea6faa9cafa9d85e (plain) (blame)
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
#!/usr/bin/env python
import os
import subprocess
import platform
import sys

import SCons
from SCons.Script.SConscript import SConsEnvironment


def UnitTestPostAction(target=None, source=None, env=None):
    print()
    return subprocess.run([target[0].path]).returncode

def UnitTest(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

Import("env")

BINDIR = "bin"

env.openvic_dataloader_tests = {}

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# tweak this if you want to use different folders, or more folders, to store your source code in.
source_path = "src"

tests_name = "openvic-dataloader"
tests_env = env.Clone()
tests_env.Append(CPPDEFINES=["OPENVIC_DATALOADER_TESTS"])
tests_env.Append(CPPPATH=[tests_env.Dir(source_path)])
tests_env.tests_sources = env.GlobRecursive("*.cpp", [source_path])

SConscript("deps/SCsub", {"env": tests_env })

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