Simplify methods for compilation failure in test framework.
authorLei Zhang <antiagainst@google.com>
Thu, 15 Oct 2015 19:20:45 +0000 (15:20 -0400)
committerDavid Neto <dneto@google.com>
Mon, 26 Oct 2015 16:55:33 +0000 (12:55 -0400)
Remove  CompileWithFormatFailure() and make CompileFailure() accept
a default argument.

test/TestFixture.h
test/TextToBinary.ControlFlow.cpp

index 714994d..8711e6e 100644 (file)
@@ -86,8 +86,9 @@ class TextToBinaryTestBase : public T {
 
   // Compiles SPIR-V text with the given format, asserting compilation failure.
   // Returns the error message(s).
-  std::string CompileWithFormatFailure(const std::string& text,
-                                       spv_assembly_syntax_format_t format) {
+  std::string CompileFailure(const std::string& text,
+                             spv_assembly_syntax_format_t format =
+                                 SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT) {
     EXPECT_NE(SPV_SUCCESS,
               spvTextWithFormatToBinary(text.c_str(), text.size(), format,
                                         opcodeTable, operandTable, extInstTable,
@@ -97,12 +98,6 @@ class TextToBinaryTestBase : public T {
     return diagnostic->error;
   }
 
-  // Compiles SPIR-V text using the default format, asserting compilation failure.
-  // Returns the error message(s).
-  std::string CompileFailure(const std::string& text) {
-    return CompileWithFormatFailure(text, SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT);
-  }
-
   // Encodes SPIR-V text into binary and then decodes the binary. Returns the
   // decoded text.
   std::string EncodeAndDecodeSuccessfully(const std::string& text) {
index 62bec7e..976bb1c 100644 (file)
@@ -176,10 +176,9 @@ TEST_F(TextToBinaryTest, SwitchBadInvalidLiteralCanonicalFormat) {
   const auto input = R"(OpTypeInt %i32 32 0
                         OpConstant %i32 %selector 42
                   OpSwitch %selector %default %abc)";
-  EXPECT_THAT(
-      CompileWithFormatFailure(input, SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL),
-      Eq("Expected <opcode> at the beginning of an instruction, found "
-         "'%abc'."));
+  EXPECT_THAT(CompileFailure(input, SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL),
+              Eq("Expected <opcode> at the beginning of an instruction, found "
+                 "'%abc'."));
 }
 
 TEST_F(TextToBinaryTest, SwitchBadMissingTarget) {
@@ -280,16 +279,15 @@ INSTANTIATE_TEST_CASE_P(
         MakeSwitchTestCase(48, 0, "0x800000000000", {0x00000000, 0x00008000},
                            "0x800000000000", {0x00000000, 0x00008000}),
         MakeSwitchTestCase(63, 0, "0x500000000", {0, 5}, "12", {12, 0}),
-        MakeSwitchTestCase(64, 0, "0x600000000", { 0, 6 }, "12", {12, 0}),
-        MakeSwitchTestCase(64, 1, "0x700000123", { 0x123, 7 }, "12", {12, 0}),
+        MakeSwitchTestCase(64, 0, "0x600000000", {0, 6}, "12", {12, 0}),
+        MakeSwitchTestCase(64, 1, "0x700000123", {0x123, 7}, "12", {12, 0}),
     })));
 
 using RoundTripTest =
     spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
 
 TEST_P(RoundTripTest, Sample) {
-  EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()),
-              Eq(GetParam()));
+  EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), Eq(GetParam()));
 }
 
 // TODO(dneto): Enable this test.