10bbfda8aSnia# 20bbfda8aSnia# Automated tests 30bbfda8aSnia# 40bbfda8aSnia 5b18c2d1eSniaset(CTWMBIN "ctwm") 6b18c2d1eSniaset(CTWMPATH "${CMAKE_BINARY_DIR}/ctwm") 70bbfda8aSniaadd_custom_target(test_bins) 80bbfda8aSniaadd_dependencies(test_bins ctwm) 90bbfda8aSnia 100bbfda8aSnia 110bbfda8aSnia# Add some infrastructure for building executables for unit tests 12b18c2d1eSnia# 13b18c2d1eSnia# BIN - name of the binary to run. 14b18c2d1eSnia# BINPATH - path of the binary to run. 15b18c2d1eSnia# ARGS - Add'l arguments to the binary for the test 16b18c2d1eSnia# WORKING_DIRECTORY - self-explanatory 17b18c2d1eSnia# 18b18c2d1eSnia# Currently, ${BINPATH} means a thing is already built, so we don't need 19b18c2d1eSnia# to worry about building, that's just the path to run. Else, ${BIN} is 20b18c2d1eSnia# built from ${BIN}.c (though multiple calls with the same ${BIN} won't 21b18c2d1eSnia# try to re-do the builds). e.g., commonly, $BINPATH is used when we're 22b18c2d1eSnia# running the main ctwm binary, instead of s test-specific bin. 23b18c2d1eSnia# 24b18c2d1eSnia# This is not un-janky, but it works, and we'll worry about cleaning it 25b18c2d1eSnia# up if it gets worse. 26b18c2d1eSniafunction(ctwm_simple_unit_test TNAME) 27b18c2d1eSnia set(_opts ALLOW_DISPLAY) 28b18c2d1eSnia set(_arg_one BIN BINPATH WORKING_DIRECTORY) 29b18c2d1eSnia set(_arg_multi ARGS) 30b18c2d1eSnia cmake_parse_arguments(_ARGS "${_opts}" "${_arg_one}" "${_arg_multi}" 31b18c2d1eSnia ${ARGN}) 32b18c2d1eSnia 33b18c2d1eSnia # Maybe we're passed a specific path to run 34b18c2d1eSnia if(_ARGS_BINPATH) 35b18c2d1eSnia set(BIN_RUN "${_ARGS_BINPATH}") 36b18c2d1eSnia endif() 37b18c2d1eSnia 38b18c2d1eSnia # What's the binary name? 39b18c2d1eSnia if(_ARGS_BIN) 40b18c2d1eSnia set(BIN "${_ARGS_BIN}") 41b18c2d1eSnia else() 42b18c2d1eSnia set(BIN "${TNAME}") 43b18c2d1eSnia endif() 44b18c2d1eSnia 45b18c2d1eSnia # Derive path if we only got a name 46b18c2d1eSnia if(NOT BIN_RUN) 47b18c2d1eSnia set(BIN_RUN $<TARGET_FILE:${BIN}>) 48b18c2d1eSnia endif() 49b18c2d1eSnia 500bbfda8aSnia # Building and linking it 51b18c2d1eSnia if(NOT TARGET ${BIN}) 52b18c2d1eSnia add_executable(${BIN} EXCLUDE_FROM_ALL "${BIN}.c") 53b18c2d1eSnia target_sources(${BIN} PUBLIC $<TARGET_OBJECTS:ctwmlib>) 540bbfda8aSnia 55b18c2d1eSnia # Few of our tests really need any of the X or other libs we pull in. 56b18c2d1eSnia # However, most of the .o's for ctwm itself are going to have some 57b18c2d1eSnia # ref out to them somewhere, so any tests that wind up pulling 58b18c2d1eSnia # functions from those are going to make the linker want to resolve 59b18c2d1eSnia # them when we link ${TNAME}. So just unconditionally add them and 60b18c2d1eSnia # don't worry about which tests may not actually need 'em. 61b18c2d1eSnia target_link_libraries(${BIN} ${CTWMLIBS}) 620bbfda8aSnia 63b18c2d1eSnia # Add to pre-test target 64b18c2d1eSnia add_dependencies(test_bins ${BIN}) 65b18c2d1eSnia endif() 660bbfda8aSnia 670bbfda8aSnia # And add the test itself 68b18c2d1eSnia add_test(NAME ${TNAME} 69b18c2d1eSnia COMMAND ${BIN_RUN} ${_ARGS_ARGS} 70b18c2d1eSnia WORKING_DIRECTORY ${_ARGS_WORKING_DIRECTORY} 710bbfda8aSnia ) 72b18c2d1eSnia 73b18c2d1eSnia # Don't allow $DISPLAY unless specifically requested. 74b18c2d1eSnia if(NOT _ARGS_ALLOW_DISPLAY) 75b18c2d1eSnia set_tests_properties(${TNAME} PROPERTIES 76b18c2d1eSnia ENVIRONMENT DISPLAY= 77b18c2d1eSnia ) 78b18c2d1eSnia endif() 79b18c2d1eSnia 80b18c2d1eSniaendfunction() 81b18c2d1eSnia 82b18c2d1eSnia 83b18c2d1eSnia# Simple wrapper for when we want to explicitly skip a test (as opposed 84b18c2d1eSnia# to just silently not doing it; better UX to say we're skipping one and 85b18c2d1eSnia# why...) 86b18c2d1eSnia# 87b18c2d1eSnia# XXX This seems like the simplest way of actually "skip"'ing a test 88b18c2d1eSnia# based on configure options. That's nuts. REQUIRED_FILES sounds like 89b18c2d1eSnia# it would, but actually causes the test to "not run" and be considered 90b18c2d1eSnia# failed :( 91b18c2d1eSniafunction(ctwm_skip_unit_test TNAME REASON) 92b18c2d1eSnia add_test(NAME ${TNAME} COMMAND sh -c "echo Skipped: ${REASON} ; exit 99") 93b18c2d1eSnia set_tests_properties(${TNAME} PROPERTIES SKIP_RETURN_CODE 99) 94b18c2d1eSniaendfunction() 950bbfda8aSnia 960bbfda8aSnia 970bbfda8aSnia 980bbfda8aSnia# First a simple smoke test of the built binary 99b18c2d1eSniactwm_simple_unit_test(run-info 100b18c2d1eSnia BIN ${CTWMBIN} 101b18c2d1eSnia BINPATH ${CTWMPATH} 102b18c2d1eSnia ARGS --info 1030bbfda8aSnia ) 1040bbfda8aSniaset_tests_properties(run-info PROPERTIES 1050bbfda8aSnia PASS_REGULAR_EXPRESSION "Twm version: " 1060bbfda8aSnia ) 1070bbfda8aSnia 1080bbfda8aSnia 1090bbfda8aSnia# Try parsing the system.ctwmrc 110b18c2d1eSniactwm_simple_unit_test(cfgchk 111b18c2d1eSnia BIN ${CTWMBIN} 112b18c2d1eSnia BINPATH ${CTWMPATH} 113b18c2d1eSnia ARGS --cfgchk -f ${CMAKE_SOURCE_DIR}/system.ctwmrc 1140bbfda8aSnia ) 1150bbfda8aSnia 1160bbfda8aSnia 1170bbfda8aSnia# Simple test of m4 preprocessing, but we skip if built without m4. 1180bbfda8aSniaif(USE_M4) 119b18c2d1eSnia add_subdirectory(test_m4) 1200bbfda8aSniaelse() 121b18c2d1eSnia ctwm_skip_unit_test(test_m4 "Built without USE_M4") 1220bbfda8aSniaendif() 1230bbfda8aSnia 1240bbfda8aSnia 1250bbfda8aSnia# A first run at a unit test 1260bbfda8aSniaadd_subdirectory(util_expand) 127b18c2d1eSnia 128b18c2d1eSnia# RLayout stuff 129b18c2d1eSniaadd_subdirectory(layout) 130b18c2d1eSnia 131b18c2d1eSnia# TwmKeys menu bits 132b18c2d1eSniaadd_subdirectory(menu_twmkeys) 133