[gitg/wip/commit: 11/28] Added assert macros



commit 93fe0d68bc3736badc4035b3aab25dcd56578880
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jun 30 11:05:17 2013 +0200

    Added assert macros

 libgitg/tests/Makefile.am      |    4 +++-
 libgitg/tests/gitg-assert.h    |   32 ++++++++++++++++++++++++++++++++
 libgitg/tests/gitg-assert.vapi |    9 +++++++++
 libgitg/tests/repository.vala  |   34 +++++++++++++++++++---------------
 libgitg/tests/test.vala        |   11 -----------
 5 files changed, 63 insertions(+), 27 deletions(-)
---
diff --git a/libgitg/tests/Makefile.am b/libgitg/tests/Makefile.am
index 3dc4136..e1941d7 100644
--- a/libgitg/tests/Makefile.am
+++ b/libgitg/tests/Makefile.am
@@ -2,7 +2,7 @@ AM_CPPFLAGS = -g -I$(top_srcdir) -I$(top_srcdir)/gitg -I$(top_srcdir)/libgitg $(
 
 noinst_PROGRAMS = $(TEST_PROGS)
 
-AM_VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS) --pkg posix
+AM_VALAFLAGS = $(GITG_PLUGIN_VALAFLAGS) --vapidir $(srcdir) --pkg posix --pkg gitg-assert
 
 TEST_PROGS = test-libgitg
 
@@ -24,4 +24,6 @@ CLEANFILES =                                  \
        $(test_libgitg_SOURCES:.vala=.c)        \
        $(BUILT_SOURCES)
 
+EXTRA_DIST = gitg-assert.h
+
 -include $(top_srcdir)/git.mk
diff --git a/libgitg/tests/gitg-assert.h b/libgitg/tests/gitg-assert.h
new file mode 100644
index 0000000..5be2326
--- /dev/null
+++ b/libgitg/tests/gitg-assert.h
@@ -0,0 +1,32 @@
+/*
+ * 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/>.
+ */
+
+#ifndef __GITG_ASSERT_H__
+#define __GITG_ASSERT_H__
+
+#include <glib.h>
+
+#define gitg_test_assert_assert_no_error(error) g_assert_no_error(error)
+#define gitg_test_assert_assert_streq(a, b) g_assert_cmpstr(a, ==, b)
+#define gitg_test_assert_assert_inteq(a, b) g_assert_cmpint(a, ==, b)
+#define gitg_test_assert_assert_uinteq(a, b) g_assert_cmpuint(a, ==, b)
+#define gitg_test_assert_assert_floateq(a, b) g_assert_cmpfloat(a, ==, b)
+
+#endif /* __GITG_ASSERT_H__ */
+
diff --git a/libgitg/tests/gitg-assert.vapi b/libgitg/tests/gitg-assert.vapi
new file mode 100644
index 0000000..e83ba49
--- /dev/null
+++ b/libgitg/tests/gitg-assert.vapi
@@ -0,0 +1,9 @@
+[CCode (cprefix = "Gitg", lower_case_prefix = "gitg_", cheader_filename = "gitg-assert.h")]
+namespace Gitg.Test.Assert
+{
+       public static void assert_no_error(GLib.Error e);
+       public static void assert_streq(string a, string b);
+       public static void assert_inteq(int a, int b);
+       public static void assert_uinteq(uint a, uint b);
+       public static void assert_floateq(float a, float b);
+}
diff --git a/libgitg/tests/repository.vala b/libgitg/tests/repository.vala
index e84bf02..b1aeca2 100644
--- a/libgitg/tests/repository.vala
+++ b/libgitg/tests/repository.vala
@@ -17,6 +17,8 @@
  * along with gitg. If not, see <http://www.gnu.org/licenses/>.
  */
 
+using Gitg.Test.Assert;
+
 class Gitg.Test.Repository : Gitg.Test.Test
 {
        protected Gitg.Repository? d_repository;
@@ -80,7 +82,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                        }
                        catch (GLib.Error e)
                        {
-                               assert_noerror(e);
+                               assert_no_error(e);
                        }
                }
        }
@@ -105,7 +107,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -117,7 +119,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                        }
                        catch (GLib.Error e)
                        {
-                               assert_noerror(e);
+                               assert_no_error(e);
                        }
                }
 
@@ -130,7 +132,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -144,7 +146,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -156,7 +158,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -185,7 +187,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -195,7 +197,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                }
        }
 
@@ -219,7 +221,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                        }
                        catch (GLib.Error e)
                        {
-                               assert_noerror(e);
+                               assert_no_error(e);
                        }
                }
        }
@@ -254,7 +256,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -267,7 +269,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                        }
                        catch (GLib.Error e)
                        {
-                               assert_noerror(e);
+                               assert_no_error(e);
                                continue;
                        }
 
@@ -278,7 +280,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                        }
                        catch (GLib.Error e)
                        {
-                               assert_noerror(e);
+                               assert_no_error(e);
                        }
                }
 
@@ -288,7 +290,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                }
        }
 
@@ -296,13 +298,15 @@ class Gitg.Test.Repository : Gitg.Test.Test
        {
                string wd;
 
+               d_last_commit = null;
+
                try
                {
                        wd = GLib.DirUtils.make_tmp("gitg-test-XXXXXX");
                }
                catch (GLib.Error e)
                {
-                       assert_noerror(e);
+                       assert_no_error(e);
                        return;
                }
 
@@ -315,7 +319,7 @@ class Gitg.Test.Repository : Gitg.Test.Test
                catch (GLib.Error e)
                {
                        GLib.DirUtils.remove(wd);
-                       assert_noerror(e);
+                       assert_no_error(e);
                }
        }
 
diff --git a/libgitg/tests/test.vala b/libgitg/tests/test.vala
index 1363187..bbb3f91 100644
--- a/libgitg/tests/test.vala
+++ b/libgitg/tests/test.vala
@@ -19,17 +19,6 @@
 
 class Gitg.Test.Test : Object
 {
-       protected void assert_noerror(GLib.Error e)
-       {
-               if (e != null)
-               {
-                       GLib.log(null,
-                                GLib.LogLevelFlags.FLAG_FATAL,
-                                "ERROR: (error != null): %s\n",
-                                e.message);
-               }
-       }
-
        private GLib.TestSuite d_suite;
 
        construct


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]