diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt b/clang-tools-extra/clangd/unittests/CMakeLists.txt --- a/clang-tools-extra/clangd/unittests/CMakeLists.txt +++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt @@ -63,6 +63,7 @@ IndexTests.cpp JSONTransportTests.cpp LSPClient.cpp + ModulesTests.cpp ParsedASTTests.cpp PathMappingTests.cpp PreambleTests.cpp diff --git a/clang-tools-extra/clangd/unittests/ModulesTests.cpp b/clang-tools-extra/clangd/unittests/ModulesTests.cpp new file mode 100644 --- /dev/null +++ b/clang-tools-extra/clangd/unittests/ModulesTests.cpp @@ -0,0 +1,45 @@ +//===-- ModulesTests.cpp ---------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Annotations.h" +#include "TestFS.h" +#include "TestTU.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include + +namespace clang { +namespace clangd { +namespace { + +TEST(Modules, TextualIncludeInPreamble) { + TestTU TU = TestTU::withCode(R"cpp( +#include "Textual.h" + +void foo() {} +)cpp"); + TU.ExtraArgs.push_back("-fmodules"); + TU.ExtraArgs.push_back("-fmodule-name=M"); + TU.ExtraArgs.push_back("-fmodule-map-file=m.modulemap"); + TU.AdditionalFiles["Textual.h"] = "void foo();"; + TU.AdditionalFiles["m.modulemap"] = R"modulemap( +module M { + module Textual { + textual header "Textual.h" + } +} +)modulemap"; + // Test that we do not crash. + TU.index(); +} + +} // namespace +} // namespace clangd +} // namespace clang