spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit b2dea0178c2fff06584a435e9b5310115899b2f1
parent 7a1112a3a846fe9575ab8dc6670b5c00effe1c32
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Thu, 21 Feb 2013 18:28:25 -0800

Better test error reporting

Diffstat:
Mtests/test.cc | 16++--------------
Mtests/test.h | 14++++++++++++--
2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/tests/test.cc b/tests/test.cc @@ -16,12 +16,10 @@ * along with Spek. If not, see <http://www.gnu.org/licenses/>. */ -#include <iostream> - #include "test.h" -static int g_passes = 0; -static int g_total = 0; +int g_passes = 0; +int g_total = 0; int main() { @@ -42,13 +40,3 @@ void run(std::function<void ()> func, const std::string& message) std::cerr << message << std::endl; func(); } - -void test(const std::string& message, bool condition) -{ - g_total++; - if (condition) { - g_passes++; - } else { - std::cerr << "FAIL: " << message << std::endl; - } -} diff --git a/tests/test.h b/tests/test.h @@ -20,14 +20,24 @@ #define TEST_H_ #include <functional> +#include <iostream> #include <string> void run(std::function<void ()> func, const std::string& message); -void test(const std::string& message, bool condition); + +extern int g_total; +extern int g_passes; template<class T> void test(const std::string& message, const T& expected, const T& actual) { - test(message, expected == actual); + g_total++; + if (expected == actual) { + g_passes++; + } else { + std::cerr << "FAIL: " << message; + std::cerr << ", expected: " << expected; + std::cerr << ", actual: " << actual << std::endl; + } } void test_utils();