Skip to content

Commit

Permalink
Merge 1278e6e into eda002e
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Oct 9, 2020
2 parents eda002e + 1278e6e commit e1aa63b
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 34 deletions.
8 changes: 6 additions & 2 deletions .drone.yml
Expand Up @@ -53,8 +53,8 @@ trigger:

steps:
- &gcc
name: 5
image: gcc:5
name: 5.5
image: gcc:5.5
commands:
- "cp -R ./test ./$${DRONE_STEP_NAME} && cd $${DRONE_STEP_NAME}"
- make showcxxversion && make clean && make -j4 $${MAKE_OPTIONS}
Expand All @@ -66,6 +66,10 @@ steps:
# <<: *gcc
# name: 5
# image: gcc:5
-
<<: *gcc
name: 5.1
image: gcc:5.1
-
<<: *gcc
name: 4.9
Expand Down
40 changes: 40 additions & 0 deletions include/impl/iutest_core_impl.ipp
Expand Up @@ -300,6 +300,46 @@ IUTEST_IPP_INLINE ::std::string MakePrefixedIndexTestName(const char* prefix, co
return name;
}

IUTEST_IPP_INLINE void UncaughtScopedTrace::Add(const detail::iuCodeMessage& msg)
{
const Test* curr = Test::GetCurrentTest();
if( curr == NULL || curr->m_test_info == NULL )
{
return;
}
TestInfo* p = curr->m_test_info->ptr();
if( p != NULL )
{
p->m_uncaught_messages.push_back(msg);
}
}

IUTEST_IPP_INLINE bool UncaughtScopedTrace::Has()
{
const TestInfo* curr = Test::GetCurrentTestInfo();
if( curr == NULL )
{
return false;
}
return !curr->m_uncaught_messages.empty();
}

IUTEST_IPP_INLINE ::std::string UncaughtScopedTrace::Get()
{
const TestInfo* curr = Test::GetCurrentTestInfo();
::std::string msg = "";
if( curr != NULL )
{
const TestInfo::UncaughtMessagesType& v = curr->m_uncaught_messages;
for( TestInfo::UncaughtMessagesType::const_iterator it = v.begin(), end=v.end(); it != end; ++it )
{
msg.append("\n");
msg.append(it->make_message().c_str());
}
}
return msg;
}

} // end of namespace detail

