← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/regression_testing into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/regression_testing into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/regression_testing/+merge/178000
-- 
https://code.launchpad.net/~widelands-dev/widelands/regression_testing/+merge/178000
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/regression_testing into lp:widelands.
=== renamed directory 'test' => 'manual_test'
=== added file 'regression_test.py'
--- regression_test.py	1970-01-01 00:00:00 +0000
+++ regression_test.py	2013-08-01 05:33:30 +0000
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import os
+
+from test import WidelandsTestCase
+
+class LuaTestSuiteInGame(WidelandsTestCase):
+    def runTest(self):
+        self.run_widelands(scenario=os.path.join(self.maps_dir, "lua_testsuite.wmf"))
+
+class LuaTestSuiteInEditor(WidelandsTestCase):
+    def runTest(self):
+        self.run_widelands(editor=os.path.join(self.maps_dir, "lua_testsuite.wmf"))
+

=== modified file 'src/io/filesystem/disk_filesystem.cc'
--- src/io/filesystem/disk_filesystem.cc	2013-07-30 09:23:23 +0000
+++ src/io/filesystem/disk_filesystem.cc	2013-08-01 05:33:30 +0000
@@ -20,7 +20,7 @@
 #include "io/filesystem/disk_filesystem.h"
 
 #include <cassert>
-#include <cerrno>
+#include <cerrno>
 
 #include <sys/stat.h>
 
@@ -201,8 +201,6 @@
 FileSystem * RealFSImpl::MakeSubFileSystem(const std::string & path) {
 	FileSystemPath fspath(FS_CanonicalizeName(path));
 	assert(fspath.m_exists); //TODO: throw an exception instead
-	//printf("RealFSImpl MakeSubFileSystem path %s fullname %s\n",
-	//path.c_str(), fspath.c_str());
 
 	if (fspath.m_isDirectory)
 		return new RealFSImpl   (fspath);

=== modified file 'src/io/filesystem/layered_filesystem.cc'
--- src/io/filesystem/layered_filesystem.cc	2013-07-26 20:19:36 +0000
+++ src/io/filesystem/layered_filesystem.cc	2013-08-01 05:33:30 +0000
@@ -406,7 +406,6 @@
 		if ((*it)->IsWritable() and (*it)->FileExists(dirname))
 			return (*it)->MakeSubFileSystem(dirname);
 
-	printf("dirname %s\n", dirname.c_str());
 	throw wexception("LayeredFileSystem: unable to create sub filesystem");
 }
 
@@ -425,7 +424,6 @@
 		if ((*it)->IsWritable() and not (*it)->FileExists(dirname))
 			return (*it)->CreateSubFileSystem(dirname, type);
 
-	printf("dirname %s\n", dirname.c_str());
 	throw wexception("LayeredFileSystem: unable to create sub filesystem");
 }
 

=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2013-07-26 20:19:36 +0000
+++ src/logic/game.cc	2013-08-01 05:33:30 +0000
@@ -221,7 +221,7 @@
 	set_map(new Map);
 
 	std::unique_ptr<Map_Loader> maploader(map().get_correct_loader(mapname));
-	if (not maploader.get())
+	if (!maploader)
 		throw wexception("could not load \"%s\"", mapname);
 	UI::ProgressWindow loaderUI;
 

=== modified file 'src/logic/map.cc'
--- src/logic/map.cc	2013-07-31 18:17:53 +0000
+++ src/logic/map.cc	2013-08-01 05:33:30 +0000
@@ -22,6 +22,8 @@
 #include <algorithm>
 #include <cstdio>
 
+#include <boost/algorithm/string/predicate.hpp>
+
 #include "economy/flag.h"
 #include "economy/road.h"
 #include "editor/tools/editor_increase_resources_tool.h"
@@ -1670,16 +1672,10 @@
 	}
 }
 
