55#include < stdexcept>
66#include < string>
77
8+ #include < gmock/gmock.h>
89#include < gtest/gtest.h>
910
1011namespace colmap {
@@ -20,13 +21,14 @@ TEST(CudaSafeCall, InsufficientDriver) {
2021 FAIL () << " Expected a runtime error" ;
2122 } catch (const std::invalid_argument& error) {
2223 const std::string message = error.what ();
23- EXPECT_NE (message.find (" probe.cc:42" ), std::string::npos);
24- EXPECT_NE (message.find (" error " + std::to_string (static_cast <int >(
25- cudaErrorInsufficientDriver))),
26- std::string::npos);
27- EXPECT_NE (message.find (" driver" ), std::string::npos);
28- EXPECT_NE (message.find (" COLMAP build" ), std::string::npos);
29- EXPECT_EQ (message.find (" (null)" ), std::string::npos);
24+ EXPECT_THAT (message, testing::HasSubstr (" probe.cc:42" ));
25+ EXPECT_THAT (
26+ message,
27+ testing::HasSubstr (" error " + std::to_string (static_cast <int >(
28+ cudaErrorInsufficientDriver))));
29+ EXPECT_THAT (message, testing::HasSubstr (" driver" ));
30+ EXPECT_THAT (message, testing::HasSubstr (" COLMAP build" ));
31+ EXPECT_THAT (message, testing::Not (testing::HasSubstr (" (null)" )));
3032 }
3133}
3234
@@ -36,10 +38,11 @@ TEST(CudaSafeCall, UnknownErrorPreservesCode) {
3638 FAIL () << " Expected a runtime error" ;
3739 } catch (const std::invalid_argument& error) {
3840 const std::string message = error.what ();
39- EXPECT_NE (message.find (" 123456" ), std::string::npos);
40- EXPECT_NE (message.find (" probe.cc:7" ), std::string::npos);
41- EXPECT_EQ (message.find (" (null)" ), std::string::npos);
42- EXPECT_EQ (message.find (" Update the NVIDIA driver" ), std::string::npos);
41+ EXPECT_THAT (message, testing::HasSubstr (" 123456" ));
42+ EXPECT_THAT (message, testing::HasSubstr (" probe.cc:7" ));
43+ EXPECT_THAT (message, testing::Not (testing::HasSubstr (" (null)" )));
44+ EXPECT_THAT (message,
45+ testing::Not (testing::HasSubstr (" Update the NVIDIA driver" )));
4346 }
4447}
4548
0 commit comments