Guard ASSERT_THROWS checks with BENCHMARK_HAS_NO_EXCEPTIONS (#874)

* Guard ASSERT_THROWS checks with BENCHMARK_HAS_NO_EXCEPTIONS

This allows the test be run with exceptions turned off

* Add myself to CONTRIBUTORS

I don't need to be added to AUTHORS, as I am a Google employee
This commit is contained in:
Geoffrey Martin-Noble 2019-09-20 02:25:31 -07:00 committed by Dominic Hamon
parent bf4f2ea0bd
commit d2fc7fe659
2 changed files with 8 additions and 0 deletions

View File

@ -41,6 +41,7 @@ Eugene Zhuk <eugene.zhuk@gmail.com>
Evgeny Safronov <division494@gmail.com>
Federico Ficarelli <federico.ficarelli@gmail.com>
Felix Homann <linuxaudio@showlabor.de>
Geoffrey Martin-Noble <gcmn@google.com> <gmngeoffrey@gmail.com>
Hannes Hauswedell <h2@fsfe.org>
Ismael Jimenez Martinez <ismael.jimenez.martinez@gmail.com>
Jern-Kuan Leong <jernkuan@gmail.com>

View File

@ -3,6 +3,7 @@
//===---------------------------------------------------------------------===//
#include "../src/string_util.h"
#include "../src/internal_macros.h"
#include "gtest/gtest.h"
namespace {
@ -60,9 +61,11 @@ TEST(StringUtilTest, stoul) {
EXPECT_EQ(0xBEEFul, benchmark::stoul("BEEF", &pos, 16));
EXPECT_EQ(4ul, pos);
}
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
{
ASSERT_THROW(benchmark::stoul("this is a test"), std::invalid_argument);
}
#endif
}
TEST(StringUtilTest, stoi) {
@ -106,9 +109,11 @@ TEST(StringUtilTest, stoi) {
EXPECT_EQ(0xBEEF, benchmark::stoi("BEEF", &pos, 16));
EXPECT_EQ(4ul, pos);
}
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
{
ASSERT_THROW(benchmark::stoi("this is a test"), std::invalid_argument);
}
#endif
}
TEST(StringUtilTest, stod) {
@ -138,9 +143,11 @@ TEST(StringUtilTest, stod) {
EXPECT_EQ(-1.25e+9, benchmark::stod("-1.25e+9", &pos));
EXPECT_EQ(8ul, pos);
}
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
{
ASSERT_THROW(benchmark::stod("this is a test"), std::invalid_argument);
}
#endif
}
} // end namespace