Skip to content

Commit 36cc5c9

Browse files
committed
Setup Test
1 parent a60920c commit 36cc5c9

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ jobs:
5151
run: |
5252
sudo dpkg --add-architecture i386
5353
sudo apt-get update -y
54-
sudo apt-get install ${{ matrix.pkgs }} cmake ninja-build -y
54+
sudo apt-get install ${{ matrix.pkgs }} cmake ninja-build libcriterion-dev -y
55+
56+
- name: Install Deps (Windows)
57+
if: ${{ matrix.os == 'windows-2022' }}
58+
run: |
59+
choco install cmake meson ninja
60+
git clone https://github.com/Snaipe/Criterion.git --recursive
61+
cd Criterion
62+
meson install -C build
63+
64+
- name: Install Deps (MacOS)
65+
if: ${{ matrix.os == 'macos-12' }}
66+
run: brew install criterion
5567

5668
- name: Generate Build Files & Build (Linux)
5769
if: ${{ matrix.os == 'ubuntu-22.04' }}
@@ -73,6 +85,14 @@ jobs:
7385
run: |
7486
make all GENERATOR="${{ matrix.gen }}" BUILD_TYPE=Release NUM_JOBS=4 CMAKE_GEN_FLAGS='-DBUILD_APPLE_BUNDLE=ON -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}'
7587
88+
- name: Run Test (Windows)
89+
if: ${{ matrix.os == 'windows-2022' }}
90+
run: ./build/Release/FileSystem_Test.exe
91+
92+
- name: Run Test (Non-Windows)
93+
if: ${{ matrix.os != 'windows-2022' }}
94+
run: ./build/FileSystem_Test
95+
7696
- name: Upload Artifacts (Linux)
7797
if: ${{ matrix.os == 'ubuntu-22.04' }}
7898
uses: actions/upload-artifact@v3

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 11)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

8+
option(FILESYSTEM_BUILD_TESTS "Build tests" ON)
9+
810
project(FileSystem CXX)
911
add_library(
1012
FileSystem STATIC
@@ -17,8 +19,18 @@ target_include_directories(FileSystem
1719
PUBLIC
1820
${CMAKE_CURRENT_SOURCE_DIR}/include/
1921
)
20-
2122
if(WIN32 OR CYGWIN)
2223
target_compile_definitions(FileSystem PUBLIC FS_TARGET_WINDOWS)
2324
endif()
2425

26+
if(FILESYSTEM_BUILD_TESTS)
27+
include(./FindCriterion.cmake)
28+
if(NOT CRITERION_FOUND)
29+
message(FATAL_ERROR "criterion not found")
30+
endif()
31+
project(FileSystem_Test CXX)
32+
add_executable(FileSystem_Test ${CMAKE_CURRENT_SOURCE_DIR}/src/test.cpp)
33+
target_include_directories(FileSystem_Test PUBLIC ${CRITERION_INCLUDE_DIRS})
34+
target_link_libraries(FileSystem_Test PUBLIC FileSystem ${CRITERION_LIBRARIES} criterion)
35+
endif()
36+

FindCriterion.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is licensed under the WTFPL version 2 -- you can see the full
2+
# license over at http://www.wtfpl.net/txt/copying/
3+
#
4+
# - Try to find Criterion
5+
#
6+
# Once done this will define
7+
# CRITERION_FOUND - System has Criterion
8+
# CRITERION_INCLUDE_DIRS - The Criterion include directories
9+
# CRITERION_LIBRARIES - The libraries needed to use Criterion
10+
11+
find_package(PkgConfig)
12+
13+
find_path(CRITERION_INCLUDE_DIR criterion/criterion.h
14+
PATH_SUFFIXES criterion)
15+
16+
find_library(CRITERION_LIBRARY NAMES criterion libcriterion)
17+
18+
set(CRITERION_LIBRARIES ${CRITERION_LIBRARY})
19+
set(CRITERION_INCLUDE_DIRS ${CRITERION_INCLUDE_DIR})
20+
21+
include(FindPackageHandleStandardArgs)
22+
# handle the QUIET and REQUIRED arguments and set CRITERION_FOUND to TRUE
23+
# if all listed variables are TRUE
24+
find_package_handle_standard_args(Criterion DEFAULT_MSG
25+
CRITERION_LIBRARY CRITERION_INCLUDE_DIR)
26+
27+
mark_as_advanced(CRITERION_INCLUDE_DIR CRITERION_LIBRARY)
28+

src/test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <criterion/criterion.h>
2+
3+
4+

0 commit comments

Comments
 (0)