1 //===- DialectTest.cpp - Dialect 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/Dialect.h" 10 #include "gtest/gtest.h" 11 12 using namespace mlir; 13 using namespace mlir::detail; 14 15 namespace { 16 struct TestDialect : public Dialect { 17 static StringRef getDialectNamespace() { return "test"; }; 18 TestDialect(MLIRContext *context) 19 : Dialect(getDialectNamespace(), context, TypeID::get<TestDialect>()) {} 20 }; 21 struct AnotherTestDialect : public Dialect { 22 static StringRef getDialectNamespace() { return "test"; }; 23 AnotherTestDialect(MLIRContext *context) 24 : Dialect(getDialectNamespace(), context, 25 TypeID::get<AnotherTestDialect>()) {} 26 }; 27 28 TEST(DialectDeathTest, MultipleDialectsWithSameNamespace) { 29 MLIRContext context; 30 31 // Registering a dialect with the same namespace twice should result in a 32 // failure. 33 context.getOrCreateDialect<TestDialect>(); 34 ASSERT_DEATH(context.getOrCreateDialect<AnotherTestDialect>(), ""); 35 } 36 37 } // end namespace 38