Browse Source

Ticket #3708: fix usability problems with `--enable-tests`

Signed-off-by: Mooffie <mooffie@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Mooffie 8 years ago
parent
commit
4a559344fb
4 changed files with 49 additions and 8 deletions
  1. 2 3
      configure.ac
  2. 21 4
      m4.include/mc-tests.m4
  3. 1 1
      tests/Makefile.am
  4. 25 0
      tests/README

+ 2 - 3
configure.ac

@@ -628,8 +628,7 @@ intl/Makefile
 po/Makefile.in
 ])
 
-if test x$enable_tests != xno; then
-    AC_CONFIG_FILES([
+AC_CONFIG_FILES([
 tests/Makefile
 tests/lib/Makefile
 tests/lib/mcconfig/Makefile
@@ -645,7 +644,6 @@ tests/src/vfs/Makefile
 tests/src/vfs/extfs/Makefile
 tests/src/vfs/extfs/helpers-list/Makefile
 ])
-fi
 
 AC_OUTPUT
 
@@ -657,6 +655,7 @@ Configuration:
   Compiler:                   ${CC}
   Compiler flags:             ${CFLAGS}
   Assertions:                 ${enable_assert}
+  Unit tests:                 ${tests_msg}
   File system:                ${vfs_type}
                               ${vfs_flags}
   Screen library:             ${screen_msg}

+ 21 - 4
m4.include/mc-tests.m4

@@ -11,15 +11,32 @@ AC_DEFUN([mc_UNIT_TESTS],[
 
     AC_ARG_ENABLE(
         [tests],
-        AS_HELP_STRING([--enable-tests], [Enable unit tests (see http://check.sourceforge.net/)])
+        AS_HELP_STRING([--enable-tests], [Enable unit tests (see http://libcheck.github.io/check/) @<:@auto@:>@])
     )
 
-    if test x$enable_tests != xno; then
+    dnl 'tests_msg' holds the human-readable message to show in configure's summary text.
+
+    if test x$enable_tests == xno; then
+        dnl The user explicitly specified '--disable-tests'.
+        tests_msg="no"
+    else
         PKG_CHECK_MODULES(
             CHECK,
             [check >= 0.9.8],
-            [have_check=yes],
-            [AC_MSG_WARN(['Check' utility not found. Check your environment])])
+            [
+                have_check=yes
+                tests_msg="yes"
+            ],
+            [
+                AC_MSG_WARN(['Check' testing framework not found. Check your environment])
+                tests_msg="no ('Check' testing framework not found)"
+
+                dnl The following behavior, of "exit if feature requested but not found", is just a
+                dnl preference and can be safely removed.
+                if test x$enable_tests == xyes; then
+                    AC_MSG_ERROR([You explicitly specified '--enable-tests', but this requirement cannot be met.])
+                fi
+            ])
         AC_SUBST(CHECK_CFLAGS)
         AC_SUBST(CHECK_LIBS)
     fi

+ 1 - 1
tests/Makefile.am

@@ -1,3 +1,3 @@
 SUBDIRS = lib src
 
-EXTRA_DIST = mctest.h
+EXTRA_DIST = mctest.h README

+ 25 - 0
tests/README

@@ -0,0 +1,25 @@
+Overview
+--------
+
+This tree contains unit tests.
+
+To compile and run the tests, do 'make check' (either in the top folder,
+or just in the folder containing the tests you're interested in).
+
+IMPORTANT: To compile the tests, you need to have the "Check" unit
+testing framework[1] installed.[2] If you have it installed, you will see
+"Unit tests: yes" in configure's summary message; if you don't see this
+message, you won't be able to compile the tests.[3]
+
+Tips and tricks
+---------------
+
+* To be able to step with the debugger into test code, see [4]. E.g., do:
+
+    $ export CK_FORK=no
+
+[1]: http://libcheck.github.io/check/
+[2]: Your package manager likely has it.
+[3]: Actually, some tests (like src/vfs/extfs/helpers-list) don't use
+     this framework and will compile just fine. But that's the exception.
+[4]: http://stackoverflow.com/questions/1649814/debugging-unit-test-in-c-using-check