diff --git a/.gitignore b/.gitignore index 6b5bf870..469f6001 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ share/ocarina/#* bin/ .sconsign.dblite *.patch +tests/*-lib diff --git a/Sconstruct b/Sconstruct index 4bd6c5a8..2ef52ca3 100644 --- a/Sconstruct +++ b/Sconstruct @@ -4,6 +4,7 @@ import os # Configuration variables CONFIG_VERSION = 6.1 CONFIG_DEBUG = True +CONFIG_TEST_VALGRIND = False # Set up default environment @@ -11,28 +12,36 @@ CONFIG_CCFLAGS = [ "-O2" ] if CONFIG_DEBUG == True: CONFIG_CCFLAGS = [ "-Wall", "-Werror", "-g", "-DCONFIG_DEBUG" ] -env = Environment( CCFLAGS = CONFIG_CCFLAGS ) -env.Append(CPPPATH = os.path.abspath("include")) -env.Append(CXXCOMSTR = "C++ $TARGET") -env.Append(LINKCOMSTR = "Linking $TARGET") +class OEnvironment(Environment): + Debug = False + Version = 0 + Valgrind = False + def __init__(self): + Environment.__init__(self, CCFLAGS = CONFIG_CCFLAGS) + self.Append(CPPPATH = os.path.abspath("include")) + self.Append(CXXCOMSTR = "C++ $TARGET") + self.Append(LINKCOMSTR = "Linking $TARGET") + self.Debug = CONFIG_DEBUG + self.Version = CONFIG_VERSION + self.Valgrind = CONFIG_TEST_VALGRIND -def use_package(name): - env.ParseConfig("pkg-config --cflags --libs %s" % name) + def UsePackage(self, name): + self.ParseConfig("pkg-config --cflags --libs %s" % name) -Export("env", "use_package", "CONFIG_DEBUG", "CONFIG_VERSION") +env = OEnvironment() +test_env = OEnvironment() +Export("env", "test_env") include = SConscript("include/Sconscript") - lib = SConscript("lib/Sconscript") -Export("lib") +gui = SConscript("gui/Sconscript") tests = SConscript("tests/Sconscript") -gui = SConscript("gui/Sconscript") -ocarina = env.Program("bin/ocarina", lib + gui) +ocarina = env.Program("bin/ocarina", lib + gui, LIBS="y") Default(ocarina) Clean(ocarina, "bin/") diff --git a/TODO b/TODO index e4e93e66..c0b3ddec 100644 --- a/TODO +++ b/TODO @@ -61,13 +61,7 @@ Future work: the library? Perhaps create a mirror group? - Extra testing ideas: - - Run tests through valgrind to help find memory leaks - - Some way to enable / disable tests during development - - Run tests based on dependencies - - Fix tests that will only work on my computer - Double check that all inputs and outputs are tested - - Simple testing library? - - Stop tests on failure - Test callbacks - Preferences: diff --git a/gui/Sconscript b/gui/Sconscript index 268611ad..abc00633 100644 --- a/gui/Sconscript +++ b/gui/Sconscript @@ -1,7 +1,7 @@ #!/usr/bin/python -Import("use_package") +Import("env") -use_package("gtkmm-3.0") +env.UsePackage("gtkmm-3.0") res = Glob("*.cpp") Return("res") diff --git a/include/Sconscript b/include/Sconscript index 6ea804e1..5a1db8b7 100644 --- a/include/Sconscript +++ b/include/Sconscript @@ -1,8 +1,9 @@ #!/usr/bin/python -Import("env", "CONFIG_DEBUG", "CONFIG_VERSION") +Import("env", "test_env") -version = str(CONFIG_VERSION) -if CONFIG_DEBUG == True: +version = str(env.Version) +if env.Debug == True: version += "-debug" -env.Append( CCFLAGS = [ "-DCONFIG_VERSION='\"%s\"'" % version ] ) +for e in (env, test_env): + e.Append( CCFLAGS = [ "-DCONFIG_VERSION='\"%s\"'" % version ] ) diff --git a/lib/Sconscript b/lib/Sconscript index 9bc77cf7..17003556 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -1,8 +1,8 @@ #!/usr/bin/python -Import("use_package") +Import("env") -use_package("gstreamer-1.0") -use_package("taglib") +env.UsePackage("gstreamer-1.0") +env.UsePackage("taglib") res = Glob("*.cpp") Return("res") diff --git a/tests/Sconscript b/tests/Sconscript index 3ef2a0c6..39ba2253 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -1,7 +1,7 @@ #!/usr/bin/python -import sys -Import("env") +import sys, os +Import("test_env") tests = [ ### @@ -9,18 +9,19 @@ tests = [ # (source.cpp, use collected lib_files?, [ other files ]) # - ("version.cpp", False, []), - ("file.cpp", True, []), - ("database.cpp", True, []), - ("index.cpp", True, []), - ("filter.cpp", True, []), - ("idle.cpp", False, [ "idle.cpp" ]), - ("tags.cpp", True, []), - ("queue.cpp", True, [ "callback.cpp" ]), + ("version.cpp", False, [], [ "glib-2.0" ]), + ("file.cpp", True, [], []), + ("database.cpp", True, [], []), + ("index.cpp", True, [], []), + ("filter.cpp", True, [], []), + ("idle.cpp", False, [ "idle.cpp" ], []), + ("tags.cpp", True, [], [ "taglib" ]), + ("queue.cpp", True, [ "callback.cpp" ], []), ] - +env = test_env +env.UsePackage("glib-2.0") check_depends = True for arg in sys.argv: @@ -33,15 +34,18 @@ for arg in sys.argv: def expand_files(extra_files): res = [] for f in extra_files: - res += [ "../lib/%s" % f ] + res += [ env.Object("%s-lib" % f, "../lib/%s" % f) ] return res def make_program(src, name, extra_files): return env.Program("%s" % name, [ src ] + expand_files(extra_files)) def make_test(src, name): - test = Command("%s.out" % name, [], - "set -o pipefail; ./tests/%s | tee ./tests/%s.out" % (name, name)) + cmd = "./tests/%s | tee ./tests/%s.out" % (name, name) + if env.Valgrind == True: + cmd = "valgrind -q --leak-check=full --error-exitcode=42 %s" % cmd + + test = Command("%s.out" % name, [], "set -o pipefail; %s" % cmd) Alias("tests/%s" % name, test) AlwaysBuild(test) return test @@ -56,13 +60,16 @@ res = [] lib_files = [] ignore = open(".gitignore", 'w') -for src, lib, extra in tests: +for src, lib, extra, pkgs in tests: name = "%s" % src.rsplit(".")[0] if lib == True: lib_files += [ src ] extra = lib_files + extra + for p in pkgs: + env.UsePackage(p) + test = prepare_test(name, src, extra) if (check_depends == True) and (len(res) > 0): Depends(test, res[len(res) - 1])