From bbdf5c44915655dd9f046c8f0641226598ef4808 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 19 Feb 2022 14:54:51 +0000 Subject: [PATCH] Disable the test cases of libserene and prepare them for refactoring --- libserene/tests/CMakeLists.txt | 23 ++++---- libserene/tests/context_tests.cpp.inc | 62 +++++++++++---------- libserene/tests/environment_tests.cpp.inc | 2 +- libserene/tests/errors/error_tests.cpp.inc | 2 +- libserene/tests/exprs/list_tests.cpp.inc | 2 +- libserene/tests/exprs/number_tests.cpp.inc | 2 +- libserene/tests/namespace_tests.cpp.inc | 2 +- libserene/tests/reader/reader_tests.cpp.inc | 2 +- libserene/tests/serenetests.cpp | 24 ++++---- libserene/tests/test_helpers.cpp.inc | 20 ++++--- libserene/tests/traits_tests.cpp.inc | 2 +- 11 files changed, 74 insertions(+), 69 deletions(-) diff --git a/libserene/tests/CMakeLists.txt b/libserene/tests/CMakeLists.txt index 021552d..d483cdf 100644 --- a/libserene/tests/CMakeLists.txt +++ b/libserene/tests/CMakeLists.txt @@ -1,11 +1,13 @@ # Catch2 should be installed system wide -find_package(Catch2 REQUIRED) +#find_package(Catch2 3 REQUIRED) # Tests need to be added as executables first -add_executable(tests serenetests.cpp) -add_dependencies(tests SereneDialectGen) -add_dependencies(tests serene) -target_link_libraries(tests PRIVATE +add_executable(libsereneTests serenetests.cpp) + +add_dependencies(libsereneTests SereneDialectGen) +add_dependencies(libsereneTests serene) + +target_link_libraries(libsereneTests PRIVATE serene ${llvm_libs} MLIRAnalysis @@ -13,18 +15,15 @@ target_link_libraries(tests PRIVATE MLIRParser MLIRSideEffectInterfaces MLIRTransforms + + Catch2::Catch2WithMain ) -target_compile_features(tests PRIVATE cxx_std_17) +target_compile_features(libsereneTests PRIVATE cxx_std_17) -# Should be linked to the main library, as well as the Catch2 testing library -target_link_libraries(tests PUBLIC serene Catch2::Catch2) # target_include_directories(serene SYSTEM PRIVATE $ENV{INCLUDE}) # target_include_directories(serene PUBLIC ${INCLUDE_DIR}) -# If you register a test, then ctest and make test will run it. -# You can also run examples and check the output, as well. -# add_test(NAME testlibtest serene testlib) # Command can be a target include(CTest) include(Catch) -catch_discover_tests(tests) +catch_discover_tests(libsereneTests) diff --git a/libserene/tests/context_tests.cpp.inc b/libserene/tests/context_tests.cpp.inc index 7705b0c..a99b1f4 100644 --- a/libserene/tests/context_tests.cpp.inc +++ b/libserene/tests/context_tests.cpp.inc @@ -24,54 +24,56 @@ #include "serene/context.h" #include "serene/namespace.h" +#include "serene/serene.h" #include "./test_helpers.cpp.inc" -#include +#include namespace serene { TEST_CASE("Context tests", "[context]") { + initCompiler(); auto ctx = makeSereneContext(); - auto ns = ctx->getNS("blah"); + auto *ns = ctx->getNS("blah"); REQUIRE_FALSE(ns); - auto userNs = makeNamespace(*ctx, "user", - llvm::Optional("/some/file")); + SECTION("blah") { + auto userNs = ctx->makeNamespace( + "user", llvm::Optional("/some/file")); - CHECK(userNs->name == "user"); - REQUIRE(userNs->filename); - CHECK(userNs->filename.getValue() == "/some/file"); + CHECK(userNs->name == "user"); + REQUIRE(userNs->filename); + CHECK(userNs->filename.getValue() == "/some/file"); - ns = ctx->getNS("user"); + ns = ctx->getNS("user"); - REQUIRE(ns); - CHECK(ns->name == userNs->name); + REQUIRE(ns); + CHECK(ns->name == userNs->name); - /// Creating new ns with the same name overrides the old one - auto userNs1 = makeNamespace( - *ctx, "user", llvm::Optional("/some/other/file")); + /// Creating new ns with the same name overrides the old one + auto userNs1 = ctx->makeNamespace( + "user", llvm::Optional("/some/other/file")); - ns = ctx->getNS("user"); + ns = ctx->getNS("user"); - REQUIRE(ns); - CHECK(ns->name == userNs1->name); - REQUIRE(ns->filename); - CHECK(ns->filename.getValue() == "/some/other/file"); + REQUIRE(ns); + CHECK(ns->name == userNs1->name); + REQUIRE(ns->filename); + CHECK(ns->filename.getValue() == "/some/other/file"); + } }; -TEST_CASE("Get and Set current namespace", "[context]") { - auto ctx = makeSereneContext(); - auto userNs = makeNamespace(*ctx, "user", - llvm::Optional("/some/file")); +TEST_CASE( + "withCurrentNS run a function with the given namespace as the current NS", + "[context]") { + auto ctx = makeSereneContext(); + auto userNs = + ctx->makeNamespace("user", llvm::Optional("/some/file")); - auto isSet = ctx->setCurrentNS("user"); - - REQUIRE(isSet); - CHECK(ctx->getCurrentNS() == userNs); - - isSet = ctx->setCurrentNS("user1"); - REQUIRE_FALSE(isSet); - CHECK(ctx->getCurrentNS() == userNs); + ctx->withCurrentNS("user", [&]() -> int { + CHECK(ctx->getCurrentNS().name == userNs->name); + return 0; + }); }; } // namespace serene diff --git a/libserene/tests/environment_tests.cpp.inc b/libserene/tests/environment_tests.cpp.inc index d63244b..0839b4b 100644 --- a/libserene/tests/environment_tests.cpp.inc +++ b/libserene/tests/environment_tests.cpp.inc @@ -27,7 +27,7 @@ #include "serene/exprs/symbol.h" #include "./test_helpers.cpp.inc" -#include +#include #include diff --git a/libserene/tests/errors/error_tests.cpp.inc b/libserene/tests/errors/error_tests.cpp.inc index c5e1b13..bbb2828 100644 --- a/libserene/tests/errors/error_tests.cpp.inc +++ b/libserene/tests/errors/error_tests.cpp.inc @@ -26,7 +26,7 @@ #include "serene/exprs/symbol.h" #include "../test_helpers.cpp.inc" -#include +#include #include diff --git a/libserene/tests/exprs/list_tests.cpp.inc b/libserene/tests/exprs/list_tests.cpp.inc index 59366c6..d52fa62 100644 --- a/libserene/tests/exprs/list_tests.cpp.inc +++ b/libserene/tests/exprs/list_tests.cpp.inc @@ -30,7 +30,7 @@ #include "serene/reader/semantics.h" #include "../test_helpers.cpp.inc" -#include +#include namespace serene { namespace exprs { diff --git a/libserene/tests/exprs/number_tests.cpp.inc b/libserene/tests/exprs/number_tests.cpp.inc index bc15b0b..5ff3cfd 100644 --- a/libserene/tests/exprs/number_tests.cpp.inc +++ b/libserene/tests/exprs/number_tests.cpp.inc @@ -25,7 +25,7 @@ #include "serene/exprs/number.h" #include "../test_helpers.cpp.inc" -#include +#include namespace serene { namespace exprs { diff --git a/libserene/tests/namespace_tests.cpp.inc b/libserene/tests/namespace_tests.cpp.inc index 64b9ad0..fbdcb41 100644 --- a/libserene/tests/namespace_tests.cpp.inc +++ b/libserene/tests/namespace_tests.cpp.inc @@ -28,7 +28,7 @@ #include "serene/reader/reader.h" #include "./test_helpers.cpp.inc" -#include +#include namespace serene { diff --git a/libserene/tests/reader/reader_tests.cpp.inc b/libserene/tests/reader/reader_tests.cpp.inc index e558498..676aec2 100644 --- a/libserene/tests/reader/reader_tests.cpp.inc +++ b/libserene/tests/reader/reader_tests.cpp.inc @@ -25,7 +25,7 @@ #include "serene/reader/reader.h" #include "../test_helpers.cpp.inc" -#include +#include namespace serene { namespace reader { diff --git a/libserene/tests/serenetests.cpp b/libserene/tests/serenetests.cpp index 3c286f7..7c638b0 100644 --- a/libserene/tests/serenetests.cpp +++ b/libserene/tests/serenetests.cpp @@ -17,15 +17,17 @@ */ #define CATCH_CONFIG_MAIN + #include "./context_tests.cpp.inc" -#include "./environment_tests.cpp.inc" -#include "./errors/error_tests.cpp.inc" -#include "./exprs/expression_tests.cpp.inc" -#include "./exprs/list_tests.cpp.inc" -#include "./exprs/number_tests.cpp.inc" -#include "./exprs/symbol_tests.cpp.inc" -#include "./namespace_tests.cpp.inc" -#include "./reader/reader_tests.cpp.inc" -#include "./traits_tests.cpp.inc" -#include "./utils_tests.cpp.inc" -#include +//#include "./environment_tests.cpp.inc" +// #include "./errors/error_tests.cpp.inc" +// #include "./exprs/expression_tests.cpp.inc" +// #include "./exprs/list_tests.cpp.inc" +// #include "./exprs/number_tests.cpp.inc" +// #include "./exprs/symbol_tests.cpp.inc" +// #include "./namespace_tests.cpp.inc" +// #include "./reader/reader_tests.cpp.inc" +// #include "./traits_tests.cpp.inc" +// #include "./utils_tests.cpp.inc" +// include +#include diff --git a/libserene/tests/test_helpers.cpp.inc b/libserene/tests/test_helpers.cpp.inc index 344dfa7..a693d56 100644 --- a/libserene/tests/test_helpers.cpp.inc +++ b/libserene/tests/test_helpers.cpp.inc @@ -27,21 +27,23 @@ #include "serene/reader/location.h" -#include +#include namespace serene { reader::LocationRange *dummyLocation() { - reader::Location start; - reader::Location end; + reader::Location start("serene.test.ns"); + reader::Location end("serene.test.ns"); - start.line = 2; - start.col = 20; - start.pos = 40; + constexpr const int line1 = 2; + constexpr const int line2 = 3; + constexpr const int col1 = 20; + constexpr const int col2 = 30; - end.line = 3; - end.col = 30; - end.pos = 80; + start.line = line1; + start.col = col1; + end.line = line2; + end.col = col2; return new reader::LocationRange(start, end); }; diff --git a/libserene/tests/traits_tests.cpp.inc b/libserene/tests/traits_tests.cpp.inc index 2a7a842..62f8e38 100644 --- a/libserene/tests/traits_tests.cpp.inc +++ b/libserene/tests/traits_tests.cpp.inc @@ -25,7 +25,7 @@ #include "serene/traits.h" #include "./test_helpers.cpp.inc" -#include +#include namespace serene {