--- /dev/null 2016-05-02 13:22:46.000000000 +0300 +++ new/test/native/unittest.hpp 2016-05-02 13:22:45.000000000 +0300 @@ -0,0 +1,80 @@ +#include +#include + +#define GTEST_DONT_DEFINE_TEST 1 +#include "gtest/gtest.h" +#ifdef assert + #undef assert +#endif + +#define CONCAT(a, b) a ## b + +#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test)) + +#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm)) + +#define TEST_VM_F(test_fixture, name) \ + GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture, \ + ::testing::internal::GetTypeId()) + +#define TEST_OTHER_VM(category, name) \ + static void test_ ## category ## _ ## name ## _(); \ + \ + static void child_ ## category ## _ ## name ## _() { \ + ::testing::GTEST_FLAG(throw_on_failure) = true; \ + test_ ## category ## _ ## name ## _(); \ + fprintf(stderr, "OKIDOKI"); \ + exit(0); \ + } \ + \ + TEST(category, CONCAT(name, _other_vm)) { \ + ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ + ::testing::ExitedWithCode(0), \ + ".*OKIDOKI.*"); \ + } \ + \ + void test_ ## category ## _ ## name ## _() + +#ifdef ASSERT +#define TEST_VM_ASSERT(category, name) \ + static void test_ ## category ## _ ## name ## _(); \ + \ + static void child_ ## category ## _ ## name ## _() { \ + ::testing::GTEST_FLAG(throw_on_failure) = true; \ + test_ ## category ## _ ## name ## _(); \ + exit(0); \ + } \ + \ + TEST(category, CONCAT(name, _vm_assert)) { \ + ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ + ::testing::ExitedWithCode(1), \ + "assert failed"); \ + } \ + \ + void test_ ## category ## _ ## name ## _() +#else +#define TEST_VM_ASSERT(...) \ + TEST_VM_ASSERT is only available in debug builds +#endif + +#ifdef ASSERT +#define TEST_VM_ASSERT_MSG(category, name, msg) \ + static void test_ ## category ## _ ## name ## _(); \ + \ + static void child_ ## category ## _ ## name ## _() { \ + ::testing::GTEST_FLAG(throw_on_failure) = true; \ + test_ ## category ## _ ## name ## _(); \ + exit(0); \ + } \ + \ + TEST(category, CONCAT(name, _vm_assert)) { \ + ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ + ::testing::ExitedWithCode(1), \ + "assert failed: " msg); \ + } \ + \ + void test_ ## category ## _ ## name ## _() +#else +#define TEST_VM_ASSERT_MSG(...) \ + TEST_VM_ASSERT_MSG is only available in debug builds +#endif