Skip to content

Commit

Permalink
Rework testing (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin authored May 19, 2024
1 parent 426cd60 commit fa8dc6b
Show file tree
Hide file tree
Showing 13 changed files with 962 additions and 6,338 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.target}} `
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} `
-DLIBASSERT_BUILD_TESTING=On `
-DLIBASSERT_USE_CI_WRAPPER=On `
"-GUnix Makefiles"
make -j
- name: test
Expand Down
6 changes: 5 additions & 1 deletion cmake/OptionVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ option(
"Override BUILD_TESTING for ${package_name} library"
${build_testing}
)
set(build_testing )
set(build_testing)
mark_as_advanced(LIBASSERT_BUILD_TESTING)


Expand Down Expand Up @@ -154,3 +154,7 @@ option(LIBASSERT_USE_EXTERNAL_MAGIC_ENUM "Obtain magic_enum via find_package ins
set(LIBASSERT_DESIRED_CXX_STANDARD cxx_std_17 CACHE STRING "")

mark_as_advanced(LIBASSERT_DESIRED_CXX_STANDARD)


option(LIBASSERT_USE_CI_WRAPPER "" OFF)
mark_as_advanced(LIBASSERT_USE_CI_WRAPPER)
13 changes: 12 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,30 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
tests/unit/type_handling.cpp
tests/unit/stringify.cpp
tests/unit/fmt-test.cpp
tests/unit/assertion_tests.cpp
)
foreach(test_file ${unit_test_sources})
get_filename_component(test_name ${test_file} NAME_WE)
list(APPEND all_targets ${test_name})
add_executable(${test_name} ${test_file})
target_link_libraries(${test_name} PRIVATE libassert-lib)
target_include_directories(${test_name} PRIVATE src)
add_test(NAME ${test_name} COMMAND ${test_name})
target_compile_features(${test_name} PUBLIC cxx_std_17)
if(LIBASSERT_USE_CI_WRAPPER)
add_test(
NAME ${test_name}
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/tests/ci-wrapper.py $<TARGET_FILE:${test_name}>
)
else()
add_test(NAME ${test_name} COMMAND ${test_name})
endif()
list(APPEND dsym_targets ${test_name})
endforeach()

target_link_libraries(lexer PRIVATE GTest::gtest_main)
target_link_libraries(fmt-test PRIVATE GTest::gtest_main fmt::fmt)
target_link_libraries(assertion_tests PRIVATE GTest::gtest_main)
target_compile_options(assertion_tests PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/permissive- /Zc:preprocessor>)
target_compile_definitions(fmt-test PRIVATE LIBASSERT_USE_FMT)
target_compile_options(lexer PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>)
target_compile_options(fmt-test PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>)
Expand Down
23 changes: 23 additions & 0 deletions tests/ci-wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import os
import subprocess
import sys

env = os.environ.copy()
lp = "{}/../bin".format(os.path.dirname(os.path.realpath(__file__)))
if "LD_LIBRARY_PATH" in env:
env["LD_LIBRARY_PATH"] += ":" + lp
else:
env["LD_LIBRARY_PATH"] = lp

# This script is just a poor workaround for https://github.com/actions/runner-images/issues/8803
buggy_path = "C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Users\\runneradmin\\bin;"
if env["PATH"].startswith(buggy_path):
env["PATH"] = env["PATH"].replace(buggy_path, "", 1)

p = subprocess.Popen(
sys.argv[1:],
env=env
)
p.wait()
sys.exit(p.returncode)
Loading

0 comments on commit fa8dc6b

Please sign in to comment.