IUTEST_IPP_INLINE void Test::TestRecordPropertyHelper::RecordProperty(const TestProperty& prop)
Expand Down
7 changes: 5 additions & 2 deletions include/impl/iutest_info.ipp
Expand Up @@ -66,7 +66,8 @@ IUTEST_IPP_INLINE void TestInfo::RunImpl()
catch (const ::std::exception& e)
{
elapsedmsec = sw.stop();
iutest::AssertionHelper(NULL, -1, detail::FormatCxxException(e.what()), TestPartResult::kFatalFailure).OnFixed(AssertionHelper::Fixed());
iutest::AssertionHelper(NULL, -1, detail::FormatCxxException(e.what())
, TestPartResult::kFatalFailure).OnFixed(AssertionHelper::Fixed(), true);
if( TestFlag::IsEnableFlag(TestFlag::THROW_ON_FAILURE) )
{
throw;
Expand All @@ -83,7 +84,8 @@ IUTEST_IPP_INLINE void TestInfo::RunImpl()
catch (...)
{
elapsedmsec = sw.stop();
iutest::AssertionHelper(NULL, -1, detail::FormatCxxException(NULL), TestPartResult::kFatalFailure).OnFixed(AssertionHelper::Fixed());
iutest::AssertionHelper(NULL, -1, detail::FormatCxxException(NULL)
, TestPartResult::kFatalFailure).OnFixed(AssertionHelper::Fixed(), true);
if( TestFlag::IsEnableFlag(TestFlag::THROW_ON_FAILURE) )
{
throw;
Expand Down Expand Up @@ -150,6 +152,7 @@ IUTEST_IPP_INLINE void TestInfo::clear()
m_ran = false;
m_skip = false;
m_test_result.Clear();
m_uncaught_messages.clear();
}

IUTEST_IPP_INLINE bool TestInfo::filter()
Expand Down
4 changes: 2 additions & 2 deletions include/internal/iutest_exception.hpp
Expand Up @@ -47,7 +47,7 @@ inline ::std::string FormatCxxException(const char* description)
} // end of namespace detail
} // end of namespace iutest

#if IUTEST_HAS_SEH && IUTEST_HAS_EXCEPTIONS
#if IUTEST_HAS_SEH
#include <iomanip>

namespace iutest {
Expand All @@ -61,7 +61,7 @@ class seh_exception : public ::std::exception
{
public:
seh_exception() : ::std::exception() {}
explicit seh_exception(const char *const& _What) : ::std::exception(_What) {}
explicit seh_exception(const char *const& what) : ::std::exception(what) {}
public:
static void translator(DWORD code, _EXCEPTION_POINTERS* ep)
{
Expand Down
6 changes: 5 additions & 1 deletion include/internal/iutest_list.hpp
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2011-2019, Takazumi Shirayanagi\n
* Copyright (C) 2011-2020, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -157,6 +157,10 @@ class iu_list
{
return count();
}
bool empty() const IUTEST_CXX_NOEXCEPT_SPEC
{
return m_node == NULL;
}
public:
// ソートして挿入
void sort_insert(node_ptr p)
Expand Down
9 changes: 9 additions & 0 deletions include/internal/iutest_stdlib.hpp
Expand Up @@ -266,6 +266,15 @@ class optional
T m_value;
};

inline bool uncaught_exception()
{
#if IUTEST_HAS_CXX1Z && (!defined(IUTEST_LIBSTDCXX_VERSION) || (IUTEST_LIBSTDCXX_VERSION >= 60000))
return ::std::uncaught_exceptions() > 0;
#else
return ::std::uncaught_exception();
#endif
}

} // end of namespace stl

namespace detail
Expand Down
37 changes: 28 additions & 9 deletions include/iutest_assertion.hpp
Expand Up @@ -41,9 +41,19 @@ inline ::std::string StreamableToString(const T& value)
// declare
namespace detail
{
//! TestPartResultReporter がない場合の処理関数
void DefaultReportTestPartResult(const TestPartResult& test_part_result);
}

//! TestPartResultReporter がない場合の処理関数
void DefaultReportTestPartResult(const TestPartResult& test_part_result);

class UncaughtScopedTrace
{
public:
static void Add(const detail::iuCodeMessage& msg);
static bool Has();
static ::std::string Get();
};

} // end of namespace detail

//======================================================================
// class
Expand Down Expand Up @@ -217,6 +227,10 @@ class AssertionHelper
~ScopedMessage()
{
ScopedTrace::GetInstance().list.remove(this);
if( stl::uncaught_exception() )
{
detail::UncaughtScopedTrace::Add(*this);
}
}
};
private:
Expand All @@ -229,20 +243,25 @@ class AssertionHelper
typedef ::std::list<ScopedMessage*> msg_list;
#endif
msg_list list;

static ScopedTrace& GetInstance() { static ScopedTrace inst; return inst; }
public:
void append_message(TestPartResult& part_result)
void append_message(TestPartResult& part_result, bool isException)
{
if( list.size() )
if( !list.empty() || detail::UncaughtScopedTrace::Has() )
{
part_result.add_message("\niutest trace:");
// TODO : 追加メッセージとして保存するべき
// 現状はテスト結果のメッセージに追加している。
for( msg_list::iterator it = list.begin(), end=list.end(); it != end; ++it )
{
// TODO : 追加メッセージとして保存するべき
// 現状はテスト結果のメッセージに追加している。
part_result.add_message("\n");
part_result.add_message((*it)->make_message().c_str());
}
if( isException )
{
part_result.add_message(detail::UncaughtScopedTrace::Get());
}
}
}
};
Expand Down Expand Up @@ -334,15 +353,15 @@ class AssertionHelper
#endif

