File: TestingTools.cmake

package info (click to toggle)
qtrvsim 0.9.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,844 kB
  • sloc: cpp: 25,687; ansic: 7,754; makefile: 318; python: 303; sh: 278; asm: 268; xml: 9
file content (44 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Helper functions for integration testing

# Creates a new CLI test. The test consists of two parts: the first runs the command and checks nonzero return value,
# the second compares the stdout with provided files. Currently there diff is not displayed as cmake does not provide a
# portable way to do that.
#
# TODO: show diff whenever available.
#
# NOTE:
#   If CLI was build in debug mode (which is recommended) the test will run with sanitizers and any memory errors
#   including memory leaks will fail the test.
#
# Usage:
#   add_cli_test(
#		NAME <name>
#		ARGS
#			--asm "${CMAKE_SOURCE_DIR}/tests/cli/<name>/program.S"
#			<other CLI commands>
#		EXPECTED_OUTPUT "tests/cli/<name>/stdout.txt"
#   )

function(add_cli_test)
	cmake_parse_arguments(
			CLI_TEST
			""
			"NAME;EXPECTED_OUTPUT"
			"ARGS"
			${ARGN}
	)
	add_custom_target(
			cli_test_${CLI_TEST_NAME}
			COMMAND ${CMAKE_COMMAND} -E make_directory "Testing"
			COMMAND cli ${CLI_TEST_ARGS} > "Testing/stall_test.out"
			COMMAND ${CMAKE_COMMAND} -E compare_files "Testing/stall_test.out"
			"${CMAKE_SOURCE_DIR}/${CLI_TEST_EXPECTED_OUTPUT}"
			WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
			DEPENDS cli
	)

	add_test(
			NAME "cli_${CLI_TEST_NAME}"
			COMMAND ${CMAKE_COMMAND} --build . --target "cli_test_${CLI_TEST_NAME}"
			WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
endfunction()