Skip to content

Commit 8b87621

Browse files
committed
Now using common test library
1 parent a647fe2 commit 8b87621

File tree

9 files changed

+95
-159
lines changed

9 files changed

+95
-159
lines changed

CMakeLists.txt

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,12 @@ project(LangulusEntity
55
HOMEPAGE_URL https://langulus.com
66
)
77

8-
# Check if this project is built as standalone, or a part of something else
9-
if(PROJECT_IS_TOP_LEVEL OR NOT LANGULUS)
8+
# Check if this project is built as standalone, or a part of something else
9+
if (PROJECT_IS_TOP_LEVEL OR NOT LANGULUS)
1010
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
1111
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
12-
1312
include(LangulusUtilities.cmake)
14-
15-
# Add all Langulus libraries
16-
fetch_langulus_module(Core GIT_TAG 35756f11d2f9c475f27b094b8d4c82cd453969fc)
17-
fetch_langulus_module(Logger GIT_TAG dafbeb825071ec60d8403254143f75606151a7e6)
18-
fetch_langulus_module(RTTI GIT_TAG fc49750884ac943dff4261ac5b8dfb2c148423d7)
19-
if(LANGULUS_FEATURE_MANAGED_MEMORY)
20-
fetch_langulus_module(Fractalloc GIT_TAG 66408e8557b1bb3c80615909129342bcebd3fb9f)
21-
endif()
22-
fetch_langulus_module(SIMD GIT_TAG ead5493049e2800b4c3c02d385c0c6314efac69c)
23-
fetch_langulus_module(Anyness GIT_TAG 46a6513d6bcf3d532e9bf746b50d1299692eb96a)
24-
fetch_langulus_module(Flow GIT_TAG 06000427afccf13016738140d09850f0b8cf837b)
25-
fetch_langulus_module(Math GIT_TAG d25c6d59a8ffd352d94c260d102a53217e12c42d)
13+
fetch_langulus_module(Math GIT_TAG e3460ab98514d9d3e10fbf4d827dbb4af0e7426d)
2614
endif()
2715

