Replace CppUnit with Catch for unit tests

Drop the legacy CppUnit testing framework used for the unit tests.
Replacing it with Catch has the advantage of not requiring CppUnit
libraries to be installed on the system in order to be able to run
tests (Catch is header-only and a copy of it is now included in the
main repository itself) and, in the future, of being able to write
the tests in a much more natural way.

For now, however, avoid changing the existing tests code as much as
[reasonably] possible to avoid introducing bugs in them and provide
the CppUnit compatibility macros in the new wx/catch_cppunit.h header
which allow to preserve the 99% of the existing code unchanged. Some
of the required changes are:

 - Decompose asserts using "a && b" conditions into multiple asserts
   checking "a" and "b" independently. This would have been better
   even with CppUnit (to know which part of condition exactly failed)
   and is required with Catch.

 - Use extra parentheses around such conditions when they can't be
   easily decomposed in the arrays test, due to the use of macros.
   This is not ideal from the point of view of messages given when
   the tests fail but will do for now.

 - Rewrite asserts using "a || b" as a combination of condition
   checks and assert macros. Again, this is better anyhow, and is
   required with Catch. Incidentally, this allowed to fix a bug in
   the "exec" unit test which didn't leave enough time for the new
   process to be launched before trying to kill it.

 - Remove multiple CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() macros,
   our emulation of this macro can be used only once.

 - Provide string conversions using Catch-specific StringMaker for
   a couple of types.

 - Replace custom wxImage comparison with a Catch-specific matcher
   class.

 - Remove most of test running logic from test.cpp, in particular don't
   parse command line ourselves any longer but use Catch built-in
   command line parser. This is a source of a minor regression:
   previously, both "Foo" and "FooTestCase" could be used as the name of
   the test to run, but now only the latter is accepted.
This commit is contained in:
Vadim Zeitlin
2017-11-01 19:15:24 +01:00
parent 5520d56222
commit e70fc11ef1
85 changed files with 876 additions and 1718 deletions

223
configure vendored
View File