private:
void OnFixed(const Fixed& fixed)
void OnFixed(const Fixed& fixed, bool isException = false)
{
// OnFixed で throw しないこと!テスト側の例外キャッチにかからなくなる
const ::std::string append_message = fixed.GetString();
if( !append_message.empty() )
{
m_part_result.add_message(" " + append_message);
}
ScopedTrace::GetInstance().append_message(m_part_result);
ScopedTrace::GetInstance().append_message(m_part_result, isException);

if( TestEnv::GetGlobalTestPartResultReporter() != IUTEST_NULLPTR )
{
Expand Down
1 change: 1 addition & 0 deletions include/iutest_body.hpp
Expand Up @@ -217,6 +217,7 @@ class Test
friend class UnitTest;
friend class UnitTestImpl;
friend class TestInfo;
friend class detail::UncaughtScopedTrace;

detail::iuITestInfoMediator* m_test_info;
#if IUTEST_HAS_GENRAND
Expand Down
4 changes: 4 additions & 0 deletions include/iutest_info.hpp
Expand Up @@ -240,6 +240,7 @@ class TestInfo
friend class UnitTestImpl;
friend class UnitTest;
friend class TestSuite;
friend class detail::UncaughtScopedTrace;

::std::string m_testname; //!< テスト名
::std::string m_value_param; //!< value param string
Expand All @@ -253,6 +254,9 @@ class TestInfo
bool m_skip; //!< スキップしたかどうか
bool m_matches_filter; //!< フィルターにマッチしたかどうか

typedef ::std::vector<detail::iuCodeMessage> UncaughtMessagesType;
UncaughtMessagesType m_uncaught_messages;

IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TestInfo);
};

Expand Down
4 changes: 4 additions & 0 deletions projects/cmake/CMakeLists.txt
Expand Up @@ -152,6 +152,7 @@ if (build_tests)
cxx_executable_test(env_var_gtest_tests)
cxx_executable_test(environment_tests)
cxx_executable_test(exception_assertion_tests)
cxx_executable_test(exception_setup_testsuite_tests)
cxx_executable_test(exception_tests)
cxx_executable_test(expression_assertion_tests)
cxx_executable_test_with_main(extension_tests
Expand Down Expand Up @@ -252,6 +253,7 @@ if (build_tests)
cxx_executable_test(param_test_name_invalid_tests)
cxx_executable_test(param_test_name_tests)
cxx_executable_test(no_yoda_tests)
cxx_executable_test(scoped_trace_exception_tests)
cxx_executable_test(tap_file_generator_listener_tests)
cxx_executable_test(tap_printer_listener_tests)
cxx_executable_test(type_param_strict_tests)
Expand Down Expand Up @@ -285,6 +287,7 @@ if (build_tests)
cxx_add_test(env_var_gtest_tests)
cxx_add_test(environment_tests)
cxx_add_test(exception_assertion_tests)
cxx_add_test(exception_setup_testsuite_tests)
cxx_add_test(exception_tests)
cxx_add_test(expression_assertion_tests)
cxx_add_test(extension_tests)
Expand Down Expand Up @@ -345,6 +348,7 @@ if (build_tests)
cxx_add_test(param_test_name_invalid_tests)
cxx_add_test(param_test_name_tests)
cxx_add_test(no_yoda_tests)
cxx_add_test(scoped_trace_exception_tests)
cxx_add_test(tap_file_generator_listener_tests)
cxx_add_test(tap_printer_listener_tests)
cxx_add_test(type_param_strict_tests)
Expand Down
20 changes: 19 additions & 1 deletion projects/vscode/iutest.code-workspace
Expand Up @@ -98,7 +98,25 @@
"__functional_base_03": "cpp",
"__hash_table": "cpp",
"__tree": "cpp",
"__tuple": "cpp"
"__tuple": "cpp",
"__bit_reference": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"mutex": "cpp",
"numeric": "cpp",
"stack": "cpp",
"unordered_map": "cpp"
}
},
"launch": {
Expand Down
2 changes: 2 additions & 0 deletions test/CommonMakefile.in
Expand Up @@ -110,6 +110,7 @@ TARGETS1= \
$(OUTDIR)/env_var_gtest_tests \
$(OUTDIR)/environment_tests \
$(OUTDIR)/exception_assertion_tests \
$(OUTDIR)/exception_setup_testsuite_tests \
$(OUTDIR)/exception_tests \
$(OUTDIR)/expression_assertion_tests \
$(OUTDIR)/file_system_tests \
Expand Down Expand Up @@ -181,6 +182,7 @@ TARGETS_IUTEST_ONLY = \
$(OUTDIR)/param_test_name_invalid_tests \
$(OUTDIR)/param_test_name_tests \
$(OUTDIR)/no_yoda_tests \
$(OUTDIR)/scoped_trace_exception_tests \
$(OUTDIR)/tap_file_generator_listener_tests \
$(OUTDIR)/tap_printer_listener_tests \
$(OUTDIR)/type_param_strict_tests
Expand Down

0 comments on commit e1aa63b

Please sign in to comment.