[llvm] 402f900 - [NFC][AsmWriter] Use HasSubstr in test

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 00:11:56 PST 2023


Author: Vitaly Buka
Date: 2023-01-11T00:11:32-08:00
New Revision: 402f90045c3c9a65fd842a2101bd3d9c4d654240

URL: https://github.com/llvm/llvm-project/commit/402f90045c3c9a65fd842a2101bd3d9c4d654240
DIFF: https://github.com/llvm/llvm-project/commit/402f90045c3c9a65fd842a2101bd3d9c4d654240.diff

LOG: [NFC][AsmWriter] Use HasSubstr in test

Added: 
    

Modified: 
    llvm/unittests/IR/AsmWriterTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/IR/AsmWriterTest.cpp b/llvm/unittests/IR/AsmWriterTest.cpp
index 04f977e0e402..3e0dad89b0c3 100644
--- a/llvm/unittests/IR/AsmWriterTest.cpp
+++ b/llvm/unittests/IR/AsmWriterTest.cpp
@@ -12,9 +12,11 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
+using ::testing::HasSubstr;
 
 namespace {
 
@@ -31,8 +33,8 @@ TEST(AsmWriterTest, DebugPrintDetachedInstruction) {
   std::string S;
   raw_string_ostream OS(S);
   Add->print(OS);
-  std::size_t r = OS.str().find("<badref> = add i32 poison, poison, !<empty");
-  EXPECT_TRUE(r != std::string::npos);
+  EXPECT_THAT(OS.str(),
+              HasSubstr("<badref> = add i32 poison, poison, !<empty"));
 }
 
 TEST(AsmWriterTest, DebugPrintDetachedArgument) {
@@ -78,8 +80,7 @@ TEST(AsmWriterTest, PrintAddrspaceWithNullOperand) {
   std::string S;
   raw_string_ostream OS(S);
   Call->print(OS);
-  std::size_t r = OS.str().find("<cannot get addrspace!>");
-  EXPECT_TRUE(r != std::string::npos);
+  EXPECT_THAT(OS.str(), HasSubstr("<cannot get addrspace!>"));
 }
 
 TEST(AsmWriterTest, PrintNullOperandBundle) {
@@ -102,6 +103,6 @@ TEST(AsmWriterTest, PrintNullOperandBundle) {
   std::string S;
   raw_string_ostream OS(S);
   Invoke->print(OS);
-  EXPECT_TRUE(OS.str().find("<null operand bundle!>") != std::string::npos);
+  EXPECT_THAT(OS.str(), HasSubstr("<null operand bundle!>"));
 }
 }


        


More information about the llvm-commits mailing list