1 //===- PassPipelineParserTest.cpp - Pass Parser unit tests ----------------===//
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
7 //===----------------------------------------------------------------------===//
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"
20 using namespace mlir::detail
;
23 TEST(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
) {
29 llvm::raw_string_ostream
os(errorMsg
);
30 FailureOr
<OpPassManager
> result
= parsePassPipeline(pipeline
, os
);
31 EXPECT_TRUE(failed(result
));
33 EXPECT_TRUE(StringRef(errorMsg
).contains(expectedErrorMsg
));
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
);