-/**
- * Returns the correct initialized loader for the given mapfile
-*/
-Map_Loader * Map::get_correct_loader(char const * const filename) {
-	Map_Loader * result = 0;
+Map_Loader * Map::get_correct_loader(const std::string& filename) {
+	Map_Loader * result = nullptr;
 
-	if
-		(!
-		 strcasecmp
-		 	(filename + (strlen(filename) - strlen(WLMF_SUFFIX)), WLMF_SUFFIX))
+	if (boost::algorithm::ends_with(filename, WLMF_SUFFIX)) {
 		try {
 			result = new WL_Map_Loader(*g_fs->MakeSubFileSystem(filename), this);
 		} catch (...) {
@@ -1687,16 +1683,13 @@
 			//  format)
 			//  TODO: catchall hides real errors! Replace with more specific code
 		}
-	else if
-		(!
-		 strcasecmp
-		 	(filename + (strlen(filename) - strlen(S2MF_SUFFIX)), S2MF_SUFFIX)
-		 |
-		 !
-		 strcasecmp
-		 	(filename + (strlen(filename) - strlen(S2MF_SUFFIX2)), S2MF_SUFFIX2))
+	} else if
+		(boost::algorithm::ends_with(filename, S2MF_SUFFIX) ||
+		 boost::algorithm::ends_with(filename, S2MF_SUFFIX2))
+	{
 		//  It is a S2 Map file. Load it as such.
-		result = new S2_Map_Loader(filename, *this);
+		result = new S2_Map_Loader(filename.c_str(), *this);
+	}
 
 	return result;
 }

=== modified file 'src/logic/map.h'
--- src/logic/map.h	2013-07-26 20:19:36 +0000
+++ src/logic/map.h	2013-08-01 05:33:30 +0000
@@ -154,8 +154,9 @@
 	const Overlay_Manager & overlay_manager() const {return *m_overlay_manager;}
 	Overlay_Manager       & overlay_manager()       {return *m_overlay_manager;}
 
-	//  for loading
-	Map_Loader * get_correct_loader(char const *);
+	/// Returns the correct initialized loader for the given mapfile
+	Map_Loader* get_correct_loader(const std::string& filename);
+
 	void cleanup();
 
 	void create_empty_map // for editor

=== modified file 'src/logic/worker_descr.cc'
--- src/logic/worker_descr.cc	2013-07-26 20:19:36 +0000
+++ src/logic/worker_descr.cc	2013-08-01 05:33:30 +0000
@@ -33,9 +33,6 @@
 #include "sound/sound_handler.h"
 #include "wexception.h"
 
-// NOCOM(#sirver): is this really needed?
-// #include <scripting/pdep/llimits.h>
-
 namespace Widelands {
 
 Worker_Descr::Worker_Descr

=== added directory 'test'
=== added file 'test/__init__.py'
--- test/__init__.py	1970-01-01 00:00:00 +0000
+++ test/__init__.py	2013-08-01 05:33:30 +0000
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+"""
+Classes and utilities for Widelands Regression testing.
+"""
+
+import os
+import subprocess
+import tempfile
+import unittest
+
+class WidelandsTestCase(unittest.TestCase):
+    def setUp(self):
+        self.maps_dir = os.path.join(".", "test", "__maps__")
+        self.home_dir = tempfile.mkdtemp(prefix="widelands_regression_test")
+
+    def tearDown(self):
+        # NOCOM(#sirver): should clean up on success, bark on error.
+        print "Tear down called!"
+
+    def run_widelands(self, **kwargs):
+        """Runs widelands with the arguments given, catching stdout and stderr in files."""
+
+        stdout_filename = os.path.join(self.home_dir, "stdout.txt")
+        stderr_filename = os.path.join(self.home_dir, "stderr.txt")
+
+        print "#sirver stdout_filename: %r\n" % (stdout_filename)
+        with open(stdout_filename, 'w') as stdout_file, open(stderr_filename, 'w') as stderr_file:
+            # NOCOM(#sirver): shoud ignore config files.
+            # NOCOM(#sirver): hard coded
+            args = ["../widelands.build/src/widelands", '--datadir=.', '--homedir=%s' % self.home_dir]
+            args += [ "--%s=%s" % (key, value) for key, value in kwargs.iteritems() ]
+
+            widelands = subprocess.Popen(args, shell=False, stdout=stdout_file, stderr=stderr_file)
+            widelands.communicate()
+        self.assertEqual(widelands.returncode, 0)

=== added directory 'test/__maps__'
=== renamed directory 'test/lua/persistence.wmf' => 'test/__maps__/lua_persistence.wmf'
=== renamed directory 'test/lua/ts.wmf' => 'test/__maps__/lua_testsuite.wmf'
=== added file 'test/lua_persistence.py'
--- test/lua_persistence.py	1970-01-01 00:00:00 +0000
+++ test/lua_persistence.py	2013-08-01 05:33:30 +0000
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import os
+
+from test import WidelandsTestCase
+
+class LuaPersistence(WidelandsTestCase):
+    def runTest(self):
+        self.run_widelands(scenario=os.path.join(self.maps_dir, "lua_persistence.wmf"))
+        self.run_widelands(loadgame=os.path.join("save", "lua_persistence.wgf"))
+        pass
+
+
+

=== added file 'test/lua_testsuite.py'
--- test/lua_testsuite.py	1970-01-01 00:00:00 +0000
+++ test/lua_testsuite.py	2013-08-01 05:33:30 +0000
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+import os
+
+from test import WidelandsTestCase
+
+class LuaTestsuiteInGame(WidelandsTestCase):
+    def runTest(self):
+        self.run_widelands(scenario=os.path.join(self.maps_dir, "lua_testsuite.wmf"))
+
+class LuaTestsuiteInEditor(WidelandsTestCase):
+    def runTest(self):
+        self.run_widelands(editor=os.path.join(self.maps_dir, "lua_testsuite.wmf"))
+
+


Follow ups