Skip to content

Commit

Permalink
🎉 Added catch2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherFoxGuy committed Dec 8, 2022
1 parent e9dfc26 commit bd55966
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 22 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build & Test
on: [ push, pull_request ]
jobs:
build:
name: Testing on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest ]
steps:
- uses: actions/checkout@v1

- name: Get latest CMake and ninja
uses: lukka/get-cmake@latest

- name: Cache conan
uses: actions/[email protected]
with:
key: conan-${{ runner.os }}-${{ hashFiles('**/Testbed/CMakeLists.txt') }}
path: ~/.conan/

- uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Enable Developer Command Prompt
uses: ilammy/[email protected]

- name: Install conan
run: pip install conan

- name: Configure
env:
CONAN_USER_HOME_SHORT: None
run: cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DUSE_CONAN=ON Testbed

- name: Build
run: ninja

- name: Test
run: ctest --output-on-failure

- name: Clean Conan pkgs
run: conan remove "*" -fsb
6 changes: 3 additions & 3 deletions Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include "RefCountingObject.h"
#include "RefCountingObjectPtr.h"

#include <string>
#include <vector>
#include <angelscript.h>
#include <cassert>
#include <iostream>
#include <angelscript.h>
#include <string>
#include <vector>

class Horse: public RefCountingObject<Horse>
{
Expand Down
63 changes: 45 additions & 18 deletions Testbed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
#-------------------------------------------------------
# Testbed Main Build Script
#-------------------------------------------------------
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})
cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR})

project(testbed)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

if (USE_CONAN)
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif ()

include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_configure(REQUIRES angelscript/2.35.1 catch2/3.1.0 GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE . BUILD missing SETTINGS ${settings})
endif ()

find_package(Angelscript REQUIRED)
find_package(Catch2)

project(Testbed)

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

set(SRC
../RefCountingObject.h
../RefCountingObjectHandle.h
../RefCountingObjectPtr.h
debug_log.h
scriptstdstring.h

../Example.cpp
../RefCountingObjectHandle.cpp
main.cpp
scriptstdstring.cpp
)

add_executable(${PROJECT_NAME} ${SRC})
target_compile_definitions(${PROJECT_NAME} PRIVATE RCO_ENABLE_DEBUGTRACE)
../RefCountingObject.h
../RefCountingObjectPtr.h
debug_log.h
scriptstdstring.h

../Example.cpp

scriptstdstring.cpp
)

add_executable(${PROJECT_NAME} ${SRC} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Angelscript::angelscript)

if (Catch2_FOUND)
include(CTest)
include(Catch)
enable_testing()

set(TEST_PR_NAME "${PROJECT_NAME}_tests")

add_executable(${TEST_PR_NAME} ${SRC} test.cpp)
target_link_libraries(${TEST_PR_NAME} PRIVATE Catch2::Catch2 Angelscript::angelscript Catch2::Catch2WithMain)

catch_discover_tests(${TEST_PR_NAME})
endif ()

if (WIN32)
target_link_libraries(${PROJECT_NAME} PRIVATE Winmm)
endif()
if (Catch2_FOUND)
target_link_libraries(${TEST_PR_NAME} PRIVATE Winmm)
endif ()
endif ()
1 change: 1 addition & 0 deletions Testbed/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[requires]
angelscript/2.35.1
catch2/3.1.0

[generators]
cmake_find_package
3 changes: 2 additions & 1 deletion Testbed/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ int getch()
return ch;
}

#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename),(mode)))==NULL
#endif

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

// Wait until the user presses a key
std::cout << std::endl << "Press any key to quit." << std::endl;
while(!_getch());
while(!getch());

return 0;
}
Expand Down
Loading

0 comments on commit bd55966

Please sign in to comment.