[beast: 9/15] SFI: provide simplistic TEST_ADD() and Bse::Test::run
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 9/15] SFI: provide simplistic TEST_ADD() and Bse::Test::run
- Date: Sun, 23 Jul 2017 18:58:35 +0000 (UTC)
commit 7482e2184e9cd79a7cdd0440cae29cf2ef861a0c
Author: Tim Janik <timj gnu org>
Date: Sun Jul 23 01:47:59 2017 +0200
SFI: provide simplistic TEST_ADD() and Bse::Test::run
Signed-off-by: Tim Janik <timj gnu org>
sfi/testing.cc | 40 +++++++++++++++++++++++++++++++++-------
sfi/testing.hh | 12 ++++++++++++
sfi/tests/misctests.cc | 40 +++++++---------------------------------
3 files changed, 52 insertions(+), 40 deletions(-)
---
diff --git a/sfi/testing.cc b/sfi/testing.cc
index 16c9431..3e42f2b 100644
--- a/sfi/testing.cc
+++ b/sfi/testing.cc
@@ -199,13 +199,6 @@ verbose()
return cached_verbose;
}
-int
-run (void)
-{
- // FIXME: run_tests();
- return 0;
-}
-
uint64_t
random_int64 ()
{
@@ -230,4 +223,37 @@ random_frange (double begin, double end)
return Bse::random_frange (begin, end);
}
+// == TestChain ==
+static const TestChain *global_test_chain = NULL;
+
+TestChain::TestChain (std::function<void()> tfunc, const std::string &tname) :
+ name_ (tname), func_ (tfunc), next_ (global_test_chain)
+{
+ assert_return (next_ == global_test_chain);
+ global_test_chain = this;
+}
+
+void
+TestChain::run (ptrdiff_t internal_token)
+{
+ assert_return (internal_token == ptrdiff_t (global_test_chain));
+ for (const TestChain *t = global_test_chain; t; t = t->next_)
+ {
+ fflush (stderr);
+ printout (" RUN… %s\n", t->name_);
+ fflush (stdout);
+ t->func_();
+ fflush (stderr);
+ printout (" PASS %s\n", t->name_);
+ fflush (stdout);
+ }
+}
+
+int
+run (void)
+{
+ TestChain::run (ptrdiff_t (global_test_chain));
+ return 0;
+}
+
} } // Bse::Test
diff --git a/sfi/testing.hh b/sfi/testing.hh
index 56e093e..4591fbf 100644
--- a/sfi/testing.hh
+++ b/sfi/testing.hh
@@ -23,6 +23,9 @@ void init (int *argcp, char **argv, const StringVector &args = StringVector());
#define TASSERT_AT(LINE, cond) TASSERT__AT (LINE, cond) ///< Unconditional test assertion for deputy
__LINE__.
#define TOK() do {} while (0) ///< Deprecated progress indicator, tests
generally need to run fast.
+/// Register a function to run as part of the unit test suite.
+#define TEST_ADD(fun) static const ::Bse::Test::TestChain BSE_CPP_PASTE2 (__Bse__Test__TestChain_,
__LINE__) (fun, BSE_CPP_STRINGIFY (fun))
+
/** Class for profiling benchmark tests.
* UseCase: Benchmarking function implementations, e.g. to compare sorting implementations.
*/
@@ -120,6 +123,15 @@ Timer::benchmark (Callee callee)
return min_elapsed();
}
+class TestChain {
+ std::string name_;
+ std::function<void()> func_;
+ const TestChain *const next_;
+public:
+ explicit TestChain (std::function<void()> tfunc, const std::string &tname);
+ static void run (ptrdiff_t internal_token);
+};
+
/// @endcond
} // Test
diff --git a/sfi/tests/misctests.cc b/sfi/tests/misctests.cc
index 12dea49..2e54f0b 100644
--- a/sfi/tests/misctests.cc
+++ b/sfi/tests/misctests.cc
@@ -11,35 +11,6 @@
using namespace Bse;
-struct TestChain;
-static const TestChain *global_test_chain = NULL;
-
-struct TestChain {
- std::string name;
- std::function<void()> func;
- const TestChain *const next;
- TestChain (std::function<void()> tfunc, const std::string &tname) :
- name (tname), func (tfunc), next (global_test_chain)
- {
- assert_return (next == global_test_chain);
- global_test_chain = this;
- }
-};
-
-static void
-run_test_chain()
-{
- for (const TestChain *t = global_test_chain; t; t = t->next)
- {
- printout (" .... %s", t->name);
- fflush (stdout);
- t->func();
- printout ("\r PASS %s\n", t->name);
- }
-}
-
-#define ADD_TEST(fun) static const TestChain BSE_CPP_PASTE2 (__testchain__, __LINE__) (fun,
BSE_CPP_STRINGIFY (fun))
-
static void
test_paths()
{
@@ -112,7 +83,7 @@ test_paths()
TCMP (Path::searchpath_contains ("/foo/:/bar", "/bar"), ==, true); // file search matches /bar
TCMP (Path::searchpath_contains ("/foo/:/bar", "/bar/"), ==, true); // dir search matches /bar
}
-ADD_TEST (test_paths);
+TEST_ADD (test_paths);
static void
test_timestamps()
@@ -132,7 +103,7 @@ test_timestamps()
const uint64 b2 = timestamp_benchmark();
TASSERT (b1 < b2);
}
-ADD_TEST (test_timestamps);
+TEST_ADD (test_timestamps);
static void
test_feature_toggles()
@@ -154,7 +125,7 @@ test_feature_toggles()
b = feature_toggle_bool ("no-a:b:a=5:c", "b"); TCMP (b, ==, true);
b = feature_toggle_bool ("x", ""); TCMP (b, ==, true); // *any* feature?
}
-ADD_TEST (test_feature_toggles);
+TEST_ADD (test_feature_toggles);
/* provide IDL type initializers */
#define sfidl_pspec_Real(group, name, nick, blurb, dflt, min, max, step, hints) \
@@ -902,7 +873,10 @@ main (int argc,
generate_vmarshal_code ();
return 0;
}
- run_test_chain();
+
+ if (0 != Bse::Test::run())
+ return -1;
+
test_notes ();
test_time ();
test_renames ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]