• R/O
  • SSH
  • HTTPS

iutest: Commit


Commit MetaInfo

Revision1412 (tree)
Zeit2020-06-09 14:01:10
Autorsrz_zumix

Log Message

Merge remote-tracking branch 'origin/develop'

git@40b817af8fa9358806d6de8e1025e12a3abe9187
https://github.com/srz-zumix/iutest/commit/40b817af8fa9358806d6de8e1025e12a3abe9187


Merge remote-tracking branch 'origin/develop'

git@b4924b2db37287c8574b14f30284b223943f7ae2


[LGTM.com] suppress alert (#461)

* suppress alert

* fix
git@b65692ddb6bc17f4fe6637a460febe5381801bef

Ändern Zusammenfassung

Diff

--- trunk/appveyor.yml (revision 1411)
+++ trunk/appveyor.yml (revision 1412)
@@ -94,6 +94,7 @@
9494 - .bandit
9595 - .editorconfig
9696 - .hadolint.yaml
97+ - .lgtm.yaml
9798 - tox.ini
9899 - azure-pipelines.yml
99100 - bitrise.yml
--- trunk/azure-pipelines.yml (revision 1411)
+++ trunk/azure-pipelines.yml (revision 1412)
@@ -13,6 +13,7 @@
1313 - .bandit
1414 - .editorconfig
1515 - .hadolint.yaml
16+ - .lgtm.yaml
1617 - tox.ini
1718 - appveyor.yml
1819 - bitrise.yml
--- trunk/include/internal/iutest_debug.hpp (revision 1411)
+++ trunk/include/internal/iutest_debug.hpp (revision 1412)
@@ -19,10 +19,10 @@
1919 // iutest 自体のデバッグ用定義
2020
2121 #if defined(_MSC_VER) && !defined(IUTEST_OS_WINDOWS_MOBILE)
22-# include <streambuf>
2322 # include <crtdbg.h>
2423 # include <xlocnum>
2524 # include <xtree>
25+# include <streambuf>
2626 # ifndef _DEBUG_NEW_
2727 # define _DEBUG_NEW_ new ( _NORMAL_BLOCK , __FILE__, __LINE__)
2828 # pragma push_macro("new")
--- trunk/include/internal/iutest_exception.hpp (revision 1411)
+++ trunk/include/internal/iutest_exception.hpp (revision 1412)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2019, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2020, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -20,7 +20,6 @@
2020
2121 #if IUTEST_HAS_EXCEPTIONS
2222 #include <exception>
23-//#include <stdexcept> // ::std::invalid_argment
2423
2524 namespace iutest {
2625 namespace detail
--- trunk/include/internal/iutest_genparams_from_file.hpp (revision 1411)
+++ trunk/include/internal/iutest_genparams_from_file.hpp (revision 1412)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2015-2018, Takazumi Shirayanagi\n
9+ * Copyright (C) 2015-2020, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -41,17 +41,6 @@
4141 }
4242
4343 private:
44- bool ToParam(const ::std::string& data, T& param)
45- {
46- ::std::istringstream strm(data);
47- if( strm >> param )
48- {
49- return true;
50- }
51- return false;
52- }
53-
54-private:
5544 void AppendParams(params_t& params, const ::std::string& data)
5645 {
5746 if( StringIsBlank(data) )
@@ -59,7 +48,7 @@
5948 return;
6049 }
6150 T param;
62- if( !ToParam(data, param) )
51+ if( !StringToValue(data, param) )
6352 {
6453 return;
6554 }
@@ -97,22 +86,6 @@
9786 }
9887 };
9988
100-template<>inline bool iuCsvFileParamsGenerator<float>::ToParam(const ::std::string& data, float& param)
101-{
102-#if IUTEST_HAS_STD_STR_TO_VALUE
103- param = ::std::stof(data);
104- return true;
105-#else
106- ::std::istringstream strm(data);
107- if( !(strm >> param) )
108- {
109- param = static_cast<float>(atof(data.c_str()));
110- }
111- return true;
112-#endif
113-}
114-
115-
11689 } // end of namespace detail
11790 } // end of namespace iutest
11891
--- trunk/include/internal/iutest_string_stream.hpp (revision 1411)
+++ trunk/include/internal/iutest_string_stream.hpp (revision 1412)
@@ -26,6 +26,9 @@
2626 #if IUTEST_HAS_IOMANIP
2727 # include <iomanip>
2828 #endif
29+#if IUTEST_HAS_EXCEPTIONS
30+# include <stdexcept>
31+#endif
2932
3033 namespace iutest
3134 {
@@ -33,6 +36,97 @@
3336 namespace detail
3437 {
3538
39+template<typename T>
40+bool StringToValue(const ::std::string& s, T& out)
41+{
42+ ::std::istringstream strm(s);
43+ if( strm >> out )
44+ {
45+ return true;
46+ }
47+ return false;
48+}
49+
50+inline bool StringToValue(const ::std::string& s, float& out)
51+{
52+#if IUTEST_HAS_STD_STR_TO_VALUE
53+ out = ::std::stof(s);
54+#else
55+ char* endptr=NULL;
56+ const char* p = s.c_str();
57+ errno = 0;
58+#if !defined(IUTEST_OS_WINDOWS_MINGW) || !defined(__STRICT_ANSI__)
59+ const floating_point<float> v = strtof(p, &endptr);
60+#else
61+ const floating_point<float> v = static_cast<float>(strtod(p, &endptr));
62+#endif
63+#if IUTEST_HAS_EXCEPTIONS
64+ if(p == endptr)
65+ {
66+ throw ::std::invalid_argument(p);
67+ }
68+ if((errno == ERANGE) || v.is_inf() )
69+ {
70+ throw ::std::out_of_range(p);
71+ }
72+#endif
73+ out = v;
74+#endif
75+ return true;
76+}
77+
78+inline bool StringToValue(const ::std::string& s, double& out)
79+{
80+#if IUTEST_HAS_STD_STR_TO_VALUE
81+ out = ::std::stod(s);
82+#else
83+ char* endptr=NULL;
84+ const char* p = s.c_str();
85+ errno = 0;
86+ const floating_point<double> v = strtod(s.c_str(), &endptr);
87+#if IUTEST_HAS_EXCEPTIONS
88+ if(p == endptr)
89+ {
90+ throw ::std::invalid_argument(p);
91+ }
92+ if((errno == ERANGE) || v.is_inf() )
93+ {
94+ throw ::std::out_of_range(p);
95+ }
96+#endif
97+ out = v;
98+#endif
99+ return true;
100+}
101+
102+#if IUTEST_HAS_LONG_DOUBLE
103+
104+inline bool StringToValue(const ::std::string& s, long double& out)
105+{
106+#if IUTEST_HAS_STD_STR_TO_VALUE
107+ out = ::std::stold(s);
108+#else
109+ char* endptr=NULL;
110+ const char* p = s.c_str();
111+ errno = 0;
112+ const floating_point<long double> v = strtold(s.c_str(), &endptr);
113+#if IUTEST_HAS_EXCEPTIONS
114+ if(p == endptr)
115+ {
116+ throw ::std::invalid_argument(p);
117+ }
118+ if((errno == ERANGE) || v.is_inf() )
119+ {
120+ throw ::std::out_of_range(p);
121+ }
122+#endif
123+ out = v;
124+#endif
125+ return true;
126+}
127+
128+#endif
129+
36130 #if !IUTEST_HAS_STRINGSTREAM && !IUTEST_HAS_STRSTREAM
37131
38132 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
--- trunk/include/iutest_assertion.hpp (revision 1411)
+++ trunk/include/iutest_assertion.hpp (revision 1412)
@@ -326,7 +326,7 @@
326326 #if IUTEST_HAS_ASSERTION_RETURN
327327 /** @private */
328328 template<typename R>
329- R operator = (const ReturnTypedFixed<R>& fixed)
329+ R operator = (const ReturnTypedFixed<R>& fixed) // lgtm [cpp/assignment-does-not-return-this]
330330 {
331331 this->operator=(fixed.fixed);
332332 return fixed.ret.value;
--- trunk/include/iutest_defs.hpp (revision 1411)
+++ trunk/include/iutest_defs.hpp (revision 1412)
@@ -306,6 +306,11 @@
306306 */
307307 bool is_nan() const { return exponent_bits() == kExpMask && fraction_bits() != 0; }
308308
309+ /**
310+ * @brief is inf
311+ */
312+ bool is_inf() const { return exponent_bits() == kExpMask && fraction_bits() == 0; }
313+
309314 public:
310315 //! plus inf
311316 static _Myt PINF()
--- trunk/include/iutest_result.hpp (revision 1411)
+++ trunk/include/iutest_result.hpp (revision 1412)
@@ -75,9 +75,6 @@
7575 */
7676 TestPartResult(const char* file, int line, const char* message, Type type)
7777 : detail::iuCodeMessage(file, line, message), m_type(type) {}
78- //! コピーコンストラクタ
79- TestPartResult(const TestPartResult& rhs) : detail::iuCodeMessage(rhs)
80- , m_type(rhs.m_type) {}
8178
8279 public:
8380 /**
--- trunk/include/util/iutest_util_menu.hpp (revision 1411)
+++ trunk/include/util/iutest_util_menu.hpp (revision 1412)
@@ -20,8 +20,8 @@
2020 #include "iutest_util_tests.hpp"
2121
2222 #if defined(IUTEST_OS_WINDOWS)
23+#include <windows.h>
2324 #include <map>
24-#include <windows.h>
2525
2626 namespace iuutil
2727 {
--- trunk/test/unit_string_tests.cpp (revision 1411)
+++ trunk/test/unit_string_tests.cpp (revision 1412)
@@ -241,3 +241,62 @@
241241 memcpy(expect, uexpect, sizeof(expect));
242242 IUTEST_EXPECT_EQ_RANGE(expect, s);
243243 }
244+
245+IUTEST(UnitStringTest, StringToValue)
246+{
247+ {
248+ float f;
249+ IUTEST_EXPECT_TRUE(::iutest::detail::StringToValue("1.0", f));
250+ IUTEST_EXPECT_FLOAT_EQ(1.0f, f);
251+ }
252+ {
253+ double f;
254+ IUTEST_EXPECT_TRUE(::iutest::detail::StringToValue("1.0", f));
255+ IUTEST_EXPECT_DOUBLE_EQ(1.0, f);
256+ }
257+#if IUTEST_HAS_LONG_DOUBLE
258+ {
259+ long double f;
260+ IUTEST_EXPECT_TRUE(::iutest::detail::StringToValue("1.0", f));
261+ IUTEST_EXPECT_DOUBLE_EQ(1.0, f);
262+ }
263+#endif
264+}
265+
266+#if IUTEST_HAS_EXCEPTIONS
267+IUTEST(UnitStringTest, StringToValueException)
268+{
269+ {
270+ float f = -10.0f;
271+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("ABC", f), ::std::invalid_argument);
272+ IUTEST_EXPECT_FLOAT_EQ(-10.0f, f);
273+ }
274+ {
275+ float f = -10.0f;
276+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("123456789e1000", f), ::std::out_of_range);
277+ IUTEST_EXPECT_FLOAT_EQ(-10.0f, f);
278+ }
279+ {
280+ float f = -10.0;
281+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("ABC", f), ::std::invalid_argument);
282+ IUTEST_EXPECT_DOUBLE_EQ(-10.0, f);
283+ }
284+ {
285+ float f = -10.0;
286+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("123456789e1000", f), ::std::out_of_range);
287+ IUTEST_EXPECT_DOUBLE_EQ(-10.0, f);
288+ }
289+#if IUTEST_HAS_LONG_DOUBLE
290+ {
291+ long double f = -10.0;
292+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("ABC", f), ::std::invalid_argument);
293+ IUTEST_EXPECT_LONG_DOUBLE_EQ(-10.0, f);
294+ }
295+ {
296+ long double f = -10.0;
297+ IUTEST_EXPECT_THROW(::iutest::detail::StringToValue("123456789e1000000", f), ::std::out_of_range);
298+ IUTEST_EXPECT_LONG_DOUBLE_EQ(-10.0, f);
299+ }
300+#endif
301+}
302+#endif
--- trunk/tools/wandbox/wandbox.py (revision 1411)
+++ trunk/tools/wandbox/wandbox.py (revision 1412)
@@ -180,7 +180,7 @@
180180 if is_retry(e) and retries > 0:
181181 try:
182182 print(e.message)
183- except:
183+ except Exception:
184184 pass
185185 print('wait {0}sec...'.format(retry_wait))
186186 sleep(retry_wait)
@@ -187,7 +187,7 @@
187187 return Wandbox.Call(action, retries, retry_wait)
188188 else:
189189 raise
190- except:
190+ except Exception:
191191 raise
192192
193193
Show on old repository browser