head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC6:1.1.1.2
	netbsd-11-0-RC5:1.1.1.2
	netbsd-11-0-RC4:1.1.1.2
	netbsd-11-0-RC3:1.1.1.2
	netbsd-11-0-RC2:1.1.1.2
	netbsd-11-0-RC1:1.1.1.2
	netbsd-11:1.1.1.2.0.2
	netbsd-11-base:1.1.1.2
	netbsd-10-1-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	ctwm-4-1-0:1.1.1.2
	netbsd-10:1.1.1.1.0.2
	netbsd-10-base:1.1.1.1
	ctwm-4-0-3:1.1.1.1
	CTWM:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2021.04.11.08.36.54;	author nia;	state Exp;
branches
	1.1.1.1;
next	;
commitid	PjWN65car4ihSQOC;

1.1.1.1
date	2021.04.11.08.36.54;	author nia;	state Exp;
branches;
next	1.1.1.2;
commitid	PjWN65car4ihSQOC;

1.1.1.2
date	2023.07.05.07.36.07;	author nia;	state Exp;
branches;
next	;
commitid	W6xbaV6G6L8elAvE;


desc
@@


1.1
log
@Initial revision
@
text
@#
# Automated tests
#

set(CTWMBIN "${CMAKE_BINARY_DIR}/ctwm")
add_custom_target(test_bins)
add_dependencies(test_bins ctwm)


# Add some infrastructure for building executables for unit tests
macro(ctwm_simple_unit_test BIN)
	# Building and linking it
	add_executable(${BIN} EXCLUDE_FROM_ALL "${BIN}.c")
	target_link_libraries(${BIN} ctwmlib)

	# Few of our tests really need any of the X or other libs we pull in.
	# However, most of the .o's for ctwm itself are going to have some
	# ref out to them somewhere, so any tests that wind up pulling
	# functions from those are going to make the linker want to resolve
	# them when we link ${BIN}.  So just unconditionally add them and
	# don't worry about which tests may not actually need 'em.
	target_link_libraries(${BIN} ${CTWMLIBS})

	# Add to pre-test target
	add_dependencies(test_bins ${BIN})

	# And add the test itself
	add_test(NAME ${BIN}
		COMMAND $<TARGET_FILE:${BIN}>
		)
endmacro()



# First a simple smoke test of the built binary
add_test(NAME run-info
	COMMAND ${CTWMBIN} --info
	)
set_tests_properties(run-info PROPERTIES
	PASS_REGULAR_EXPRESSION "Twm version: "
	)


# Try parsing the system.ctwmrc
# Have to support skipping if no $DISPLAY is set, since we require
# talking to the X server to get far enough to cfgchk.  Should really
# find a way around that, but it's a lot more involved than you'd think,
# so 'till then...
add_test(NAME cfgchk
	COMMAND sh -c "[ -z \"\$DISPLAY\" ] && exit 99 ; ${CTWMBIN} --cfgchk -f ${CMAKE_SOURCE_DIR}/system.ctwmrc"
	)
set_tests_properties(cfgchk PROPERTIES
	# XXX Requires cmake 3.0...
	SKIP_RETURN_CODE 99
	)


# Simple test of m4 preprocessing, but we skip if built without m4.
# XXX Gotta skip if no $DISPLAY here too.  Fix that   :(
# XXX This seems like the simplest way of actually "skip"'ing a test
# based on configure options.  That's nuts.  REQUIRED_FILES sounds like
# it would, but actually causes the test to "not run" and be considered
# failed   :(
if(USE_M4)
	set(_test_m4_cmd
		"[ -z \"\$DISPLAY\" ] && exit 99 \\; ${CTWMBIN} --cfgchk -f ${CMAKE_CURRENT_SOURCE_DIR}/test_m4/ctwmrc"
		)
else()
	set(_test_m4_cmd "echo Built without m4, skipping \\; exit 99")
endif()
add_test(NAME test_m4
	COMMAND sh -c ${_test_m4_cmd}
	)
set_tests_properties(test_m4 PROPERTIES
	SKIP_RETURN_CODE 99
	)


# A first run at a unit test
add_subdirectory(util_expand)
@


1.1.1.1
log
@ctwm-4.0.3
@
text
@@


