From b3aeba684b4e27e9fdf2c07949750bb567e40d6b Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 19 Feb 2015 09:38:01 +0100 Subject: [PATCH] Unit tests must be done at integration process. * Remove --enable-unittests and --disable-unittests and add --do-unittests function * --do-unittests function will exit 0 on success. * minetest and minetestserver binaries are launched with --do-unittests in travis build. --- src/CMakeLists.txt | 6 +++++- src/main.cpp | 23 ++++------------------- src/test.cpp | 14 +++++++------- util/travis/script.sh | 6 +++++- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 929dbacad..ce1cc30bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -355,6 +355,10 @@ add_subdirectory(jthread) add_subdirectory(script) add_subdirectory(util) +set (unittests_SRCS + test.cpp +) + set(common_SRCS ban.cpp base64.cpp @@ -422,7 +426,6 @@ set(common_SRCS sound.cpp staticobject.cpp subgame.cpp - test.cpp tool.cpp treegen.cpp version.cpp @@ -435,6 +438,7 @@ set(common_SRCS ${JTHREAD_SRCS} ${common_SCRIPT_SRCS} ${UTIL_SRCS} + ${unittests_SRCS} ) # This gives us the icon and file version information diff --git a/src/main.cpp b/src/main.cpp index 092fa9e17..33cb34f68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,19 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifdef NDEBUG - /*#ifdef _WIN32 - #pragma message ("Disabling unit tests") - #else - #warning "Disabling unit tests" - #endif*/ - // Disable unit tests - #define ENABLE_TESTS 0 -#else - // Enable unit tests - #define ENABLE_TESTS 1 -#endif - #ifdef _MSC_VER #ifndef SERVER // Dedicated server isn't linked with Irrlicht #pragma comment(lib, "Irrlicht.lib") @@ -279,9 +266,9 @@ int main(int argc, char *argv[]) #ifndef __ANDROID__ // Run unit tests - if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false) - || cmd_args.getFlag("enable-unittests") == true) { + if (cmd_args.getFlag("do-unittests")) { run_tests(); + return 0; } #endif @@ -352,10 +339,8 @@ static void set_allowed_options(OptionList *allowed_options) _("Load configuration from specified file")))); allowed_options->insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING, _("Set network port (UDP)")))); - allowed_options->insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG, - _("Disable unit tests")))); - allowed_options->insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG, - _("Enable unit tests")))); + allowed_options->insert(std::make_pair("do-unittests", ValueSpec(VALUETYPE_FLAG, + _("Run the unit tests and exit")))); allowed_options->insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING, _("Same as --world (deprecated)")))); allowed_options->insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING, diff --git a/src/test.cpp b/src/test.cpp index d8ab6336f..40943035d 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -2132,9 +2132,9 @@ void run_tests() TEST(TestCollision); if(INTERNET_SIMULATOR == false){ TEST(TestSocket); - dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<