Disable the test cases of libserene and prepare them for refactoring

This commit is contained in:
Sameer Rahmani 2022-02-19 14:54:51 +00:00
parent 8dde04d6ce
commit bbdf5c4491
11 changed files with 74 additions and 69 deletions

View File

@ -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)

View File

@ -24,54 +24,56 @@
#include "serene/context.h"
#include "serene/namespace.h"
#include "serene/serene.h"
#include "./test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
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<llvm::StringRef>("/some/file"));
SECTION("blah") {
auto userNs = ctx->makeNamespace(
"user", llvm::Optional<llvm::StringRef>("/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<llvm::StringRef>("/some/other/file"));
/// Creating new ns with the same name overrides the old one
auto userNs1 = ctx->makeNamespace(
"user", llvm::Optional<llvm::StringRef>("/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<llvm::StringRef>("/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<llvm::StringRef>("/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<int>("user", [&]() -> int {
CHECK(ctx->getCurrentNS().name == userNs->name);
return 0;
});
};
} // namespace serene

View File

@ -27,7 +27,7 @@
#include "serene/exprs/symbol.h"
#include "./test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <llvm/ADT/StringRef.h>

View File

@ -26,7 +26,7 @@
#include "serene/exprs/symbol.h"
#include "../test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <llvm/Support/Casting.h>

View File

@ -30,7 +30,7 @@
#include "serene/reader/semantics.h"
#include "../test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
namespace serene {
namespace exprs {

View File

@ -25,7 +25,7 @@
#include "serene/exprs/number.h"
#include "../test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
namespace serene {
namespace exprs {

View File

@ -28,7 +28,7 @@
#include "serene/reader/reader.h"
#include "./test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
namespace serene {

View File

@ -25,7 +25,7 @@
#include "serene/reader/reader.h"
#include "../test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
namespace serene {
namespace reader {

View File

@ -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 <catch2/catch.hpp>
//#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 <catch2/catch.hpp>
#include <catch2/catch_all.hpp>

View File

@ -27,21 +27,23 @@
#include "serene/reader/location.h"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
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);
};

View File

@ -25,7 +25,7 @@
#include "serene/traits.h"
#include "./test_helpers.cpp.inc"
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
namespace serene {