CMakeLists.txt revision 0bbfda8a
1# 2# Automated tests 3# 4 5set(CTWMBIN "${CMAKE_BINARY_DIR}/ctwm") 6add_custom_target(test_bins) 7add_dependencies(test_bins ctwm) 8 9 10# Add some infrastructure for building executables for unit tests 11macro(ctwm_simple_unit_test BIN) 12 # Building and linking it 13 add_executable(${BIN} EXCLUDE_FROM_ALL "${BIN}.c") 14 target_link_libraries(${BIN} ctwmlib) 15 16 # Few of our tests really need any of the X or other libs we pull in. 17 # However, most of the .o's for ctwm itself are going to have some 18 # ref out to them somewhere, so any tests that wind up pulling 19 # functions from those are going to make the linker want to resolve 20 # them when we link ${BIN}. So just unconditionally add them and 21 # don't worry about which tests may not actually need 'em. 22 target_link_libraries(${BIN} ${CTWMLIBS}) 23 24 # Add to pre-test target 25 add_dependencies(test_bins ${BIN}) 26 27 # And add the test itself 28 add_test(NAME ${BIN} 29 COMMAND $<TARGET_FILE:${BIN}> 30 ) 31endmacro() 32 33 34 35# First a simple smoke test of the built binary 36add_test(NAME run-info 37 COMMAND ${CTWMBIN} --info 38 ) 39set_tests_properties(run-info PROPERTIES 40 PASS_REGULAR_EXPRESSION "Twm version: " 41 ) 42 43 44# Try parsing the system.ctwmrc 45# Have to support skipping if no $DISPLAY is set, since we require 46# talking to the X server to get far enough to cfgchk. Should really 47# find a way around that, but it's a lot more involved than you'd think, 48# so 'till then... 49add_test(NAME cfgchk 50 COMMAND sh -c "[ -z \"\$DISPLAY\" ] && exit 99 ; ${CTWMBIN} --cfgchk -f ${CMAKE_SOURCE_DIR}/system.ctwmrc" 51 ) 52set_tests_properties(cfgchk PROPERTIES 53 # XXX Requires cmake 3.0... 54 SKIP_RETURN_CODE 99 55 ) 56 57 58# Simple test of m4 preprocessing, but we skip if built without m4. 59# XXX Gotta skip if no $DISPLAY here too. Fix that :( 60# XXX This seems like the simplest way of actually "skip"'ing a test 61# based on configure options. That's nuts. REQUIRED_FILES sounds like 62# it would, but actually causes the test to "not run" and be considered 63# failed :( 64if(USE_M4) 65 set(_test_m4_cmd 66 "[ -z \"\$DISPLAY\" ] && exit 99 \\; ${CTWMBIN} --cfgchk -f ${CMAKE_CURRENT_SOURCE_DIR}/test_m4/ctwmrc" 67 ) 68else() 69 set(_test_m4_cmd "echo Built without m4, skipping \\; exit 99") 70endif() 71add_test(NAME test_m4 72 COMMAND sh -c ${_test_m4_cmd} 73 ) 74set_tests_properties(test_m4 PROPERTIES 75 SKIP_RETURN_CODE 99 76 ) 77 78 79# A first run at a unit test 80add_subdirectory(util_expand) 81