From 3e2aaea21848d2e91ed809851bc9c19152927a54 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 15 Aug 2023 21:50:16 +0100 Subject: [PATCH] Replace catch2 with google test --- CMakeLists.txt | 19 ++++++++-------- serene/CMakeLists.txt | 5 ++++ serene/src/jit/jit.cpp | 5 ++-- serene/src/jit/jit.h | 6 ++++- serene/tests/CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++ serene/tests/reader_tests.cpp | 23 +++++++++++++++++++ 6 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 serene/tests/CMakeLists.txt create mode 100644 serene/tests/reader_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a90c84c..ebdca62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ cmake_policy(SET CMP0116 OLD) # User Options # ============================================================================= option(CPP_20_SUPPORT "C++20 Support" ON) -option(SERENE_BUILD_TESTING "Enable tests" OFF) +option(SERENE_BUILD_TESTING "Enable tests" ON) option(SERENE_ENABLE_BUILDID "Enable build id." OFF) option(SERENE_ENABLE_THINLTO "Enable ThisLTO." ON) option(SERENE_ENABLE_DOCS "Enable document generation" OFF) @@ -132,15 +132,16 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) Include(FetchContent) if(SERENE_BUILD_TESTING) - message(STATUS "Fetching Catch2 v3...") - + message(STATUS "Fetching google test...") FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.0.0-preview4 - ) - FetchContent_MakeAvailable(Catch2) - list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz + DOWNLOAD_EXTRACT_TIMESTAMP ON + ) + + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) endif() # LLVM setup ================================================================== diff --git a/serene/CMakeLists.txt b/serene/CMakeLists.txt index aa0dc86..43cc701 100644 --- a/serene/CMakeLists.txt +++ b/serene/CMakeLists.txt @@ -134,3 +134,8 @@ install(TARGETS serene EXPORT SereneTargets add_subdirectory(src) add_subdirectory(include) + +if(SERENE_BUILD_TESTING) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/serene/src/jit/jit.cpp b/serene/src/jit/jit.cpp index 6006473..9b953da 100644 --- a/serene/src/jit/jit.cpp +++ b/serene/src/jit/jit.cpp @@ -19,6 +19,7 @@ #include "jit/jit.h" #include "options.h" // for Options +#include "source_mgr.h" #include <__type_traits/remove_reference.h> // for remov... #include <__utility/move.h> // for move @@ -130,9 +131,7 @@ size_t JIT::getNumberOfJITDylibs(const llvm::StringRef &nsName) { JIT::JIT(llvm::orc::JITTargetMachineBuilder &&jtmb, std::unique_ptr opts) - : - - options(std::move(opts)), + : options(std::move(opts)), cache(options->JITenableObjectCache ? new ObjectCache() : nullptr), gdbListener(options->JITenableGDBNotificationListener ? llvm::JITEventListener::createGDBRegistrationListener() diff --git a/serene/src/jit/jit.h b/serene/src/jit/jit.h index fac16d4..8821de6 100644 --- a/serene/src/jit/jit.h +++ b/serene/src/jit/jit.h @@ -27,6 +27,7 @@ #define JIT_JIT_H #include "options.h" +#include "source_mgr.h" #include <__memory/unique_ptr.h> @@ -60,7 +61,7 @@ class LLLazyJIT; } // namespace llvm::orc namespace serene { -class Namespace; +class SourceMgr; } // namespace serene #define MAIN_PROCESS_JD_NAME "*main*" @@ -109,6 +110,9 @@ class JIT { std::vector loadPaths; + // The source manager is the owner of all the sources and there can be + // just one source manager. + SourceMgr srcMgr; // We keep the jibDylibs for each name space in a mapping from the ns // name to a vector of jitdylibs, the last element is always the newest // jitDylib diff --git a/serene/tests/CMakeLists.txt b/serene/tests/CMakeLists.txt new file mode 100644 index 0000000..cb4b0c6 --- /dev/null +++ b/serene/tests/CMakeLists.txt @@ -0,0 +1,43 @@ +# Serene Programming Language +# +# Copyright (c) 2019-2023 Sameer Rahmani +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if(SERENE_BUILD_TESTING) + include(GoogleTest) + + + + + add_executable(serene_test + reader_tests.cpp + ) + + target_link_libraries(serene_test PRIVATE + GTest::gtest_main + LLVMSupport) + + target_include_directories(serene_test + SYSTEM PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ) + + target_include_directories(serene_test SYSTEM PUBLIC + # We don't want the generated files from table gen + # to be treated as local since the contain warnings + ${PROJECT_BINARY_DIR}/serene/include) + + gtest_discover_tests(serene_test) +endif() diff --git a/serene/tests/reader_tests.cpp b/serene/tests/reader_tests.cpp new file mode 100644 index 0000000..5152ba8 --- /dev/null +++ b/serene/tests/reader_tests.cpp @@ -0,0 +1,23 @@ +/* -*- C++ -*- + * Serene Programming Language + * + * Copyright (c) 2019-2023 Sameer Rahmani + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "reader.h" + +#include + +TEST(Reader, ReadNumber) { EXPECT_EQ(1, 1); }