summaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index a1149ef..07263a3 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -7,6 +7,7 @@
test_runner* test_runner::_tests = 0;
size_t test_runner::_memory_fail_threshold = 0;
+jmp_buf test_runner::_failure;
static size_t g_memory_total_size = 0;
@@ -46,33 +47,58 @@ static void replace_memory_management()
pugi::set_memory_management_functions(custom_allocate, custom_deallocate);
}
+#if defined(_MSC_VER) && _MSC_VER > 1200 && _MSC_VER < 1400 && !defined(__INTEL_COMPILER)
+namespace std
+{
+ _CRTIMP2 _Prhand _Raise_handler;
+ _CRTIMP2 void __cdecl _Throw(const exception&) {}
+}
+#endif
+
static bool run_test(test_runner* test)
{
+#ifndef PUGIXML_NO_EXCEPTIONS
try
{
+#endif
g_memory_total_size = 0;
test_runner::_memory_fail_threshold = 0;
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4611) // interaction between _setjmp and C++ object destruction is non-portable
+#endif
+
+ volatile int result = setjmp(test_runner::_failure);
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+ if (result)
+ {
+ printf("Test %s failed: %s\n", test->_name, (const char*)(intptr_t)result);
+ return false;
+ }
test->run();
- if (g_memory_total_size != 0) throw "Memory leaks found";
+ if (g_memory_total_size != 0) longjmp(test_runner::_failure, (int)(intptr_t)"Memory leaks found");
return true;
+#ifndef PUGIXML_NO_EXCEPTIONS
}
catch (const std::exception& e)
{
printf("Test %s failed: exception %s\n", test->_name, e.what());
- }
- catch (const char* e)
- {
- printf("Test %s failed: %s\n", test->_name, e);
+ return false;
}
catch (...)
{
printf("Test %s failed for unknown reason\n", test->_name);
+ return false;
}
-
- return false;
+#endif
}
int main()