@@ -626,7 +626,6 @@ enable_option_checking=no
enable_option_checking=fatal
ac_subst_vars='LTLIBOBJS
LIBOBJS
CPPUNIT_CONFIG
RESCOMP
DLLTOOL
GCC
@@ -891,8 +890,6 @@ INSTALL_DATA
INSTALL_SCRIPT
INSTALL_PROGRAM
RANLIB
CPPUNIT_LIBS
CPPUNIT_CFLAGS
HOST_SUFFIX
HEADER_PAD_OPTION
SAMPLES_CXXFLAGS
@@ -1355,8 +1352,6 @@ with_sdl_exec_prefix
enable_sdltest
enable_dependency_tracking
enable_precomp_headers
with_cppunit_prefix
with_cppunit_exec_prefix
'
ac_precious_vars='build_alias
host_alias
@@ -1409,9 +1404,7 @@ WEBKIT_LIBS
CAIRO_CFLAGS
CAIRO_LIBS
GST_CFLAGS
GST_LIBS
CPPUNIT_CFLAGS
CPPUNIT_LIBS'
GST_LIBS'
ac_subdirs_all='src/tiff
src/expat'
@@ -2342,8 +2335,6 @@ Optional Packages:
--with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib
--with-sdl-prefix=PFX Prefix where SDL is installed (optional)
--with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)
--with-cppunit-prefix=PFX Prefix where CppUnit is installed (optional)
--with-cppunit-exec-prefix=PFX Exec prefix where CppUnit is installed (optional)
Some influential environment variables:
CC C compiler command
@@ -2417,10 +2408,6 @@ Some influential environment variables:
CAIRO_LIBS linker flags for CAIRO, overriding pkg-config
GST_CFLAGS C compiler flags for GST, overriding pkg-config
GST_LIBS linker flags for GST, overriding pkg-config
CPPUNIT_CFLAGS
C compiler flags for CPPUNIT, overriding pkg-config
CPPUNIT_LIBS
linker flags for CPPUNIT, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
@@ -35891,8 +35878,6 @@ TOOLKIT_LOWERCASE=`echo $TOOLKIT | tr '[A-Z]' '[a-z]'`
case "$TOOLKIT" in
GTK)
TOOLKIT_DESC="GTK+"
@@ -38524,211 +38509,7 @@ if test "$wxUSE_GUI" = "yes"; then
else
SUBDIRS="samples utils"
fi
# Check whether --with-cppunit-prefix was given.
if test "${with_cppunit_prefix+set}" = set; then :
withval=$with_cppunit_prefix; cppunit_config_prefix="$withval"
else
cppunit_config_prefix=""
fi
# Check whether --with-cppunit-exec-prefix was given.
if test "${with_cppunit_exec_prefix+set}" = set; then :
withval=$with_cppunit_exec_prefix; cppunit_config_exec_prefix="$withval"
else
cppunit_config_exec_prefix=""
fi
if test x$cppunit_config_exec_prefix != x ; then
cppunit_config_args="$cppunit_config_args --exec-prefix=$cppunit_config_exec_prefix"
if test x${CPPUNIT_CONFIG+set} != xset ; then
CPPUNIT_CONFIG=$cppunit_config_exec_prefix/bin/cppunit-config
fi
fi
if test x$cppunit_config_prefix != x ; then
cppunit_config_args="$cppunit_config_args --prefix=$cppunit_config_prefix"
if test x${CPPUNIT_CONFIG+set} != xset ; then
CPPUNIT_CONFIG=$cppunit_config_prefix/bin/cppunit-config
fi
fi
# Extract the first word of "cppunit-config", so it can be a program name with args.
set dummy cppunit-config; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_CPPUNIT_CONFIG+:} false; then :
$as_echo_n "(cached) " >&6
else
case $CPPUNIT_CONFIG in
[\\/]* | ?:[\\/]*)
ac_cv_path_CPPUNIT_CONFIG="$CPPUNIT_CONFIG" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_CPPUNIT_CONFIG="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
test -z "$ac_cv_path_CPPUNIT_CONFIG" && ac_cv_path_CPPUNIT_CONFIG="no"
;;
esac
fi
CPPUNIT_CONFIG=$ac_cv_path_CPPUNIT_CONFIG
if test -n "$CPPUNIT_CONFIG"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPPUNIT_CONFIG" >&5
$as_echo "$CPPUNIT_CONFIG" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
cppunit_version_min=1.8.0
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Cppunit - version >= $cppunit_version_min" >&5
$as_echo_n "checking for Cppunit - version >= $cppunit_version_min... " >&6; }
no_cppunit=""
if test "$CPPUNIT_CONFIG" = "no" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
no_cppunit=yes
else
CPPUNIT_CFLAGS=`$CPPUNIT_CONFIG --cflags`
CPPUNIT_LIBS=`$CPPUNIT_CONFIG --libs`
cppunit_version=`$CPPUNIT_CONFIG --version`
cppunit_major_version=`echo $cppunit_version | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'`
cppunit_minor_version=`echo $cppunit_version | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'`
cppunit_micro_version=`echo $cppunit_version | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'`
cppunit_major_min=`echo $cppunit_version_min | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'`
cppunit_minor_min=`echo $cppunit_version_min | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'`
cppunit_micro_min=`echo $cppunit_version_min | \
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'`
cppunit_version_proper=`expr \
$cppunit_major_version \> $cppunit_major_min \| \
$cppunit_major_version \= $cppunit_major_min \& \
$cppunit_minor_version \> $cppunit_minor_min \| \
$cppunit_major_version \= $cppunit_major_min \& \
$cppunit_minor_version \= $cppunit_minor_min \& \
$cppunit_micro_version \>= $cppunit_micro_min `
if test "$cppunit_version_proper" = "1" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cppunit_major_version.$cppunit_minor_version.$cppunit_micro_version" >&5
$as_echo "$cppunit_major_version.$cppunit_minor_version.$cppunit_micro_version" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
no_cppunit=yes
fi
fi
if test "x$no_cppunit" = x ; then
SUBDIRS="$SUBDIRS tests"
else
CPPUNIT_CFLAGS=""
CPPUNIT_LIBS=""
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CPPUNIT" >&5
$as_echo_n "checking for CPPUNIT... " >&6; }
if test -n "$PKG_CONFIG"; then
if test -n "$CPPUNIT_CFLAGS"; then
pkg_cv_CPPUNIT_CFLAGS="$CPPUNIT_CFLAGS"
else
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"cppunit >= 1.8.0\""; } >&5
($PKG_CONFIG --exists --print-errors "cppunit >= 1.8.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_CPPUNIT_CFLAGS=`$PKG_CONFIG --cflags "cppunit >= 1.8.0" 2>/dev/null`
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
fi
if test -n "$PKG_CONFIG"; then
if test -n "$CPPUNIT_LIBS"; then
pkg_cv_CPPUNIT_LIBS="$CPPUNIT_LIBS"
else
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"cppunit >= 1.8.0\""; } >&5
($PKG_CONFIG --exists --print-errors "cppunit >= 1.8.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_CPPUNIT_LIBS=`$PKG_CONFIG --libs "cppunit >= 1.8.0" 2>/dev/null`
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
fi
if test $pkg_failed = yes; then
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
_pkg_short_errors_supported=yes
else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
CPPUNIT_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "cppunit >= 1.8.0"`
else
CPPUNIT_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "cppunit >= 1.8.0"`
fi
# Put the nasty error message in config.log where it belongs
echo "$CPPUNIT_PKG_ERRORS" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cppunit not found" >&5
$as_echo "$as_me: WARNING: cppunit not found" >&2;}
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cppunit not found" >&5
$as_echo "$as_me: WARNING: cppunit not found" >&2;}
else
CPPUNIT_CFLAGS=$pkg_cv_CPPUNIT_CFLAGS
CPPUNIT_LIBS=$pkg_cv_CPPUNIT_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SUBDIRS="$SUBDIRS tests"
fi
fi
SUBDIRS="$SUBDIRS tests"
for subdir in $SUBDIRS; do
if test -d ${srcdir}/${subdir} ; then