1//===- PassPipelineParserTest.cpp - Pass Parser unit tests ----------------===//
2//
3// Part of the LLVM Project, 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//===----------------------------------------------------------------------===//
8
9#include "mlir/IR/Builders.h"
10#include "mlir/IR/BuiltinOps.h"
11#include "mlir/Pass/Pass.h"
12#include "mlir/Pass/PassManager.h"
13#include "mlir/Pass/PassRegistry.h"
14#include "llvm/Support/raw_ostream.h"
15#include "gtest/gtest.h"
16
17#include <memory>
18
19using namespace mlir;
20using namespace mlir::detail;
21
22namespace {
23TEST(PassPipelineParserTest, InvalidOpAnchor) {
24 // Helper functor used to parse a pipeline and check that it results in the
25 // provided error message.
26 auto checkParseFailure = [](StringRef pipeline, StringRef expectedErrorMsg) {
27 std::string errorMsg;
28 {
29 llvm::raw_string_ostream os(errorMsg);
30 FailureOr<OpPassManager> result = parsePassPipeline(pipeline, errorStream&: os);
31 EXPECT_TRUE(failed(result));
32 }
33 EXPECT_TRUE(StringRef(errorMsg).contains(expectedErrorMsg));
34 };
35
36 // Handle parse errors when the anchor is incorrectly structured.
37 StringRef anchorErrorMsg =
38 "expected pass pipeline to be wrapped with the anchor operation type";
39 checkParseFailure("module", anchorErrorMsg);
40 checkParseFailure("()", anchorErrorMsg);
41 checkParseFailure("module(", anchorErrorMsg);
42 checkParseFailure("module)", anchorErrorMsg);
43}
44
45} // namespace
46

source code of mlir/unittests/Pass/PassPipelineParserTest.cpp