Skip to content

Commit 596ad25

Browse files
committed
🎉 Added catch2 test
1 parent 6b3905a commit 596ad25

File tree

8 files changed

+376
-22
lines changed

8 files changed

+376
-22
lines changed

.github/workflows/main.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build & Test
2+
on: [ push, pull_request ]
3+
jobs:
4+
build:
5+
name: Testing on ${{ matrix.os }}
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
os: [ ubuntu-latest, windows-latest ]
11+
steps:
12+
- uses: actions/checkout@v1
13+
14+
- name: Get latest CMake and ninja
15+
uses: lukka/get-cmake@latest
16+
17+
- name: Cache conan
18+
uses: actions/[email protected]
19+
with:
20+
key: conan-${{ runner.os }}-${{ hashFiles('**/Testbed/CMakeLists.txt') }}
21+
path: ~/.conan/
22+
23+
- uses: actions/setup-python@v2
24+
with:
25+
python-version: "3.9"
26+
27+
- name: Enable Developer Command Prompt
28+
uses: ilammy/[email protected]
29+
30+
- name: Install conan
31+
run: pip install conan
32+
33+
- name: Configure
34+
env:
35+
CONAN_USER_HOME_SHORT: None
36+
run: cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DUSE_CONAN=ON Testbed
37+
38+
- name: Build
39+
run: ninja
40+
41+
- name: Test
42+
run: ctest --output-on-failure
43+
44+
- name: Clean Conan pkgs
45+
run: conan remove "*" -fsb

Example.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#include "RefCountingObject.h"
33
#include "RefCountingObjectPtr.h"
44

5+
#include <angelscript.h>
6+
#include <cassert>
7+
#include <iostream>
58
#include <string>
69
#include <vector>
7-
#include <cassert>
8-
#include <angelscript.h>
910

1011
class Horse: public RefCountingObject<Horse>
1112
{

RefCountingObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cassert>
1010

1111
#if !defined(RefCoutingObject_DEBUGTRACE)
12-
# define RefCoutingObject_DEBUGTRACE
12+
# define RefCoutingObject_DEBUGTRACE()
1313
#endif
1414

1515
/// Self reference-counting objects, as requred by AngelScript garbage collector.

RefCountingObjectPtr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <angelscript.h>
1111
#include <cassert>
12+
#include <stdio.h>
1213

1314
#if !defined(RefCoutingObjectPtr_DEBUGTRACE)
1415
# define RefCoutingObjectPtr_DEBUGTRACE

Testbed/CMakeLists.txt

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
#-------------------------------------------------------
22
# Testbed Main Build Script
33
#-------------------------------------------------------
4-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})
54
cmake_minimum_required(VERSION 3.0)
5+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})
6+
7+
project(testbed)
68

79
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
8-
set(CMAKE_CXX_STANDARD 11)
10+
set(CMAKE_CXX_STANDARD 14)
11+
12+
if(USE_CONAN)
13+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
14+
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
15+
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
16+
"${CMAKE_BINARY_DIR}/conan.cmake"
17+
TLS_VERIFY ON)
18+
endif()
19+
20+
include(${CMAKE_BINARY_DIR}/conan.cmake)
21+
conan_cmake_configure(REQUIRES angelscript/2.35.1 catch2/3.1.0 GENERATORS cmake_find_package)
22+
conan_cmake_autodetect(settings)
23+
conan_cmake_install(PATH_OR_REFERENCE . BUILD missing SETTINGS ${settings})
24+
endif()
925

1026
find_package(Angelscript REQUIRED)
27+
find_package(Catch2)
1128

12-
project(Testbed)
1329

1430
file(COPY "${CMAKE_SOURCE_DIR}/../Example.as" DESTINATION "${CMAKE_BINARY_DIR}")
1531

1632
set(SRC
17-
../RefCountingObject.h
18-
../RefCountingObjectHandle.h
19-
../RefCountingObjectPtr.h
20-
debug_log.h
21-
scriptstdstring.h
22-
23-
../Example.cpp
24-
../RefCountingObjectHandle.cpp
25-
main.cpp
26-
scriptstdstring.cpp
27-
)
28-
29-
add_executable(${PROJECT_NAME} ${SRC})
30-
target_compile_definitions(${PROJECT_NAME} PRIVATE RCO_ENABLE_DEBUGTRACE)
33+
../RefCountingObject.h
34+
../RefCountingObjectPtr.h
35+
debug_log.h
36+
scriptstdstring.h
37+
38+
../Example.cpp
39+
40+
scriptstdstring.cpp
41+
)
42+
43+
add_executable(${PROJECT_NAME} ${SRC} main.cpp)
3144
target_link_libraries(${PROJECT_NAME} PRIVATE Angelscript::angelscript)
3245

46+
if (Catch2_FOUND)
47+
include(CTest)
48+
include(Catch)
49+
enable_testing()
50+
51+
set(TEST_PR_NAME "${PROJECT_NAME}_tests")
52+
53+
add_executable(${TEST_PR_NAME} ${SRC} test.cpp)
54+
target_link_libraries(${TEST_PR_NAME} PRIVATE Catch2::Catch2 Angelscript::angelscript Catch2::Catch2WithMain)
55+
56+
catch_discover_tests(${TEST_PR_NAME})
57+
endif ()
58+
3359
if (WIN32)
3460
target_link_libraries(${PROJECT_NAME} PRIVATE Winmm)
35-
endif()
61+
if (Catch2_FOUND)
62+
target_link_libraries(${TEST_PR_NAME} PRIVATE Winmm)
63+
endif ()
64+
endif ()

Testbed/conanfile.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[requires]
22
angelscript/2.35.1
3+
catch2/3.1.0
34

45
[generators]
56
cmake_find_package

Testbed/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int getch()
4949
return ch;
5050
}
5151

52+
#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename),(mode)))==NULL
5253
#endif
5354

5455
// Function prototypes
@@ -69,7 +70,7 @@ int main(int argc, char **argv)
6970

7071
// Wait until the user presses a key
7172
std::cout << std::endl << "Press any key to quit." << std::endl;
72-
while(!_getch());
73+
while(!getch());
7374

7475
return 0;
7576
}

0 commit comments

Comments
 (0)