Introduce unit tests for automated testing

The first one is a test for sokoke_magic_uri and
it already helped improving the function.
This commit is contained in:
Christian Dywan 2008-11-14 02:46:23 +01:00
parent 0b16997f1a
commit 7863d0f7fd
2 changed files with 24 additions and 3 deletions

View file

@ -88,9 +88,9 @@ sokoke_magic_uri (const gchar* uri,
{ {
gchar* current_dir; gchar* current_dir;
gchar* result; gchar* result;
gchar** parts;
gchar* search; gchar* search;
const gchar* search_uri; const gchar* search_uri;
gchar** parts;
KatzeItem* item; KatzeItem* item;
g_return_val_if_fail (uri, NULL); g_return_val_if_fail (uri, NULL);
@ -114,8 +114,17 @@ sokoke_magic_uri (const gchar* uri,
if (!strstr (uri, "://")) if (!strstr (uri, "://"))
{ {
/* Do we have a domain, ip address or localhost? */ /* Do we have a domain, ip address or localhost? */
if (strchr (uri, '.') != NULL || strchr (uri, ':') parts = g_strsplit (uri, ".", 0);
|| !strcmp (uri, "localhost")) if (parts[0] && parts[1])
{
search = NULL;
if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0])))
search = g_strconcat ("http://", uri, NULL);
g_free (parts);
if (search)
return search;
}
if (strchr (uri, ':') || !strcmp (uri, "localhost"))
return g_strconcat ("http://", uri, NULL); return g_strconcat ("http://", uri, NULL);
/* We don't want to search? So return early. */ /* We don't want to search? So return early. */
if (!search_engines) if (!search_engines)

12
wscript
View file

@ -7,6 +7,7 @@ import pproc as subprocess
import Common import Common
import sys import sys
import os import os
import UnitTest
APPNAME = 'midori' APPNAME = 'midori'
VERSION = '0.1.0' VERSION = '0.1.0'
@ -224,6 +225,9 @@ def build (bld):
else: else:
Params.pprint ('BLUE', "logo-shade could not be rasterized.") Params.pprint ('BLUE', "logo-shade could not be rasterized.")
if Params.g_commands['check']:
bld.add_subdirs ('tests')
def shutdown (): def shutdown ():
if Params.g_commands['install'] or Params.g_commands['uninstall']: if Params.g_commands['install'] or Params.g_commands['uninstall']:
dir = Common.path_install ('DATADIR', 'icons/hicolor') dir = Common.path_install ('DATADIR', 'icons/hicolor')
@ -242,6 +246,14 @@ def shutdown ():
Params.pprint ('YELLOW', "Icon cache not updated. After install, run this:") Params.pprint ('YELLOW', "Icon cache not updated. After install, run this:")
Params.pprint ('YELLOW', "gtk-update-icon-cache -q -f -t %s" % dir) Params.pprint ('YELLOW', "gtk-update-icon-cache -q -f -t %s" % dir)
elif Params.g_commands['check']:
test = UnitTest.unit_test ()
test.change_to_testfile_dir = True
test.want_to_see_test_output = True
test.want_to_see_test_error = True
test.run ()
test.print_results ()
elif Params.g_options.update_po: elif Params.g_options.update_po:
os.chdir('./po') os.chdir('./po')
try: try: