diff --git a/.gitignore b/.gitignore index 6698338a..0e9fbb8c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ bin/ .sconsign.dblite *.patch *.tar.gz -tests/*-core +tests/*/*-core tests/*-lib *.gcov *.gcda diff --git a/tests/test.h b/include/tests/test.h similarity index 100% rename from tests/test.h rename to include/tests/test.h diff --git a/tests/Sconscript b/tests/Sconscript index 26d5c6a8..6c898565 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -2,99 +2,86 @@ import sys, os Import("test_env") -tests = [ -### -# -# (source.cpp, use collected lib_files?, [ other files ], [ other packages ]) -# +test_env.UsePackage("glib-2.0") +test_env.DEBUG = True - ("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" ]), - ("random.cpp", False, [ "random.cpp" ], []), - ("queue.cpp", True, [ "callback.cpp", "random.cpp" ], []), - ("library.cpp", True, [ "idle.cpp" ], []), - ("playlist.cpp", True, [], []), - ("deck.cpp", True, [], []), - ("driver.cpp", False, [ "driver.cpp" ], []), - ("audio.cpp", True, [ "driver.cpp" ], []), - -] - -env = test_env -env.UsePackage("glib-2.0") -if env.Coverage == True: - env.Append( CCFLAGS = [ "--coverage" ] ) - env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] ) +if test_env.Coverage == True: + test_env.Append( CCFLAGS = [ "--coverage" ] ) + test_env.Append( LINKFLAGS = [ "-lgcov", "-coverage" ] ) check_depends = True for arg in sys.argv: - if arg.find("tests") == 0 and len(arg) > 5: + if arg.find("tests/core") == 0 and len(arg) > 11: check_depends = False break -def expand_files(extra_files): - res = [] - for f in extra_files: - res += [ env.Object("%s-core" % f, "../core/%s" % f) ] - return res -def make_program(src, name, extra_files): - return env.Program("%s" % name, [ src ] + expand_files(extra_files)) +valgrind = "valgrind -q --leak-check=full --error-exitcode=42" +gcov = "gcov -r tests/%s/*.gcda" -def make_test(src, 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 +class OTest: + Prev = None + Env = test_env -def prepare_test(name, src, extra_files): - exe = make_program(src, name, extra_files) - test = make_test(src, name) - Depends(test, exe) - return test + def __init__(self, src, pkg = None): + self.Name = src.rsplit(".")[0] + self.Src = src + if pkg != None: + test_env.UsePackage(pkg) -res = [] -lib_files = [] + def get_program(self): + return test_env.Program(self.Name, self.Src) -ignore = open(".gitignore", 'w') -for src, lib, extra, pkgs in tests: - name = "%s" % src.rsplit(".")[0] + def prepare(self, subdir): + prog = self.get_program() - if lib == True: - lib_files += [ src ] + extra - extra = lib_files + path = "./tests/%s/%s" % (subdir, self.Name) + cmd = "%s | tee %s.out" % (path, path) + if test_env.Valgrind == True: + cmd = "%s %s" % (valgrind, cmd) + test = Command("%s.out" % self.Name, [], "set -x pipefail; %s" % cmd) - for p in pkgs: - env.UsePackage(p) + Depends(test, prog) + if (check_depends == True) and (OTest.Prev != None): + Depends(test, OTest.Prev) + Alias("tests/%s" % subdir, test) + Alias("tests/%s/%s" % (subdir, self.Name), test) + AlwaysBuild(test) + OTest.Prev = test + return test - test = prepare_test(name, src, extra) - if (check_depends == True) and (len(res) > 0): - Depends(test, res[len(res) - 1]) - res += [ test ] - ignore.write(name + "\n") -ignore.close(); +class TestList: + def __init__(self, subdir, tests): + self.subdir = subdir + self.tests = tests -if env.Coverage == True: - cov = Command("ocarina.gcov", [], "gcov -r tests/*.gcda") - Depends(cov, res[len(res) - 1]) - res += [ cov ] + f = open(".gitignore", "w") + for t in tests: + f.write(t.Name + "\n") + f.close() -if env.CppCheck == True: - check = Command("cpp.check", [], "cppcheck -q .") - Depends(check, res[len(res) - 1]) - res += [ check ] + def prepare(self): + res = [] + for t in self.tests: + res += [ t.prepare(self.subdir) ] + + if test_env.Coverage == True: + res += [ Command("%s.gcov" % self.subdir, [], gcov % self.subdir) ] + Depends(res[len(res) - 1], res[len(res) - 2]) + AlwaysBuild(res[len(res) - 1]) + return res + +Export("OTest", "TestList") + + +core = SConscript("core/Sconscript") + +res = [ core ] +if test_env.CppCheck == True: + res += [ Command("cpp.check", [], "cppcheck -q --error-exitcode=42 .") ] + Depends(res[len(res) - 1], res[len(res) - 2]) Return("res") - -##scripts = [ "library", "deck", "audio", "gui" ] diff --git a/tests/.gitignore b/tests/core/.gitignore similarity index 100% rename from tests/.gitignore rename to tests/core/.gitignore diff --git a/tests/core/Sconscript b/tests/core/Sconscript new file mode 100644 index 00000000..8c24501b --- /dev/null +++ b/tests/core/Sconscript @@ -0,0 +1,42 @@ +#!/usr/bin/python + +Import("OTest", "TestList") + + +class CoreTest(OTest): + Objs = [] + + def __init__(self, src, pkg = None, extra = None): + OTest.__init__(self, src, pkg) + if extra != None: + self.add_object(extra) + + def add_object(self, obj): + path = "../../core/%s" % obj + CoreTest.Objs += [ OTest.Env.Object("%s-core" % obj, path) ] + + def get_program(self): + self.add_object(self.Src) + return OTest.Env.Program(self.Name, [ self.Src ] + CoreTest.Objs) + + +res = TestList("core", [ + + OTest ("version.cpp"), + CoreTest("file.cpp"), + CoreTest("database.cpp"), + CoreTest("index.cpp"), + CoreTest("filter.cpp"), + CoreTest("idle.cpp"), + CoreTest("tags.cpp", "taglib"), + CoreTest("random.cpp"), + CoreTest("queue.cpp", extra = "callback.cpp"), + CoreTest("library.cpp"), + CoreTest("playlist.cpp"), + CoreTest("deck.cpp"), + CoreTest("driver.cpp"), + CoreTest("audio.cpp"), + +]).prepare() + +Return("res") diff --git a/tests/audio.cpp b/tests/core/audio.cpp similarity index 99% rename from tests/audio.cpp rename to tests/core/audio.cpp index efda10a5..72bc3cc0 100644 --- a/tests/audio.cpp +++ b/tests/core/audio.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "test.h" +#include Track *TRACK_NULL = NULL; diff --git a/tests/database.cpp b/tests/core/database.cpp similarity index 99% rename from tests/database.cpp rename to tests/core/database.cpp index b8ced050..a8235b5a 100644 --- a/tests/database.cpp +++ b/tests/core/database.cpp @@ -4,7 +4,7 @@ */ #include -#include "test.h" +#include #include diff --git a/tests/deck.cpp b/tests/core/deck.cpp similarity index 99% rename from tests/deck.cpp rename to tests/core/deck.cpp index f1f8939d..eb96968e 100644 --- a/tests/deck.cpp +++ b/tests/core/deck.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "test.h" +#include static Queue *Q_NULL = NULL; static Track *TRACK_NULL = NULL; diff --git a/tests/driver.cpp b/tests/core/driver.cpp similarity index 98% rename from tests/driver.cpp rename to tests/core/driver.cpp index 8eba2d89..bcebcddf 100644 --- a/tests/driver.cpp +++ b/tests/core/driver.cpp @@ -2,7 +2,7 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include "test.h" +#include static TestDriver *DRIVER_NULL = NULL; static unsigned int eos_count = 0; diff --git a/tests/file.cpp b/tests/core/file.cpp similarity index 98% rename from tests/file.cpp rename to tests/core/file.cpp index fb2f0e25..74c0bc90 100644 --- a/tests/file.cpp +++ b/tests/core/file.cpp @@ -2,7 +2,7 @@ * Copyright 2014 (c) Anna Schumaker. */ #include -#include "test.h" +#include static void test_filepath() diff --git a/tests/filter.cpp b/tests/core/filter.cpp similarity index 99% rename from tests/filter.cpp rename to tests/core/filter.cpp index 88c02737..75b27767 100644 --- a/tests/filter.cpp +++ b/tests/core/filter.cpp @@ -4,7 +4,7 @@ */ #include -#include "test.h" +#include static void do_test_lowercase(const std::string &text, const std::string &lc) { diff --git a/tests/idle.cpp b/tests/core/idle.cpp similarity index 97% rename from tests/idle.cpp rename to tests/core/idle.cpp index 489cc8af..489660ef 100644 --- a/tests/idle.cpp +++ b/tests/core/idle.cpp @@ -4,7 +4,7 @@ */ #include -#include "test.h" +#include #include diff --git a/tests/index.cpp b/tests/core/index.cpp similarity index 99% rename from tests/index.cpp rename to tests/core/index.cpp index dfc9fc2a..b17588df 100644 --- a/tests/index.cpp +++ b/tests/core/index.cpp @@ -4,7 +4,7 @@ */ #include -#include "test.h" +#include #include diff --git a/tests/library.cpp b/tests/core/library.cpp similarity index 99% rename from tests/library.cpp rename to tests/core/library.cpp index 75ce55f2..ecbd825e 100644 --- a/tests/library.cpp +++ b/tests/core/library.cpp @@ -3,7 +3,7 @@ */ #include #include -#include "test.h" +#include static Queue *Q_NULL = NULL; static Library *LIB_NULL = NULL; diff --git a/tests/playlist.cpp b/tests/core/playlist.cpp similarity index 99% rename from tests/playlist.cpp rename to tests/core/playlist.cpp index 7c141071..ff984845 100644 --- a/tests/playlist.cpp +++ b/tests/core/playlist.cpp @@ -3,7 +3,7 @@ */ #include #include -#include "test.h" +#include static IndexEntry *IDX_NULL = NULL; static Queue *Q_NULL = NULL; diff --git a/tests/queue.cpp b/tests/core/queue.cpp similarity index 99% rename from tests/queue.cpp rename to tests/core/queue.cpp index 7bcfe8ca..b7bf8402 100644 --- a/tests/queue.cpp +++ b/tests/core/queue.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "test.h" +#include unsigned int count_add = 0; diff --git a/tests/random.cpp b/tests/core/random.cpp similarity index 96% rename from tests/random.cpp rename to tests/core/random.cpp index 45a161fd..5c057828 100644 --- a/tests/random.cpp +++ b/tests/core/random.cpp @@ -3,7 +3,7 @@ */ #include -#include "test.h" +#include #include diff --git a/tests/tags.cpp b/tests/core/tags.cpp similarity index 99% rename from tests/tags.cpp rename to tests/core/tags.cpp index efd307bd..4c837adb 100644 --- a/tests/tags.cpp +++ b/tests/core/tags.cpp @@ -4,7 +4,7 @@ */ #include -#include "test.h" +#include static Library *LIB_NULL = NULL; static Track *TRACK_NULL = NULL; diff --git a/tests/version.cpp b/tests/core/version.cpp similarity index 93% rename from tests/version.cpp rename to tests/core/version.cpp index 8c31017a..45c7bcea 100644 --- a/tests/version.cpp +++ b/tests/core/version.cpp @@ -2,7 +2,7 @@ * Copyright 2013 (c) Anna Schumaker. */ #include -#include "test.h" +#include #ifdef CONFIG_DEBUG const std::string expected = "6.1-debug";