[gitg] Add tests for Gitg.RefActionCheckout
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Add tests for Gitg.RefActionCheckout
- Date: Thu, 13 Aug 2015 06:20:37 +0000 (UTC)
commit 68e50b4185c1dca5474fba6f03665a98285a9768
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Thu Aug 13 08:14:24 2015 +0200
Add tests for Gitg.RefActionCheckout
tests/Makefile | 8 ++-
tests/Makefile.am | 5 +
tests/gitg/Makefile | 3 +
tests/gitg/Makefile.am | 64 +++++++++++
tests/gitg/application-mock.vala | 107 ++++++++++++++++++
tests/{libgitg/test.vala => gitg/main.vala} | 21 +---
.../test.vala => gitg/notifications-mock.vala} | 26 +++--
.../ref-action-interface-mock.vala} | 37 +++++--
.../simple-notification-mock.vala} | 40 +++++--
tests/gitg/test-checkout-ref.vala | 105 ++++++++++++++++++
tests/libgitg/Makefile.am | 33 ++++---
tests/libgitg/main.vala | 85 ++-------------
tests/libgitg/test-commit.vala | 18 ++--
tests/libgitg/test-date.vala | 2 +-
tests/libgitg/test-encoding.vala | 4 +-
tests/libgitg/test-stage.vala | 2 +-
tests/{libgitg => support}/gitg-assert.h | 0
tests/{libgitg => support}/gitg-assert.vapi | 0
tests/support/main.vala | 115 ++++++++++++++++++++
tests/{libgitg => support}/repository.vala | 67 ++++++++++--
tests/{libgitg => support}/test.vala | 20 ++++
21 files changed, 604 insertions(+), 158 deletions(-)
---
diff --git a/tests/Makefile b/tests/Makefile
index d8d1086..e8d3855 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,2 +1,8 @@
-TARGETS = tests/diff-view tests/progress-bin tests/repository-list-box tests/libgitg/test-libgitg
+TARGETS = \
+ tests/diff-view \
+ tests/progress-bin \
+ tests/repository-list-box \
+ tests/libgitg/test-libgitg \
+ tests/gitg/test-gitg
+
include ../sub.mk
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1fd7d6d..eb74328 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,5 +40,10 @@ tests_progress_bin_CPPFLAGS = $(tests_common_cppflags)
tests_progress_bin_LDADD = libgitg/libgitg-1.0.la $(tests_common_ldadd)
include tests/libgitg/Makefile.am
+include tests/gitg/Makefile.am
+
+EXTRA_DIST += \
+ tests/support/gitg-assert.h \
+ tests/support/gitg-assert.vapi
# vi:ts=8:noet
diff --git a/tests/gitg/Makefile b/tests/gitg/Makefile
new file mode 100644
index 0000000..a620f70
--- /dev/null
+++ b/tests/gitg/Makefile
@@ -0,0 +1,3 @@
+TARGETS = tests/gitg/test-gitg
+
+include ../../sub.mk
diff --git a/tests/gitg/Makefile.am b/tests/gitg/Makefile.am
new file mode 100644
index 0000000..46ef18f
--- /dev/null
+++ b/tests/gitg/Makefile.am
@@ -0,0 +1,64 @@
+TESTS_GITG_PROGS = tests/gitg/test-gitg
+
+TESTS += $(TESTS_GITG_PROGS)
+noinst_PROGRAMS += $(TESTS_GITG_PROGS)
+
+tests_gitg_test_gitg_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/gitg \
+ -I$(top_srcdir)/libgitg \
+ -I$(top_srcdir)/tests/support
+
+tests_gitg_test_gitg_VALAFLAGS = \
+ --pkg posix \
+ --pkg gitg-assert \
+ --pkg Ggit-1.0 \
+ --pkg gio-2.0 \
+ --pkg gtk+-3.0 \
+ --pkg gee-0.8 \
+ --pkg libsoup-2.4 \
+ --pkg $(WEBKIT_PKGCONFIG) \
+ --pkg config \
+ $(GITG_VALAFLAGS) \
+ --vapidir $(top_srcdir)/tests/support \
+ --vapidir $(top_srcdir)/vapi \
+ --disable-warnings
+
+tests_gitg_test_gitg_CFLAGS = \
+ $(GITG_DEBUG_FLAGS) \
+ $(GITG_CFLAGS) \
+ $(LIBGITG_CFLAGS) \
+ $(LIBGITG_EXT_CFLAGS) \
+ -g \
+ -w
+
+tests_gitg_test_gitg_LDADD = \
+ libgitg/libgitg-1.0.la \
+ libgitg-ext/libgitg-ext-1.0.la \
+ $(LIBGITG_LIBS)
+
+tests/gitg/support-%.vala: tests/support/%.vala
+ cp "$<" "$@"
+
+tests/gitg/gitg-%.vala: gitg/gitg-%.vala
+ cp "$<" "$@"
+
+TESTS_GITG_TEST_GITG_COPIED_SOURCES = \
+ tests/gitg/support-test.vala \
+ tests/gitg/support-main.vala \
+ tests/gitg/support-repository.vala \
+ tests/gitg/gitg-ref-action-checkout.vala
+
+tests_gitg_test_gitg_SOURCES = \
+ tests/gitg/main.vala \
+ tests/gitg/test-checkout-ref.vala \
+ tests/gitg/simple-notification-mock.vala \
+ tests/gitg/application-mock.vala \
+ tests/gitg/notifications-mock.vala \
+ tests/gitg/ref-action-interface-mock.vala \
+ $(TESTS_GITG_TEST_GITG_COPIED_SOURCES) \
+ $(GITG_PLUGIN_VAPISOURCES)
+
+CLEANFILES += $(TESTS_GITG_TEST_GITG_COPIED_SOURCES)
+
+# vi:ts=8:noet
diff --git a/tests/gitg/application-mock.vala b/tests/gitg/application-mock.vala
new file mode 100644
index 0000000..452e3c6
--- /dev/null
+++ b/tests/gitg/application-mock.vala
@@ -0,0 +1,107 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2015 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gitg.Test.Assert;
+
+class Gitg.Test.Application : Gitg.Test.Repository, GitgExt.Application
+{
+ private Notifications d_notifications;
+
+ public Application()
+ {
+ d_notifications = new Notifications();
+ }
+
+ protected override void set_up()
+ {
+ base.set_up();
+
+ d_notifications = new Notifications();
+ }
+
+ public Gitg.Repository? repository
+ {
+ owned get { return d_repository; }
+ set {}
+ }
+
+ public GitgExt.MessageBus message_bus { owned get { return null; } }
+ public GitgExt.Activity? current_activity { owned get { return null; } }
+ public Gee.Map<string, string> environment { owned get { return new Gee.HashMap<string, string>(); } }
+
+ public Ggit.Signature? get_verified_committer()
+ {
+ try
+ {
+ return new Ggit.Signature("test", "test test test", new DateTime.from_unix_utc(0));
+ }
+ catch (Error e)
+ {
+ assert_no_error(e);
+ return null;
+ }
+ }
+
+ public Gee.ArrayList<SimpleNotification> simple_notifications
+ {
+ owned get
+ {
+ var ret = new Gee.ArrayList<SimpleNotification>();
+
+ foreach (var notification in d_notifications.notifications)
+ {
+ ret.add(notification as SimpleNotification);
+ }
+
+ return ret;
+ }
+ }
+
+ public GitgExt.Notifications notifications { owned get { return d_notifications; } }
+ public GitgExt.Activity? get_activity_by_id(string id) { return null; }
+ public GitgExt.Activity? set_activity_by_id(string id) { return null; }
+
+ public void user_query(GitgExt.UserQuery query)
+ {
+ }
+
+ public async Gtk.ResponseType user_query_async(GitgExt.UserQuery query)
+ {
+ return Gtk.ResponseType.CLOSE;
+ }
+
+ public void show_infobar(string primary_msg,
+ string secondary_msg,
+ Gtk.MessageType type)
+ {
+ }
+
+ public bool busy { get { return false; } set {} }
+
+ public GitgExt.Application open_new(Ggit.Repository repository, string? hint = null)
+ {
+ return this;
+ }
+
+ public GitgExt.RemoteLookup remote_lookup { owned get { return null; } }
+
+ public void open_repository(File path) {}
+}
+
+// ex:set ts=4 noet
diff --git a/tests/libgitg/test.vala b/tests/gitg/main.vala
similarity index 73%
copy from tests/libgitg/test.vala
copy to tests/gitg/main.vala
index bbb3f91..9673d50 100644
--- a/tests/libgitg/test.vala
+++ b/tests/gitg/main.vala
@@ -17,26 +17,15 @@
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
-class Gitg.Test.Test : Object
+class Gitg.Test.Runner
{
- private GLib.TestSuite d_suite;
-
- construct
- {
- d_suite = new GLib.TestSuite(get_type().name());
- }
-
- public GLib.TestSuite suite
+ public static void main(string[] args)
{
- get { return d_suite; }
- }
+ var m = new Gitg.Test.Main(args);
- public virtual void set_up()
- {
- }
+ m.add(new CheckoutRef());
- public virtual void tear_down()
- {
+ m.run();
}
}
diff --git a/tests/libgitg/test.vala b/tests/gitg/notifications-mock.vala
similarity index 52%
copy from tests/libgitg/test.vala
copy to tests/gitg/notifications-mock.vala
index bbb3f91..e84f82a 100644
--- a/tests/libgitg/test.vala
+++ b/tests/gitg/notifications-mock.vala
@@ -1,7 +1,7 @@
/*
* This file is part of gitg
*
- * Copyright (C) 2013 - Jesse van den Kieboom
+ * Copyright (C) 2015 - Jesse van den Kieboom
*
* gitg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,26 +17,30 @@
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
-class Gitg.Test.Test : Object
+using Gitg.Test.Assert;
+
+class Gitg.Test.Notifications : Object, GitgExt.Notifications
{
- private GLib.TestSuite d_suite;
+ public signal void added(GitgExt.Notification notification);
+ public signal void removed(GitgExt.Notification notification);
- construct
- {
- d_suite = new GLib.TestSuite(get_type().name());
- }
+ public Gee.ArrayList<GitgExt.Notification> notifications;
- public GLib.TestSuite suite
+ public Notifications()
{
- get { return d_suite; }
+ notifications = new Gee.ArrayList<GitgExt.Notification>();
}
- public virtual void set_up()
+ public void add(GitgExt.Notification notification)
{
+ added(notification);
+ notifications.add(notification);
}
- public virtual void tear_down()
+ public void remove(GitgExt.Notification notification, uint delay = 0)
{
+ removed(notification);
+ notifications.remove(notification);
}
}
diff --git a/tests/libgitg/test.vala b/tests/gitg/ref-action-interface-mock.vala
similarity index 52%
copy from tests/libgitg/test.vala
copy to tests/gitg/ref-action-interface-mock.vala
index bbb3f91..c0de9c7 100644
--- a/tests/libgitg/test.vala
+++ b/tests/gitg/ref-action-interface-mock.vala
@@ -1,7 +1,7 @@
/*
* This file is part of gitg
*
- * Copyright (C) 2013 - Jesse van den Kieboom
+ * Copyright (C) 2015 - Jesse van den Kieboom
*
* gitg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,26 +17,45 @@
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
-class Gitg.Test.Test : Object
+using Gitg.Test.Assert;
+
+class Gitg.Test.RefActionInterface : Object, GitgExt.RefActionInterface
{
- private GLib.TestSuite d_suite;
+ public GitgExt.Application application { owned get; construct set; }
+
+ public RefActionInterface(GitgExt.Application application)
+ {
+ Object(application: application);
+ }
+
+ public void add_ref(Gitg.Ref reference)
+ {
+
+ }
- construct
+ public void remove_ref(Gitg.Ref reference)
{
- d_suite = new GLib.TestSuite(get_type().name());
+
+ }
+
+ public void replace_ref(Gitg.Ref old_ref, Gitg.Ref new_ref)
+ {
+
}
- public GLib.TestSuite suite
+ public void set_busy(Gitg.Ref reference, bool busy)
{
- get { return d_suite; }
+
}
- public virtual void set_up()
+ public void edit_ref_name(Gitg.Ref reference, owned GitgExt.RefNameEditingDone callback)
{
+
}
- public virtual void tear_down()
+ public void refresh()
{
+
}
}
diff --git a/tests/libgitg/test.vala b/tests/gitg/simple-notification-mock.vala
similarity index 50%
copy from tests/libgitg/test.vala
copy to tests/gitg/simple-notification-mock.vala
index bbb3f91..8416451 100644
--- a/tests/libgitg/test.vala
+++ b/tests/gitg/simple-notification-mock.vala
@@ -1,7 +1,7 @@
/*
* This file is part of gitg
*
- * Copyright (C) 2013 - Jesse van den Kieboom
+ * Copyright (C) 2012 - Ignacio Casal Quinteiro
*
* gitg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,27 +17,47 @@
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
-class Gitg.Test.Test : Object
+namespace Gitg
{
- private GLib.TestSuite d_suite;
- construct
+public class SimpleNotification : Object, GitgExt.Notification
+{
+ public enum Status
+ {
+ NONE,
+ SUCCESS,
+ ERROR
+ }
+
+ public signal void cancel();
+ public Status status;
+
+ public string title { get; set; }
+ public string message { get; set; }
+
+ public SimpleNotification(string? title = null, string? message = null)
{
- d_suite = new GLib.TestSuite(get_type().name());
+ Object(title: title, message: message);
}
- public GLib.TestSuite suite
+ public Gtk.Widget? widget
{
- get { return d_suite; }
+ owned get { return null; }
}
- public virtual void set_up()
+ public void success(string message)
{
+ this.message = message;
+ this.status = Status.SUCCESS;
}
- public virtual void tear_down()
+ public void error(string message)
{
+ this.message = message;
+ this.status = Status.ERROR;
}
}
-// ex:set ts=4 noet
+}
+
+// ex:ts=4 noet
diff --git a/tests/gitg/test-checkout-ref.vala b/tests/gitg/test-checkout-ref.vala
new file mode 100644
index 0000000..2cc9615
--- /dev/null
+++ b/tests/gitg/test-checkout-ref.vala
@@ -0,0 +1,105 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2015 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gitg.Test.Assert;
+
+class Gitg.Test.CheckoutRef : Application
+{
+ private Gitg.Branch the_branch;
+ private RefActionInterface action_interface;
+ private RefActionCheckout action;
+
+ protected override void set_up()
+ {
+ base.set_up();
+
+ commit("b", "staged changes\n");
+ commit("a", "lala\n");
+
+ the_branch = create_branch("thebranch");
+
+ commit("a", "changed?\n");
+
+ action_interface = new RefActionInterface(this);
+ action = new Gitg.RefActionCheckout(this, action_interface, the_branch);
+ }
+
+ /**
+ * test basic branch checkout.
+ */
+ protected virtual signal void test_checkout_branch()
+ {
+ var loop = new MainLoop();
+
+ action.checkout.begin((obj, res) => {
+ action.checkout.end(res);
+ loop.quit();
+ });
+
+ loop.run();
+
+ assert_inteq(simple_notifications.size, 1);
+ assert_streq(simple_notifications[0].title, "Checkout thebranch");
+ assert_inteq(simple_notifications[0].status, SimpleNotification.Status.SUCCESS);
+ assert_streq(simple_notifications[0].message, "Successfully checked out branch to working
directory");
+ assert_file_contents("a", "lala\n");
+ }
+
+ protected virtual signal void test_checkout_branch_safe()
+ {
+ write_file("b", "something changed\n");
+
+ var loop = new MainLoop();
+
+ action.checkout.begin((obj, res) => {
+ action.checkout.end(res);
+ loop.quit();
+ });
+
+ loop.run();
+
+ assert_inteq(simple_notifications.size, 1);
+ assert_streq(simple_notifications[0].title, "Checkout thebranch");
+ assert_inteq(simple_notifications[0].status, SimpleNotification.Status.SUCCESS);
+ assert_streq(simple_notifications[0].message, "Successfully checked out branch to working
directory");
+ assert_file_contents("b", "something changed\n");
+ }
+
+ protected virtual signal void test_checkout_branch_conflict()
+ {
+ write_file("a", "something changed\n");
+
+ var loop = new MainLoop();
+
+ action.checkout.begin((obj, res) => {
+ action.checkout.end(res);
+ loop.quit();
+ });
+
+ loop.run();
+
+ assert_inteq(simple_notifications.size, 1);
+ assert_streq(simple_notifications[0].title, "Checkout thebranch");
+ assert_inteq(simple_notifications[0].status, SimpleNotification.Status.ERROR);
+ assert_streq(simple_notifications[0].message, "Failed to checkout branch: 1 conflict prevents
checkout");
+ assert_file_contents("a", "something changed\n");
+ }
+}
+
+// ex:set ts=4 noet
diff --git a/tests/libgitg/Makefile.am b/tests/libgitg/Makefile.am
index d289270..1581031 100644
--- a/tests/libgitg/Makefile.am
+++ b/tests/libgitg/Makefile.am
@@ -7,7 +7,7 @@ tests_libgitg_test_libgitg_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/gitg \
-I$(top_srcdir)/libgitg \
- -I$(top_srcdir)/tests/libgitg
+ -I$(top_srcdir)/tests/support
tests_libgitg_test_libgitg_VALAFLAGS = \
--pkg posix \
@@ -20,7 +20,7 @@ tests_libgitg_test_libgitg_VALAFLAGS = \
--pkg $(WEBKIT_PKGCONFIG) \
--pkg config \
$(GITG_VALAFLAGS) \
- --vapidir $(top_srcdir)/tests/libgitg \
+ --vapidir $(top_srcdir)/tests/support \
--vapidir $(top_srcdir)/vapi \
--disable-warnings
@@ -35,18 +35,25 @@ tests_libgitg_test_libgitg_LDADD = \
libgitg/libgitg-1.0.la \
$(LIBGITG_LIBS)
-tests_libgitg_test_libgitg_SOURCES = \
- tests/libgitg/test.vala \
- tests/libgitg/main.vala \
- tests/libgitg/repository.vala \
- tests/libgitg/test-stage.vala \
- tests/libgitg/test-date.vala \
- tests/libgitg/test-commit.vala \
- tests/libgitg/test-encoding.vala \
+tests/libgitg/support-%.vala: tests/support/%.vala
+ cp "$<" "$@"
+
+TESTS_GITG_TEST_LIBGITG_COPIED_SOURCES = \
+ tests/libgitg/support-test.vala \
+ tests/libgitg/support-main.vala \
+ tests/libgitg/support-repository.vala
+
+tests_libgitg_test_libgitg_SOURCES = \
+ tests/libgitg/main.vala \
+ tests/libgitg/test-stage.vala \
+ tests/libgitg/test-date.vala \
+ tests/libgitg/test-commit.vala \
+ tests/libgitg/test-encoding.vala \
+ $(TESTS_GITG_TEST_LIBGITG_COPIED_SOURCES) \
$(GITG_PLUGIN_VAPISOURCES)
-EXTRA_DIST += \
- tests/libgitg/gitg-assert.h \
- tests/libgitg/gitg-assert.vapi
+CLEANFILES += \
+ $(TESTS_GITG_TEST_LIBGITG_COPIED_SOURCES) \
+ $(TESTS_GITG_TEST_LIBGITG_COPIED_SOURCES:%.vala=%.c)
# vi:ts=8:noet
diff --git a/tests/libgitg/main.vala b/tests/libgitg/main.vala
index 2b33ff3..7a2b5de 100644
--- a/tests/libgitg/main.vala
+++ b/tests/libgitg/main.vala
@@ -17,89 +17,18 @@
* along with gitg. If not, see <http://www.gnu.org/licenses/>.
*/
-class Gitg.Test.Main
+class LibGitg.Test.Main
{
- private static TestCase[] s_cases;
-
public static void main(string[] args)
{
- Gitg.init();
- GLib.Test.init(ref args);
-
- add(new Stage());
- add(new Date());
- add(new Commit());
- add(new Encoding());
-
- GLib.Test.run();
- }
-
- class TestCase : Object
- {
- private Gitg.Test.Test d_test;
- private string d_name;
- private uint d_signal_id;
-
- public TestCase(Gitg.Test.Test test, string name, uint signal_id)
- {
- d_test = test;
- d_name = name;
- d_signal_id = signal_id;
- }
-
- public string name
- {
- get { return d_name; }
- }
-
- public void set_up()
- {
- d_test.set_up();
- }
-
- public void tear_down()
- {
- d_test.tear_down();
- }
-
- public void test()
- {
- GLib.Signal.emit(d_test, d_signal_id, 0);
- }
- }
-
- private static void add(Test test)
- {
- var ids = GLib.Signal.list_ids(test.get_type());
-
- var suite = test.suite;
-
- GLib.TestSuite.get_root().add_suite(suite);
-
- foreach (var id in ids)
- {
- GLib.SignalQuery q;
-
- GLib.Signal.query(id, out q);
-
- if (q.n_params != 0 || !q.signal_name.has_prefix("test-"))
- {
- continue;
- }
-
- var c = new TestCase(test,
- q.signal_name[5:q.signal_name.length],
- q.signal_id);
-
- s_cases += c;
+ var m = new Gitg.Test.Main(args);
- var tc = new GLib.TestCase(c.name,
- c.set_up,
- c.test,
- c.tear_down);
+ m.add(new Stage(),
+ new Date(),
+ new Commit(),
+ new Encoding());
- suite.add(tc);
- }
+ m.run();
}
}
diff --git a/tests/libgitg/test-commit.vala b/tests/libgitg/test-commit.vala
index 65c0473..e585077 100644
--- a/tests/libgitg/test-commit.vala
+++ b/tests/libgitg/test-commit.vala
@@ -19,7 +19,7 @@
using Gitg.Test.Assert;
-class Gitg.Test.Commit : Gitg.Test.Repository
+class LibGitg.Test.Commit : Gitg.Test.Repository
{
/**
* Create basic repository with files in a variety of states.
@@ -48,7 +48,7 @@ class Gitg.Test.Commit : Gitg.Test.Repository
stage.commit.begin(msg,
sig,
sig,
- StageCommitOptions.NONE, (obj, res) => {
+ Gitg.StageCommitOptions.NONE, (obj, res) => {
var oid = stage.commit.end(res);
var commit = d_repository.lookup<Gitg.Commit>(oid);
@@ -93,7 +93,7 @@ class Gitg.Test.Commit : Gitg.Test.Repository
stage.commit.begin(msg,
author,
sig,
- StageCommitOptions.SIGN_OFF, (obj, res) => {
+ Gitg.StageCommitOptions.SIGN_OFF, (obj, res) => {
var oid = stage.commit.end(res);
@@ -133,19 +133,19 @@ class Gitg.Test.Commit : Gitg.Test.Repository
"jessevdk gnome org");
stage.pre_commit_hook.begin(sig, (obj, res) => {
- StageError? e = null;
+ Gitg.StageError? e = null;
try
{
stage.pre_commit_hook.end(res);
}
- catch (StageError err)
+ catch (Gitg.StageError err)
{
e = err;
}
assert(e != null);
- assert(e is StageError.PRE_COMMIT_HOOK_FAILED);
+ assert(e is Gitg.StageError.PRE_COMMIT_HOOK_FAILED);
assert_streq(e.message, "pre-commit failed");
loop.quit();
@@ -173,7 +173,7 @@ class Gitg.Test.Commit : Gitg.Test.Repository
stage.commit.begin(msg,
sig,
sig,
- StageCommitOptions.NONE, (obj, res) => {
+ Gitg.StageCommitOptions.NONE, (obj, res) => {
var oid = stage.commit.end(res);
var commit = d_repository.lookup<Gitg.Commit>(oid);
@@ -204,7 +204,7 @@ class Gitg.Test.Commit : Gitg.Test.Repository
stage.commit.begin(msg,
sig,
sig,
- StageCommitOptions.SKIP_HOOKS, (obj, res) => {
+ Gitg.StageCommitOptions.SKIP_HOOKS, (obj, res) => {
var oid = stage.commit.end(res);
var commit = d_repository.lookup<Gitg.Commit>(oid);
@@ -235,7 +235,7 @@ class Gitg.Test.Commit : Gitg.Test.Repository
stage.commit.begin(msg,
headc.get_author(),
sig,
- StageCommitOptions.AMEND, (obj, res) => {
+ Gitg.StageCommitOptions.AMEND, (obj, res) => {
var oid = stage.commit.end(res);
var commit = d_repository.lookup<Gitg.Commit>(oid);
diff --git a/tests/libgitg/test-date.vala b/tests/libgitg/test-date.vala
index 1cb2e11..98db223 100644
--- a/tests/libgitg/test-date.vala
+++ b/tests/libgitg/test-date.vala
@@ -19,7 +19,7 @@
using Gitg.Test.Assert;
-class Gitg.Test.Date : Gitg.Test.Test
+class LibGitg.Test.Date : Gitg.Test.Test
{
protected virtual signal void test_iso8601()
{
diff --git a/tests/libgitg/test-encoding.vala b/tests/libgitg/test-encoding.vala
index 2848433..6172fe6 100644
--- a/tests/libgitg/test-encoding.vala
+++ b/tests/libgitg/test-encoding.vala
@@ -19,7 +19,7 @@
using Gitg.Test.Assert;
-class Gitg.Test.Encoding : Gitg.Test.Repository
+class LibGitg.Test.Encoding : Gitg.Test.Repository
{
/**
* Create basic repository with files in a variety of states.
@@ -50,7 +50,7 @@ class Gitg.Test.Encoding : Gitg.Test.Repository
stage.commit.begin(msg,
sig,
sig,
- StageCommitOptions.NONE, (obj, res) => {
+ Gitg.StageCommitOptions.NONE, (obj, res) => {
var oid = stage.commit.end(res);
var commit = d_repository.lookup<Gitg.Commit>(oid);
diff --git a/tests/libgitg/test-stage.vala b/tests/libgitg/test-stage.vala
index 9bd1175..1eed96f 100644
--- a/tests/libgitg/test-stage.vala
+++ b/tests/libgitg/test-stage.vala
@@ -19,7 +19,7 @@
using Gitg.Test.Assert;
-class Gitg.Test.Stage : Gitg.Test.Repository
+class LibGitg.Test.Stage : Gitg.Test.Repository
{
/**
* Create basic repository with files in a variety of states.
diff --git a/tests/libgitg/gitg-assert.h b/tests/support/gitg-assert.h
similarity index 100%
rename from tests/libgitg/gitg-assert.h
rename to tests/support/gitg-assert.h
diff --git a/tests/libgitg/gitg-assert.vapi b/tests/support/gitg-assert.vapi
similarity index 100%
rename from tests/libgitg/gitg-assert.vapi
rename to tests/support/gitg-assert.vapi
diff --git a/tests/support/main.vala b/tests/support/main.vala
new file mode 100644
index 0000000..3eda5c0
--- /dev/null
+++ b/tests/support/main.vala
@@ -0,0 +1,115 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class Gitg.Test.Main
+{
+ private TestCase[] d_cases;
+
+ public Main(string[] args)
+ {
+ Gitg.init();
+ GLib.Test.init(ref args);
+ }
+
+ public void run()
+ {
+ GLib.Test.run();
+ }
+
+ class TestCase : Object
+ {
+ private Gitg.Test.Test d_test;
+ private string d_name;
+ private uint d_signal_id;
+
+ public TestCase(Gitg.Test.Test test, string name, uint signal_id)
+ {
+ d_test = test;
+ d_name = name;
+ d_signal_id = signal_id;
+ }
+
+ public string name
+ {
+ get { return d_name; }
+ }
+
+ public void set_up()
+ {
+ d_test.set_up();
+ }
+
+ public void tear_down()
+ {
+ d_test.tear_down();
+ }
+
+ public void test()
+ {
+ GLib.Signal.emit(d_test, d_signal_id, 0);
+ }
+ }
+
+ public void add(...)
+ {
+ var l = va_list();
+ Test test;
+
+ while ((test = l.arg<Test>()) != null)
+ {
+ add_test(test);
+ }
+ }
+
+ public void add_test(Test test)
+ {
+ var ids = GLib.Signal.list_ids(test.get_type());
+
+ var suite = test.suite;
+
+ GLib.TestSuite.get_root().add_suite(suite);
+
+ foreach (var id in ids)
+ {
+ GLib.SignalQuery q;
+
+ GLib.Signal.query(id, out q);
+
+ if (q.n_params != 0 || !q.signal_name.has_prefix("test-"))
+ {
+ continue;
+ }
+
+ var c = new TestCase(test,
+ q.signal_name[5:q.signal_name.length],
+ q.signal_id);
+
+ d_cases += c;
+
+ var tc = new GLib.TestCase(c.name,
+ c.set_up,
+ c.test,
+ c.tear_down);
+
+ suite.add(tc);
+ }
+ }
+}
+
+// ex:set ts=4 noet
diff --git a/tests/libgitg/repository.vala b/tests/support/repository.vala
similarity index 81%
rename from tests/libgitg/repository.vala
rename to tests/support/repository.vala
index b1aeca2..6f6ca25 100644
--- a/tests/libgitg/repository.vala
+++ b/tests/support/repository.vala
@@ -66,6 +66,13 @@ class Gitg.Test.Repository : Gitg.Test.Test
return files;
}
+ public void assert_file_contents(string filename, string expected_contents)
+ {
+ var wd = d_repository.get_workdir();
+
+ Assert.assert_file_contents(Path.build_filename(wd.get_path(), filename), expected_contents);
+ }
+
private void write_files(File[] files)
{
var wd = d_repository.get_workdir();
@@ -87,6 +94,16 @@ class Gitg.Test.Repository : Gitg.Test.Test
}
}
+ protected void write_file(string filename, string contents)
+ {
+ write_files(new File[] {
+ File() {
+ filename = filename,
+ contents = contents
+ }
+ });
+ }
+
protected void commit(string? filename, ...)
{
if (d_repository == null)
@@ -154,7 +171,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
try
{
- tree = d_repository.lookup<Ggit.Tree>(treeoid);
+ tree = d_repository.lookup<Ggit.Tree>(treeoid);
}
catch (GLib.Error e)
{
@@ -294,6 +311,20 @@ class Gitg.Test.Repository : Gitg.Test.Test
}
}
+ protected Gitg.Branch? create_branch(string name)
+ {
+ try
+ {
+ var commit = d_repository.lookup<Gitg.Commit>(d_repository.get_head().get_target());
+ return d_repository.create_branch(name, commit, Ggit.CreateFlags.NONE);
+ }
+ catch (Error e)
+ {
+ assert_no_error(e);
+ return null;
+ }
+ }
+
protected override void set_up()
{
string wd;
@@ -323,6 +354,33 @@ class Gitg.Test.Repository : Gitg.Test.Test
}
}
+ private void remove_recursively(GLib.File f)
+ {
+ try
+ {
+ var info = f.query_info("standard::*", FileQueryInfoFlags.NONE);
+
+ if (info.get_file_type() == FileType.DIRECTORY)
+ {
+ var e = f.enumerate_children("standard::*", FileQueryInfoFlags.NONE);
+
+ while ((info = e.next_file()) != null)
+ {
+ var c = f.get_child(info.get_name());
+ remove_recursively(c);
+ }
+ }
+ else
+ {
+ f.delete();
+ }
+ }
+ catch (Error e)
+ {
+ stderr.printf("Failed to remove %s: %s\n", f.get_path(), e.message);
+ }
+ }
+
protected override void tear_down()
{
if (d_repository == null)
@@ -330,12 +388,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
return;
}
- var wd = d_repository.get_workdir();
-
- // nasty stuff, but I'm not going to implement recursive remove by hand
- // and glib doesn't provide anything for it
- Posix.system("rm -rf '%s'".printf(wd.get_path()));
-
+ remove_recursively(d_repository.get_workdir());
d_repository = null;
}
}
diff --git a/tests/libgitg/test.vala b/tests/support/test.vala
similarity index 76%
rename from tests/libgitg/test.vala
rename to tests/support/test.vala
index bbb3f91..f536ed2 100644
--- a/tests/libgitg/test.vala
+++ b/tests/support/test.vala
@@ -40,4 +40,24 @@ class Gitg.Test.Test : Object
}
}
+namespace Gitg.Test.Assert
+{
+ void assert_file_contents(string filename, string expected_contents)
+ {
+ string contents;
+ size_t len;
+
+ try
+ {
+ FileUtils.get_contents(filename, out contents, out len);
+ }
+ catch (Error e)
+ {
+ assert_no_error(e);
+ }
+
+ assert_streq(contents, expected_contents);
+ }
+}
+
// ex:set ts=4 noet
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]