Skip to content

Commit

Permalink
[cpp/ci] added skeleton code for libpsyc functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed May 19, 2024
1 parent 03b4a6a commit 2567950
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: cmake --build ./build/ci_${{ matrix.build_config }} --target psyc
working-directory: cpp

- name: 'Psyc functional tests ${{ matrix.compiler }}_${{ matrix.build_config }}'
run: cmake --build ./build/ci_${{ matrix.build_config }} --target test
working-directory: cpp

- name: 'Upload psyc as artifact'
uses: actions/upload-artifact@v4
with:
Expand Down
9 changes: 8 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ target_link_libraries(libpsyc PUBLIC ${llvm_dependent_libs})
add_executable(psyc
src/psyc_main.cpp
)
target_link_libraries(psyc PRIVATE libpsyc)
target_link_libraries(psyc PRIVATE libpsyc)

###################
## PSYC - TESTS ##
###################

include(CTest)
add_subdirectory(test)
42 changes: 42 additions & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function(psyc_add_test)
cmake_parse_arguments(
PSYC_ADD_TEST
""
"TARGET"
"SOURCES"
${ARGN}
)

# Add the test executable.
add_executable(${PSYC_ADD_TEST_TARGET}
${PSYC_ADD_TEST_SOURCES}
)
# All tests link against psyc.
target_link_libraries(${PSYC_ADD_TEST_TARGET} PRIVATE libpsyc)
# Note: CTest only runs test executables, doesn't build them. This is of course unfathomably stupid - You have to use "fixtures" (see: https://crascit.com/2016/10/18/test-fixtures-with-cmake-ctest/)
# I'm just parroting what it says to do here.
# Essentially:
# 1. Add a test to simply run cmake --build to build the target.
# 2. Set a "fixture" property on (1).
# 3. Add a test to simply run the executable, this is normal CMake stuff.
# 4. Set a fixture requirement on (3) against (2), causing it to essentially depend on building itself.
# (1)
add_test(${PSYC_ADD_TEST_TARGET}_build
"${CMAKE_COMMAND}"
--build "${CMAKE_BINARY_DIR}"
--config "$<CONFIG>"
--target ${PSYC_ADD_TEST_TARGET}
)
# (2)
set_tests_properties(${PSYC_ADD_TEST_TARGET}_build PROPERTIES FIXTURES_SETUP ${PSYC_ADD_TEST_TARGET}_fixture)
# (3)
add_test(${PSYC_ADD_TEST_TARGET} ${PSYC_ADD_TEST_TARGET})
# (4)
set_tests_properties(${PSYC_ADD_TEST_TARGET} PROPERTIES FIXTURES_REQUIRED ${PSYC_ADD_TEST_TARGET}_fixture)
endfunction()

# When top-level psyc CMakeLists includes CTest, this `BUILD_TESTING` option is created which defaults to ON. I guess the idea is that this is a cache variable you can turn off if you really want to.
# Seems a bit silly to me, but we'll respect it anyway.
if(BUILD_TESTING)
add_subdirectory(functional_tests)
endif()
5 changes: 5 additions & 0 deletions cpp/test/functional_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
psyc_add_test(
TARGET type_coherency
SOURCES
type_coherency.cpp
)
4 changes: 4 additions & 0 deletions cpp/test/functional_tests/type_coherency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main()
{
return 0;
}

0 comments on commit 2567950

Please sign in to comment.