Unit tests must be done at integration process.
authorLoic Blot <loic.blot@unix-experience.fr>
Thu, 19 Feb 2015 08:38:01 +0000 (09:38 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Sat, 21 Feb 2015 10:04:19 +0000 (11:04 +0100)
* 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
src/main.cpp
src/test.cpp
util/travis/script.sh

index 929dbacadd91e36a5c50c2ed6aa9e33bcdc0316e..ce1cc30bfca34d16eb4fd83ddfda508a39469f3a 100644 (file)
@@ -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
index 092fa9e1797ae58f895c21acb9bb24e08a2f9c2f..33cb34f68fbbb900c8b3dd14bc407254813e2dfb 100644 (file)
@@ -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,
index d8ab6336ff75e05868bd35cf252b6e58454bd521..40943035d1287404acf382463fee4416ed0f6377 100644 (file)
@@ -2132,9 +2132,9 @@ void run_tests()
        TEST(TestCollision);
        if(INTERNET_SIMULATOR == false){
                TEST(TestSocket);
-               dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
+               dout_con << "=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ===" << std::endl;
                TEST(TestConnection);
-               dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
+               dout_con << "=== END RUNNING UNIT TESTS FOR CONNECTION ===" << std::endl;
        }
 
        log_set_lev_silence(LMT_ERROR, false);
@@ -2142,13 +2142,13 @@ void run_tests()
        delete idef;
        delete ndef;
 
-       if(tests_failed == 0){
-               infostream<<"run_tests(): "<<tests_failed<<" / "<<tests_run<<" tests failed."<<std::endl;
-               infostream<<"run_tests() passed."<<std::endl;
+       if(tests_failed == 0) {
+               actionstream << "run_tests(): " << tests_failed << " / " << tests_run << " tests failed." << std::endl;
+               actionstream << "run_tests() passed." << std::endl;
                return;
        } else {
-               errorstream<<"run_tests(): "<<tests_failed<<" / "<<tests_run<<" tests failed."<<std::endl;
-               errorstream<<"run_tests() aborting."<<std::endl;
+               errorstream << "run_tests(): " << tests_failed << " / " << tests_run << " tests failed." << std::endl;
+               errorstream << "run_tests() aborting." << std::endl;
                abort();
        }
 }
index c37816cee1333569bad814aa26c30b55faf12cf0..437cf1ac524b1cc28101063ac00600639240cd63 100755 (executable)
@@ -3,8 +3,12 @@
 if [ $WINDOWS = "no" ]; then
        mkdir -p travisbuild
        cd travisbuild
-       cmake -DENABLE_GETTEXT=1 -DENABLE_LEVELDB=1 -DENABLE_REDIS=1 ..
+       cmake -DENABLE_GETTEXT=1 -DENABLE_LEVELDB=1 -DENABLE_REDIS=1 -DCMAKE_BUILD_TYPE=Debug ..
        make -j2
+       echo "Running unit tests for minetest"
+       ../bin/minetest --do-unittests
+       echo "Running unit tests for minetestserver"
+       ../bin/minetestserver --do-unittests
 else
        [ $CC = "clang" ] && exit 1 # Not supposed to happen
        # We need to have our build directory outside of the minetest directory because