2816
file(GLOB_RECURSE
@@ -31,7 +19,7 @@ file(GLOB_RECURSE
3119
source/*.cpp
3220
)
3321

34-
# Build and install Entity library
22+
# Build and install Entity library
3523
add_langulus_library(LangulusEntity
3624
$<TARGET_OBJECTS:LangulusLogger>
3725
$<TARGET_OBJECTS:LangulusRTTI>
@@ -42,29 +30,27 @@ add_langulus_library(LangulusEntity
4230
${LANGULUS_ENTITY_SOURCES}
4331
)
4432

45-
target_include_directories(LangulusEntity PUBLIC include
46-
$<TARGET_PROPERTY:LangulusLogger,INTERFACE_INCLUDE_DIRECTORIES>
47-
$<TARGET_PROPERTY:LangulusRTTI,INTERFACE_INCLUDE_DIRECTORIES>
48-
$<$<BOOL:${LANGULUS_FEATURE_MANAGED_MEMORY}>:$<TARGET_PROPERTY:LangulusFractalloc,INTERFACE_INCLUDE_DIRECTORIES>>
49-
$<TARGET_PROPERTY:LangulusAnyness,INTERFACE_INCLUDE_DIRECTORIES>
50-
$<TARGET_PROPERTY:LangulusFlow,INTERFACE_INCLUDE_DIRECTORIES>
51-
$<TARGET_PROPERTY:LangulusMath,INTERFACE_INCLUDE_DIRECTORIES>
33+
target_include_directories(LangulusEntity
34+
PUBLIC $<TARGET_PROPERTY:LangulusLogger,INTERFACE_INCLUDE_DIRECTORIES>
35+
$<TARGET_PROPERTY:LangulusRTTI,INTERFACE_INCLUDE_DIRECTORIES>
36+
$<$<BOOL:${LANGULUS_FEATURE_MANAGED_MEMORY}>:$<TARGET_PROPERTY:LangulusFractalloc,INTERFACE_INCLUDE_DIRECTORIES>>
37+
$<TARGET_PROPERTY:LangulusAnyness,INTERFACE_INCLUDE_DIRECTORIES>
38+
$<TARGET_PROPERTY:LangulusFlow,INTERFACE_INCLUDE_DIRECTORIES>
39+
$<TARGET_PROPERTY:LangulusMath,INTERFACE_INCLUDE_DIRECTORIES>
40+
include
5241
)
5342

5443
target_link_libraries(LangulusEntity
5544
PUBLIC LangulusCore
5645
fmt
46+
PRIVATE $<$<NOT:$<BOOL:${MSVC}>>:dl>
5747
)
5848

59-
if(NOT MSVC)
60-
target_link_libraries(LangulusEntity PRIVATE dl)
61-
endif()
62-
6349
target_compile_definitions(LangulusEntity
6450
PRIVATE LANGULUS_EXPORT_ALL
6551
)
6652

6753
if(LANGULUS_TESTING)
68-
enable_testing()
54+
enable_testing()
6955
add_subdirectory(test)
7056
endif()

LangulusUtilities.cmake

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
include(FetchContent)
22

3+
4+
# Utility for fetching Langulus libraries using FetchContent
35
function(fetch_langulus_module NAME GIT_TAG TAG)
6+
if (LANGULUS)
7+
message(FATAL_ERROR "You can't fetch Langulus::${NAME}, because this build \
8+
indicates LANGULUS is being build along your project. The library you're \
9+
trying to fetch should already be available locally.")
10+
endif()
11+
412
if(NOT DEFINED LANGULUS_EXTERNAL_DIRECTORY)
513
set(LANGULUS_EXTERNAL_DIRECTORY "${CMAKE_SOURCE_DIR}/external" CACHE PATH
614
"Place where external dependencies will be downloaded")
7-
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
15+
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: \
16+
${LANGULUS_EXTERNAL_DIRECTORY}")
817
endif()
918

10-
# Completely avoid downloading or updating anything, once the appropriate folder exists
19+
# Completely avoid downloading or updating anything, once the appropriate
20+
# folder exists
1121
string(TOUPPER ${NAME} UPPERCASE_NAME)
1222
if (EXISTS "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src")
1323
set(FETCHCONTENT_SOURCE_DIR_LANGULUS${UPPERCASE_NAME} "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src" CACHE INTERNAL "" FORCE)
14-
message(STATUS "Reusing external library Langulus::${NAME}... (delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
24+
message(STATUS "Reusing external library Langulus::${NAME}... \
25+
(delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
1526
else()
1627
unset(FETCHCONTENT_SOURCE_DIR_LANGULUS${UPPERCASE_NAME} CACHE)
1728
message(STATUS "Downloading external library Langulus::${NAME}...")
@@ -28,18 +39,23 @@ function(fetch_langulus_module NAME GIT_TAG TAG)
2839
FetchContent_MakeAvailable(Langulus${NAME})
2940
endfunction()
3041

42+
43+
# Utility for fetching external libraries using FetchContent
3144
function(fetch_external_module NAME GIT_REPOSITORY REPO GIT_TAG TAG)
3245
if(NOT DEFINED LANGULUS_EXTERNAL_DIRECTORY)
3346
set(LANGULUS_EXTERNAL_DIRECTORY "${CMAKE_SOURCE_DIR}/external" CACHE PATH
3447
"Place where external dependencies will be downloaded")
35-
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
48+
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, \
49+
using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
3650
endif()
3751

38-
# Completely avoid downloading or updating anything, once the appropriate folder exists
52+
# Completely avoid downloading or updating anything, once the appropriate
53+
# folder exists
3954
string(TOUPPER ${NAME} UPPERCASE_NAME)
4055
if (EXISTS "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src")
4156
set(FETCHCONTENT_SOURCE_DIR_${UPPERCASE_NAME} "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src" CACHE INTERNAL "" FORCE)
42-
message(STATUS "Reusing external library ${NAME}... (delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
57+
message(STATUS "Reusing external library ${NAME}... \
58+
(delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
4359
else()
4460
unset(FETCHCONTENT_SOURCE_DIR_${UPPERCASE_NAME} CACHE)
4561
message(STATUS "Downloading external library ${NAME}...")
@@ -59,4 +75,4 @@ function(fetch_external_module NAME GIT_REPOSITORY REPO GIT_TAG TAG)
5975
string(TOLOWER ${NAME} LOWERCASE_NAME)
6076
set(${NAME}_SOURCE_DIR "${${LOWERCASE_NAME}_SOURCE_DIR}" CACHE INTERNAL "${NAME} source directory")
6177
set(${NAME}_BINARY_DIR "${${LOWERCASE_NAME}_BINARY_DIR}" CACHE INTERNAL "${NAME} binary directory")
62-
endfunction()
78+
endfunction()

test/Common.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///
2+
/// Langulus::Entity
3+
/// Copyright (c) 2013 Dimo Markov <[email protected]>
4+
/// Part of the Langulus framework, see https://langulus.com
5+
///
6+
/// SPDX-License-Identifier: GPL-3.0-or-later
7+
///
8+
#include <Langulus/MetaOf.hpp>
9+
10+
LANGULUS_RTTI_BOUNDARY(RTTI::MainBoundary)

test/Common.hpp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,48 @@
88

99
/// INTENTIONALLY NOT GUARDED
1010
/// Include this file once in each cpp file, after all other headers
11-
#ifdef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
12-
#error Catch has been included prior to this header
13-
#endif
11+
#include <Langulus/Entity/Thing.hpp>
12+
#include <Langulus/Testing.hpp>
1413

15-
#define CATCH_CONFIG_ENABLE_BENCHMARKING
1614

17-
#include "Main.hpp"
18-
#include <catch2/catch.hpp>
15+
/// A unit implementation for testing
16+
class TestUnit1 final : public A::Unit {
17+
public:
18+
LANGULUS(ABSTRACT) false;
19+
LANGULUS_BASES(Unit);
20+
LANGULUS(POOL_TACTIC) RTTI::PoolTactic::Type;
1921

20-
/// See https://github.com/catchorg/Catch2/blob/devel/docs/tostring.md
21-
CATCH_TRANSLATE_EXCEPTION(::Langulus::Exception const& ex) {
22-
return fmt::format("{}", ex);
23-
}
22+
TestUnit1() : Resolvable {this} {}
2423

25-
namespace Catch
26-
{
27-
template<CT::Stringifiable T>
28-
struct StringMaker<T> {
29-
static std::string convert(T const& value) {
30-
return ::std::string {Token {static_cast<Text>(value)}};
31-
}
32-
};
24+
TestUnit1(Describe&& describe)
25+
: Resolvable {this} {
26+
Couple(*describe);
27+
}
3328

34-
/// Save catch2 from doing infinite recursions with Block types
35-
template<CT::Block T>
36-
struct is_range<T> {
37-
static const bool value = false;
38-
};
29+
~TestUnit1() {
30+
Logger::Verbose(this, ": destroying...");
31+
}
3932

40-
}
33+
void Refresh() {}
34+
};
4135

42-
using timer = Catch::Benchmark::Chronometer;
36+
/// A unit implementation for testing
37+
class TestUnit2 final : public A::Unit {
38+
public:
39+
LANGULUS(ABSTRACT) false;
40+
LANGULUS_BASES(Unit);
41+
LANGULUS(POOL_TACTIC) RTTI::PoolTactic::Type;
4342

44-
template<class T>
45-
using uninitialized = Catch::Benchmark::storage_for<T>;
43+
TestUnit2() : Resolvable {this} {}
44+
45+
TestUnit2(Describe&& describe)
46+
: Resolvable {this} {
47+
Couple(*describe);
48+
}
49+
50+
~TestUnit2() {
51+
Logger::Verbose(this, ": destroying...");
52+
}
53+
54+
void Refresh() {}
55+
};

test/Main.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/Main.hpp

Lines changed: 0 additions & 65 deletions
This file was deleted.

test/TestEvents.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
///
66
/// SPDX-License-Identifier: GPL-3.0-or-later
77
///
8-
#include "Common.hpp"
98
#include <Langulus/Entity/Event.hpp>
109
#include <Langulus/Math/Vector.hpp>
1110
#include <Langulus/Verbs/Add.hpp>
11+
#include "Common.hpp"
1212

1313

1414
SCENARIO("Testing Event", "[event]") {

test/TestTemporal.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
///
66
/// SPDX-License-Identifier: GPL-3.0-or-later
77
///
8-
#include "Common.hpp"
98
#include <Langulus/Flow/Temporal.hpp>
9+
#include "Common.hpp"
1010

1111

1212
SCENARIO("Temporal flow", "[temporal]") {
1313
static Allocator::State memoryState;
1414

15+
(void) MetaDataOf<Thing>();
16+
1517
///
1618
/// The following tests rely on this ontology sequence
1719
const auto HI = "create Thing(Name(`<unnamed user>`))"_parse;

test/TestThing.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ TEMPLATE_TEST_CASE("Testing Thing with different kidns of descriptors",
1313
Many, Neat
1414
) {
1515
static Allocator::State memoryState;
16-
static_assert(CT::Deep<Entity::Hierarchy>,
17-
"Hierarchy must be reflected as deep");
16+
17+
static_assert(CT::Complete<Entity::Hierarchy>);
18+
static_assert(CT::Complete<A::Unit>);
19+
static_assert(CT::Complete<Temporal>);
20+
static_assert(CT::Complete<Thing>);
21+
static_assert(CT::Complete<Runtime>);
22+
static_assert(CT::Deep<Entity::Hierarchy>);
1823

1924
WHEN("Creating a default Thing") {
2025
Thing root;

0 commit comments

Comments
 (0)