mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[unittests] Add a fixture for Sema unit tests
This commit is contained in:
@@ -12,6 +12,7 @@ if(SWIFT_INCLUDE_TOOLS)
|
||||
add_subdirectory(Localization)
|
||||
add_subdirectory(IDE)
|
||||
add_subdirectory(Parse)
|
||||
add_subdirectory(Sema)
|
||||
add_subdirectory(SwiftDemangle)
|
||||
add_subdirectory(Syntax)
|
||||
if(SWIFT_BUILD_SYNTAXPARSERLIB)
|
||||
|
||||
7
unittests/Sema/CMakeLists.txt
Normal file
7
unittests/Sema/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
add_swift_unittest(swiftSemaTests
|
||||
SemaFixture.cpp)
|
||||
|
||||
target_link_libraries(swiftSemaTests
|
||||
PRIVATE
|
||||
swiftSema)
|
||||
36
unittests/Sema/SemaFixture.cpp
Normal file
36
unittests/Sema/SemaFixture.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
//===--- SemaFixture.cpp - Helper for setting up Sema context --------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "SemaFixture.h"
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/ParseRequests.h"
|
||||
#include "swift/Strings.h"
|
||||
#include "swift/Subsystems.h"
|
||||
|
||||
using namespace swift;
|
||||
using namespace swift::unittest;
|
||||
|
||||
SemaTest::SemaTest()
|
||||
: Context(*ASTContext::get(LangOpts, TypeCheckerOpts, SearchPathOpts,
|
||||
ClangImporterOpts, SourceMgr, Diags)) {
|
||||
registerParseRequestFunctions(Context.evaluator);
|
||||
registerTypeCheckerRequestFunctions(Context.evaluator);
|
||||
auto stdlibID = Context.getIdentifier(STDLIB_NAME);
|
||||
auto *module = ModuleDecl::create(stdlibID, Context);
|
||||
Context.addLoadedModule(module);
|
||||
|
||||
FileForLookups = new (Context) SourceFile(*module, SourceFileKind::Library,
|
||||
/*buffer*/ None);
|
||||
module->addFile(*FileForLookups);
|
||||
|
||||
DC = module;
|
||||
}
|
||||
51
unittests/Sema/SemaFixture.h
Normal file
51
unittests/Sema/SemaFixture.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//===--- SemaFixture.h - Helper for setting up Sema context -----*- C++ -*-===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/DiagnosticEngine.h"
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/SourceFile.h"
|
||||
#include "swift/Basic/LangOptions.h"
|
||||
#include "swift/Basic/SourceManager.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace swift {
|
||||
namespace unittest {
|
||||
|
||||
class SemaTestBase : public ::testing::Test {
|
||||
public:
|
||||
LangOptions LangOpts;
|
||||
TypeCheckerOptions TypeCheckerOpts;
|
||||
SearchPathOptions SearchPathOpts;
|
||||
ClangImporterOptions ClangImporterOpts;
|
||||
SourceManager SourceMgr;
|
||||
DiagnosticEngine Diags;
|
||||
|
||||
SemaTestBase() : Diags(SourceMgr) {
|
||||
LangOpts.Target = llvm::Triple(llvm::sys::getProcessTriple());
|
||||
}
|
||||
};
|
||||
|
||||
/// Owns an ASTContext and the associated types.
|
||||
class SemaTest : public SemaTestBase {
|
||||
SourceFile *FileForLookups;
|
||||
|
||||
public:
|
||||
ASTContext &Context;
|
||||
DeclContext *DC;
|
||||
|
||||
SemaTest();
|
||||
};
|
||||
|
||||
} // end namespace unittest
|
||||
} // end namespace swift
|
||||
Reference in New Issue
Block a user