diff --git a/include/impl/iutest_default_xml_generator.ipp b/include/impl/iutest_default_xml_generator.ipp index 9fbe27e33d..6bb4bd6766 100644 --- a/include/impl/iutest_default_xml_generator.ipp +++ b/include/impl/iutest_default_xml_generator.ipp @@ -32,15 +32,14 @@ IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnTestIterationStart(const U } if( !m_output_path_format.empty() ) { - // FIXME: -Wformat-nonliteral -IUTEST_PRAGMA_WARN_PUSH() -IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() - m_output_path = detail::StringFormat(m_output_path_format.c_str(), iteration); + m_output_path = m_output_path_format; + ::std::string strIte = detail::iu_to_string(iteration); + detail::StringReplace(m_output_path, "%d", 2, strIte.c_str()); + detail::StringReplace(m_output_path, "{I}", 3, strIte.c_str()); if( m_output_path == m_output_path_format) { m_output_path_format.clear(); } -IUTEST_PRAGMA_WARN_POP() if( m_fp != NULL ) { OnReportTest(m_fp, test); diff --git a/include/internal/iutest_string.hpp b/include/internal/iutest_string.hpp index 1e996b2c82..053debc616 100644 --- a/include/internal/iutest_string.hpp +++ b/include/internal/iutest_string.hpp @@ -225,15 +225,20 @@ inline bool IsStringContains(const char* str1, const char* str2) { return strstr inline bool IsStringContains(const ::std::string& str1, const char* str2) { return str1.find(str2) != ::std::string::npos; } inline bool IsStringContains(const ::std::string& str1, const ::std::string& str2) { return str1.find(str2) != ::std::string::npos; } -inline void StringReplace(::std::string& str, char a, const char* to) +inline void StringReplace(::std::string& str, const char* from, size_t n, const char* to) { ::std::string::size_type pos = 0; - while( static_cast(pos = str.find(a, pos)), pos != ::std::string::npos ) + while( static_cast(pos = str.find(from, pos)), pos != ::std::string::npos ) { - str.replace(pos, 1, to); + str.replace(pos, n, to); ++pos; } } +inline void StringReplace(::std::string& str, char a, const char* to) +{ + char s[] = { a, 0 }; + return StringReplace(str, s, 1, to); +} inline ::std::string StripLeadingSpace(const ::std::string& str) { ::std::string::const_iterator it = str.begin(); diff --git a/include/iutest_ver.hpp b/include/iutest_ver.hpp index 1f2ec5f99c..886ab98ac0 100644 --- a/include/iutest_ver.hpp +++ b/include/iutest_ver.hpp @@ -126,6 +126,7 @@ modification, are permitted provided that the following conditions are met: \n
  • GTEST_SKIP 対応
  • ::std::wstring_view / ::std::u16string_view / ::std::u32string_view 対応
  • アサーションに operator << したときの出力を PrintToString したものと同じになるように変更
  • +
  • テストをリピートした際のレポート出力ファイル名の書式を printf 書式から {I} に変更({I} にリピート回数が置換されます)
  • Python2 のサポート終了
  • C++20 で削除された basic_ostream::operator << に対応
  • Google Test 旧バージョンとの互換性を修正
  • diff --git a/test/assertion_only_tests.cpp b/test/assertion_only_tests.cpp index 232c18a352..c2481b51b4 100644 --- a/test/assertion_only_tests.cpp +++ b/test/assertion_only_tests.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2019, Takazumi Shirayanagi\n + * Copyright (C) 2012-2020, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -40,9 +40,11 @@ static ::iutest::iu_stringstream s_outstream; void test_vprintf(const char* fmt, va_list va) { +IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN() char buf[4096]; vsprintf(buf, fmt, va); s_outstream << buf; +IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END() } #ifdef UNICODE diff --git a/test/output_xml_repeat_tests.cpp b/test/output_xml_repeat_tests.cpp index 7bae1ea50f..e31e0cbf47 100644 --- a/test/output_xml_repeat_tests.cpp +++ b/test/output_xml_repeat_tests.cpp @@ -2,11 +2,11 @@ //----------------------------------------------------------------------- /** * @file output_xml_repeat_tests.cpp - * @brief xml 出力対応テスト + * @brief Test output file name when repeating * * @author t.shirayanagi * @par copyright - * Copyright (C) 2016, Takazumi Shirayanagi\n + * Copyright (C) 2016-2020, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -59,12 +59,22 @@ int main(int argc, char* argv[]) #if OUTPUT_XML_TEST IUTEST_INIT(&argc, argv); - ::iutest::IUTEST_FLAG(output) = "xml:test_%d.xml"; if( ::iutest::IUTEST_FLAG(repeat) == 1 ) { ::iutest::IUTEST_FLAG(repeat) = 3; } - return IUTEST_RUN_ALL_TESTS(); + ::iutest::IUTEST_FLAG(output) = "xml:test_{I}.xml"; + if( IUTEST_RUN_ALL_TESTS() ) + { + return 1; + } + TestF::nI = 0; + ::iutest::IUTEST_FLAG(output) = "xml:test_%d.xml"; // deprecated format + if( IUTEST_RUN_ALL_TESTS() ) + { + return 1; + } + return 0; #else (void)argc; (void)argv; diff --git a/test/unit_string_tests.cpp b/test/unit_string_tests.cpp index 14ddc81caa..bcadc6cec1 100644 --- a/test/unit_string_tests.cpp +++ b/test/unit_string_tests.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2013-2019, Takazumi Shirayanagi\n + * Copyright (C) 2013-2020, Takazumi Shirayanagi\n * The new BSD License is applied to this software. * see LICENSE */ @@ -81,13 +81,27 @@ IUTEST(UnitStringTest, StringStrip) IUTEST_EXPECT_STREQ("a1 a2" , ::iutest::detail::StripSpace(str)); } -IUTEST(UnitStringTest, StringReplace) +IUTEST(UnitStringTest, StringReplaceChar) { ::std::string str = "a1a2a3a4b5"; ::iutest::detail::StringReplace(str, 'a', "ii"); IUTEST_EXPECT_STREQ("ii1ii2ii3ii4b5", str); } +IUTEST(UnitStringTest, StringReplaceString) +{ + { + ::std::string str = "a1a2a3a4b5"; + ::iutest::detail::StringReplace(str, "a1", 2, "ii"); + IUTEST_EXPECT_STREQ("iia2a3a4b5", str); + } + { + ::std::string str = "a1a2a3a4b5"; + ::iutest::detail::StringReplace(str, "a1", 1, "ii"); + IUTEST_EXPECT_STREQ("ii1a2a3a4b5", str); + } +} + IUTEST(UnitStringTest, StringReplaceToLF) { ::std::string str = "a\r\nb\r\rc\r\n\nd";