1.1.1.2
log
@ctwm-4.1.0
@
text
@d5 1
a5 2
set(CTWMBIN "ctwm")
set(CTWMPATH "${CMAKE_BINARY_DIR}/ctwm")
d11 12
a22 37
#
# BIN - name of the binary to run.
# BINPATH - path of the binary to run.
# ARGS - Add'l arguments to the binary for the test
# WORKING_DIRECTORY - self-explanatory
#
# Currently, ${BINPATH} means a thing is already built, so we don't need
# to worry about building, that's just the path to run.  Else, ${BIN} is
# built from ${BIN}.c (though multiple calls with the same ${BIN} won't
# try to re-do the builds).  e.g., commonly, $BINPATH is used when we're
# running the main ctwm binary, instead of s test-specific bin.
#
# This is not un-janky, but it works, and we'll worry about cleaning it
# up if it gets worse.
function(ctwm_simple_unit_test TNAME)
	set(_opts ALLOW_DISPLAY)
	set(_arg_one BIN BINPATH WORKING_DIRECTORY)
	set(_arg_multi ARGS)
	cmake_parse_arguments(_ARGS "${_opts}" "${_arg_one}" "${_arg_multi}"
		${ARGN})

	# Maybe we're passed a specific path to run
	if(_ARGS_BINPATH)
		set(BIN_RUN "${_ARGS_BINPATH}")
	endif()

	# What's the binary name?
	if(_ARGS_BIN)
		set(BIN "${_ARGS_BIN}")
	else()
		set(BIN "${TNAME}")
	endif()

	# Derive path if we only got a name
	if(NOT BIN_RUN)
		set(BIN_RUN $<TARGET_FILE:${BIN}>)
	endif()
d24 2
a25 16
	# Building and linking it
	if(NOT TARGET ${BIN})
		add_executable(${BIN} EXCLUDE_FROM_ALL "${BIN}.c")
		target_sources(${BIN} PUBLIC $<TARGET_OBJECTS:ctwmlib>)

		# Few of our tests really need any of the X or other libs we pull in.
		# However, most of the .o's for ctwm itself are going to have some
		# ref out to them somewhere, so any tests that wind up pulling
		# functions from those are going to make the linker want to resolve
		# them when we link ${TNAME}.  So just unconditionally add them and
		# don't worry about which tests may not actually need 'em.
		target_link_libraries(${BIN} ${CTWMLIBS})

		# Add to pre-test target
		add_dependencies(test_bins ${BIN})
	endif()
d28 2
a29 3
	add_test(NAME ${TNAME}
		COMMAND ${BIN_RUN} ${_ARGS_ARGS}
		WORKING_DIRECTORY ${_ARGS_WORKING_DIRECTORY}
d31 1
a31 23

	# Don't allow $DISPLAY unless specifically requested.
	if(NOT _ARGS_ALLOW_DISPLAY)
		set_tests_properties(${TNAME} PROPERTIES
			ENVIRONMENT DISPLAY=
			)
	endif()

endfunction()


# Simple wrapper for when we want to explicitly skip a test (as opposed
# to just silently not doing it; better UX to say we're skipping one and
# why...)
#
# XXX This seems like the simplest way of actually "skip"'ing a test
# based on configure options.  That's nuts.  REQUIRED_FILES sounds like
# it would, but actually causes the test to "not run" and be considered
# failed   :(
function(ctwm_skip_unit_test TNAME REASON)
	add_test(NAME ${TNAME} COMMAND sh -c "echo Skipped: ${REASON} ; exit 99")
	set_tests_properties(${TNAME} PROPERTIES SKIP_RETURN_CODE 99)
endfunction()
d36 2
a37 4
ctwm_simple_unit_test(run-info
	BIN ${CTWMBIN}
	BINPATH ${CTWMPATH}
	ARGS --info
d45 10
a54 4
ctwm_simple_unit_test(cfgchk
	BIN ${CTWMBIN}
	BINPATH ${CTWMPATH}
	ARGS --cfgchk -f ${CMAKE_SOURCE_DIR}/system.ctwmrc
d59 5
d65 3
a67 1
	add_subdirectory(test_m4)
d69 1
a69 1
	ctwm_skip_unit_test(test_m4 "Built without USE_M4")
d71 6
a80 6

# RLayout stuff
add_subdirectory(layout)

# TwmKeys menu bits
add_subdirectory(menu_twmkeys)
@

