Make test more lenient for custom clang version strings
[llvm-project.git] / mlir / unittests / Parser / ResourceTest.cpp
blobb93e7a6d6c16d3df5a2b40de6832d7930f036349
1 //===- ResourceTest.cpp -----------------------------------------*- C++ -*-===//
2 //
3 // This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "../../test/lib/Dialect/Test/TestAttributes.h"
10 #include "../../test/lib/Dialect/Test/TestDialect.h"
11 #include "mlir/Parser/Parser.h"
13 #include "gmock/gmock.h"
15 using namespace mlir;
17 namespace {
18 TEST(MLIRParser, ResourceKeyConflict) {
19 std::string moduleStr = R"mlir(
20 "test.use1"() {attr = #test.e1di64_elements<blob1> : tensor<3xi64> } : () -> ()
22 {-#
23 dialect_resources: {
24 test: {
25 blob1: "0x08000000010000000000000002000000000000000300000000000000"
28 #-}
29 )mlir";
30 std::string moduleStr2 = R"mlir(
31 "test.use2"() {attr = #test.e1di64_elements<blob1> : tensor<3xi64> } : () -> ()
33 {-#
34 dialect_resources: {
35 test: {
36 blob1: "0x08000000040000000000000005000000000000000600000000000000"
39 #-}
40 )mlir";
42 MLIRContext context;
43 context.loadDialect<test::TestDialect>();
45 // Parse both modules into the same context so that we ensure the conflicting
46 // resources have been loaded.
47 OwningOpRef<ModuleOp> module1 =
48 parseSourceString<ModuleOp>(moduleStr, &context);
49 OwningOpRef<ModuleOp> module2 =
50 parseSourceString<ModuleOp>(moduleStr2, &context);
51 ASSERT_TRUE(module1 && module2);
53 // Merge the two modules so that we can test printing the remapped resources.
54 Block *block = module1->getBody();
55 block->getOperations().splice(block->end(),
56 module2->getBody()->getOperations());
58 // Check that conflicting resources were remapped.
59 std::string outputStr;
61 llvm::raw_string_ostream os(outputStr);
62 module1->print(os);
64 StringRef output(outputStr);
65 EXPECT_TRUE(
66 output.contains("\"test.use1\"() {attr = #test.e1di64_elements<blob1>"));
67 EXPECT_TRUE(output.contains(
68 "blob1: \"0x08000000010000000000000002000000000000000300000000000000\""));
69 EXPECT_TRUE(output.contains(
70 "\"test.use2\"() {attr = #test.e1di64_elements<blob1_1>"));
71 EXPECT_TRUE(output.contains(
72 "blob1_1: "
73 "\"0x08000000040000000000000005000000000000000600000000000000\""));
75 } // namespace