2012-03-10 01:24:43 +04:00
foreach ( arg
R u n C M a k e _ G E N E R A T O R
R u n C M a k e _ S O U R C E _ D I R
R u n C M a k e _ B I N A R Y _ D I R
)
if ( NOT DEFINED ${ arg } )
message ( FATAL_ERROR "${arg} not given!" )
endif ( )
endforeach ( )
function ( run_cmake test )
set ( top_src "${RunCMake_SOURCE_DIR}" )
set ( top_bin "${RunCMake_BINARY_DIR}" )
if ( EXISTS ${ top_src } / ${ test } -result.txt )
file ( READ ${ top_src } / ${ test } -result.txt expect_result )
string ( REGEX REPLACE "\n+$" "" expect_result "${expect_result}" )
else ( )
set ( expect_result 0 )
endif ( )
foreach ( o out err )
2015-02-09 10:41:06 +03:00
if ( RunCMake-std ${ o } -file AND EXISTS ${ top_src } / ${ RunCMake-std${o } -file} )
file ( READ ${ top_src } / ${ RunCMake-std${o } -file} expect_std ${ o } )
string ( REGEX REPLACE "\n+$" "" expect_std ${ o } "${expect_std${o}}" )
elseif ( EXISTS ${ top_src } / ${ test } -std ${ o } .txt )
2012-03-10 01:24:43 +04:00
file ( READ ${ top_src } / ${ test } -std ${ o } .txt expect_std ${ o } )
string ( REGEX REPLACE "\n+$" "" expect_std ${ o } "${expect_std${o}}" )
else ( )
unset ( expect_std ${ o } )
endif ( )
endforeach ( )
2014-12-17 00:11:40 +03:00
if ( NOT expect_stderr )
if ( NOT RunCMake_DEFAULT_stderr )
set ( RunCMake_DEFAULT_stderr "^$" )
endif ( )
set ( expect_stderr ${ RunCMake_DEFAULT_stderr } )
endif ( )
2014-04-07 01:53:52 +04:00
if ( NOT RunCMake_TEST_SOURCE_DIR )
set ( RunCMake_TEST_SOURCE_DIR "${top_src}" )
endif ( )
2013-02-18 19:43:40 +04:00
if ( NOT RunCMake_TEST_BINARY_DIR )
set ( RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build" )
endif ( )
if ( NOT RunCMake_TEST_NO_CLEAN )
file ( REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}" )
endif ( )
2012-04-18 19:09:18 +04:00
file ( MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}" )
2012-12-10 19:42:33 +04:00
if ( NOT DEFINED RunCMake_TEST_OPTIONS )
set ( RunCMake_TEST_OPTIONS "" )
endif ( )
2013-10-02 22:45:54 +04:00
if ( APPLE )
list ( APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW )
endif ( )
2016-04-28 17:09:15 +03:00
if ( RunCMake_GENERATOR STREQUAL "Visual Studio 7 .NET 2003" AND NOT RunCMake_WARN_VS71 )
list ( APPEND RunCMake_TEST_OPTIONS -DCMAKE_WARN_VS71=OFF )
endif ( )
2015-01-24 15:08:12 +03:00
if ( RunCMake_MAKE_PROGRAM )
list ( APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}" )
endif ( )
2015-04-07 16:06:51 +03:00
if ( RunCMake_TEST_OUTPUT_MERGE )
set ( actual_stderr_var actual_stdout )
set ( actual_stderr "" )
else ( )
set ( actual_stderr_var actual_stderr )
endif ( )
2015-06-24 16:53:37 +03:00
if ( DEFINED RunCMake_TEST_TIMEOUT )
set ( maybe_timeout TIMEOUT ${ RunCMake_TEST_TIMEOUT } )
else ( )
set ( maybe_timeout "" )
endif ( )
2014-01-20 22:46:51 +04:00
if ( RunCMake_TEST_COMMAND )
execute_process (
C O M M A N D $ { R u n C M a k e _ T E S T _ C O M M A N D }
W O R K I N G _ D I R E C T O R Y " $ { R u n C M a k e _ T E S T _ B I N A R Y _ D I R } "
O U T P U T _ V A R I A B L E a c t u a l _ s t d o u t
2015-04-07 16:06:51 +03:00
E R R O R _ V A R I A B L E $ { a c t u a l _ s t d e r r _ v a r }
2014-01-20 22:46:51 +04:00
R E S U L T _ V A R I A B L E a c t u a l _ r e s u l t
2015-06-24 16:53:37 +03:00
$ { m a y b e _ t i m e o u t }
2014-01-20 22:46:51 +04:00
)
else ( )
execute_process (
C O M M A N D $ { C M A K E _ C O M M A N D } " $ { R u n C M a k e _ T E S T _ S O U R C E _ D I R } "
- G " $ { R u n C M a k e _ G E N E R A T O R } "
2014-09-12 17:55:06 +04:00
- A " $ { R u n C M a k e _ G E N E R A T O R _ P L A T F O R M } "
2014-01-20 22:46:51 +04:00
- T " $ { R u n C M a k e _ G E N E R A T O R _ T O O L S E T } "
2014-06-30 22:35:52 +04:00
- D R u n C M a k e _ T E S T = $ { t e s t }
2014-02-27 22:22:58 +04:00
- - n o - w a r n - u n u s e d - c l i
2014-01-20 22:46:51 +04:00
$ { R u n C M a k e _ T E S T _ O P T I O N S }
W O R K I N G _ D I R E C T O R Y " $ { R u n C M a k e _ T E S T _ B I N A R Y _ D I R } "
O U T P U T _ V A R I A B L E a c t u a l _ s t d o u t
2015-04-07 16:06:51 +03:00
E R R O R _ V A R I A B L E $ { a c t u a l _ s t d e r r _ v a r }
2014-01-20 22:46:51 +04:00
R E S U L T _ V A R I A B L E a c t u a l _ r e s u l t
2015-06-24 16:53:37 +03:00
$ { m a y b e _ t i m e o u t }
2014-01-20 22:46:51 +04:00
)
endif ( )
2012-03-10 01:24:43 +04:00
set ( msg "" )
2014-12-16 21:33:47 +03:00
if ( NOT "${actual_result}" MATCHES "${expect_result}" )
2016-07-28 01:43:04 +03:00
string ( APPEND msg "Result is [${actual_result}], not [${expect_result}].\n" )
2012-03-10 01:24:43 +04:00
endif ( )
foreach ( o out err )
2015-01-26 21:41:38 +03:00
string ( REGEX REPLACE "\r\n" "\n" actual_std ${ o } "${actual_std${o}}" )
2015-09-17 16:10:36 +03:00
string ( REGEX REPLACE "(^|\n)((==[0-9]+==|BullseyeCoverage|[a-z]+\\([0-9]+\\) malloc:|Error kstat returned|[^\n]*from Time Machine by path|[^\n]*Bullseye Testing Technology)[^\n]*\n)+" "\\1" actual_std ${ o } "${actual_std${o}}" )
2012-03-10 01:24:43 +04:00
string ( REGEX REPLACE "\n+$" "" actual_std ${ o } "${actual_std${o}}" )
set ( expect_ ${ o } "" )
if ( DEFINED expect_std ${ o } )
if ( NOT "${actual_std${o}}" MATCHES "${expect_std${o}}" )
string ( REGEX REPLACE "\n" "\n expect-${o}> " expect_ ${ o }
" e x p e c t - $ { o } > $ { e x p e c t _ s t d $ { o } } " )
set ( expect_ ${ o } "Expected std${o} to match:\n${expect_${o}}\n" )
2016-07-28 01:43:04 +03:00
string ( APPEND msg "std${o} does not match that expected.\n" )
2012-03-10 01:24:43 +04:00
endif ( )
endif ( )
endforeach ( )
2012-04-18 19:09:18 +04:00
unset ( RunCMake_TEST_FAILED )
2015-09-16 17:07:49 +03:00
if ( RunCMake-check-file AND EXISTS ${ top_src } / ${ RunCMake-check-file } )
include ( ${ top_src } / ${ RunCMake-check-file } )
else ( )
include ( ${ top_src } / ${ test } -check.cmake OPTIONAL )
endif ( )
2012-04-18 19:09:18 +04:00
if ( RunCMake_TEST_FAILED )
set ( msg "${RunCMake_TEST_FAILED}\n${msg}" )
endif ( )
2015-01-15 22:36:10 +03:00
if ( msg AND RunCMake_TEST_COMMAND )
string ( REPLACE ";" "\" \"" command "\" ${ RunCMake_TEST_COMMAND } \"")
2016-07-28 01:43:04 +03:00
string ( APPEND msg "Command was:\n command> ${command}\n" )
2015-01-15 22:36:10 +03:00
endif ( )
2012-03-10 01:24:43 +04:00
if ( msg )
string ( REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}" )
string ( REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}" )
message ( SEND_ERROR "${test} - FAILED:\n"
" $ { m s g } "
" $ { e x p e c t _ o u t } "
" A c t u a l s t d o u t : \ n $ { a c t u a l _ o u t } \ n "
" $ { e x p e c t _ e r r } "
" A c t u a l s t d e r r : \ n $ { a c t u a l _ e r r } \ n "
)
else ( )
message ( STATUS "${test} - PASSED" )
endif ( )
endfunction ( )
2014-01-20 22:46:51 +04:00
function ( run_cmake_command test )
set ( RunCMake_TEST_COMMAND "${ARGN}" )
run_cmake ( ${ test } )
endfunction ( )
2015-04-29 23:13:50 +03:00
# Protect RunCMake tests from calling environment.
unset ( ENV{MAKEFLAGS} )