Added TEST_UNSAFE to avoid exception checking in normal tests, as well as an assert_inequal() evaluation in TestableAssertions.h.
parent
f594ebf562
commit
815d892806
|
|
@ -12,8 +12,8 @@ Test::Test (const SimpleString& testName)
|
||||||
TestRegistry::addTest (this);
|
TestRegistry::addTest (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Test::Test (const SimpleString& testName, const SimpleString& filename, long lineNumber)
|
Test::Test (const SimpleString& testName, const SimpleString& filename, long lineNumber, bool safeCheck = true)
|
||||||
: name_(testName), filename_(filename), lineNumber_(lineNumber)
|
: name_(testName), filename_(filename), lineNumber_(lineNumber), safeCheck_(safeCheck)
|
||||||
{
|
{
|
||||||
TestRegistry::addTest (this);
|
TestRegistry::addTest (this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Test (const SimpleString& testName);
|
Test (const SimpleString& testName);
|
||||||
Test (const SimpleString& testName, const SimpleString& filename, long lineNumber);
|
Test (const SimpleString& testName, const SimpleString& filename, long lineNumber, bool safeCheck);
|
||||||
virtual ~Test() {};
|
virtual ~Test() {};
|
||||||
|
|
||||||
virtual void run (TestResult& result) = 0;
|
virtual void run (TestResult& result) = 0;
|
||||||
|
|
@ -33,6 +33,7 @@ public:
|
||||||
SimpleString getName() const {return name_;}
|
SimpleString getName() const {return name_;}
|
||||||
SimpleString getFilename() const {return filename_;}
|
SimpleString getFilename() const {return filename_;}
|
||||||
long getLineNumber() const {return lineNumber_;}
|
long getLineNumber() const {return lineNumber_;}
|
||||||
|
bool safe() const {return safeCheck_;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
@ -43,13 +44,27 @@ protected:
|
||||||
Test *next_;
|
Test *next_;
|
||||||
SimpleString filename_;
|
SimpleString filename_;
|
||||||
long lineNumber_; /// This is the line line number of the test, rather than the a single check
|
long lineNumber_; /// This is the line line number of the test, rather than the a single check
|
||||||
|
bool safeCheck_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normal test will wrap execution in a try/catch block to catch exceptions more effectively
|
||||||
|
*/
|
||||||
#define TEST(testName, testGroup)\
|
#define TEST(testName, testGroup)\
|
||||||
class testGroup##testName##Test : public Test \
|
class testGroup##testName##Test : public Test \
|
||||||
{ public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__) {} \
|
{ public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__, true) {} \
|
||||||
|
void run (TestResult& result_);} \
|
||||||
|
testGroup##testName##Instance; \
|
||||||
|
void testGroup##testName##Test::run (TestResult& result_)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For debugging only: use TEST_UNSAFE to allow debuggers to have access to exceptions, as this
|
||||||
|
* will not wrap execution with a try/catch block
|
||||||
|
*/
|
||||||
|
#define TEST_UNSAFE(testName, testGroup)\
|
||||||
|
class testGroup##testName##Test : public Test \
|
||||||
|
{ public: testGroup##testName##Test () : Test (#testName "Test", __FILE__, __LINE__, false) {} \
|
||||||
void run (TestResult& result_);} \
|
void run (TestResult& result_);} \
|
||||||
testGroup##testName##Instance; \
|
testGroup##testName##Instance; \
|
||||||
void testGroup##testName##Test::run (TestResult& result_)
|
void testGroup##testName##Test::run (TestResult& result_)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ int TestRegistry::run (TestResult& result)
|
||||||
result.testsStarted ();
|
result.testsStarted ();
|
||||||
|
|
||||||
for (Test *test = tests; test != 0; test = test->getNext ()) {
|
for (Test *test = tests; test != 0; test = test->getNext ()) {
|
||||||
|
if (test->safe()) {
|
||||||
try {
|
try {
|
||||||
test->run (result);
|
test->run (result);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
|
|
@ -59,6 +60,10 @@ int TestRegistry::run (TestResult& result)
|
||||||
SimpleString("ExceptionThrown!")));
|
SimpleString("ExceptionThrown!")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
test->run (result);
|
||||||
|
}
|
||||||
|
}
|
||||||
result.testsEnded ();
|
result.testsEnded ();
|
||||||
return result.getFailureCount();
|
return result.getFailureCount();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,17 @@ bool assert_equal(const std::vector<V>& expected, const std::vector<V>& actual,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow for testing inequality
|
||||||
|
*/
|
||||||
|
template<class V>
|
||||||
|
bool assert_inequal(const V& expected, const V& actual, double tol = 1e-9) {
|
||||||
|
if (!actual.equals(expected, tol))
|
||||||
|
return true;
|
||||||
|
printf("Erroneously equal:\n");
|
||||||
|
expected.print("expected");
|
||||||
|
actual.print("actual");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // \namespace gtsam
|
} // \namespace gtsam
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <gtsam/CppUnitLite/TestHarness.h>
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <gtsam/base/TestableAssertions.h>
|
||||||
|
|
||||||
#define GTSAM_MAGIC_KEY
|
#define GTSAM_MAGIC_KEY
|
||||||
|
|
||||||
#include <gtsam/geometry/Pose2.h>
|
#include <gtsam/geometry/Pose2.h>
|
||||||
|
|
@ -410,9 +412,9 @@ TEST( TupleConfig, equals )
|
||||||
|
|
||||||
EXPECT(assert_equal(config1,config2));
|
EXPECT(assert_equal(config1,config2));
|
||||||
EXPECT(assert_equal(config1,config1));
|
EXPECT(assert_equal(config1,config1));
|
||||||
EXPECT(!config1.equals(config3));
|
EXPECT(assert_inequal(config1,config3));
|
||||||
EXPECT(!config1.equals(config4));
|
EXPECT(assert_inequal(config1,config4));
|
||||||
EXPECT(!config1.equals(config5));
|
EXPECT(assert_inequal(config1,config5));
|
||||||
EXPECT(assert_equal(config1, config6));
|
EXPECT(assert_equal(config1, config6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue