summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-07-12 21:11:02 -0400
committerColin Walters <walters@verbum.org>2017-07-17 12:23:31 -0400
commit607f1775bb1c626cae1875a957a34802daebe81c (patch)
tree3054da3fbacfd15b63f9cddd827f55a6308e9e8f /tests
parent61ef326ad8381ea08ad3045fd0c65f974684afde (diff)
downloadlibglnx-607f1775bb1c626cae1875a957a34802daebe81c.tar.gz
errors: Add GLNX_AUTO_PREFIX_ERROR
In a lot of places in ostree, we end up prefixing errors in the *caller*. Often we only have 1-2 callers, and doing the error prefixing isn't too duplicative. But there are definitely cases where it's cleaner to do the prefixing in the callee. We have functions that aren't ported to new style for this reason (they still do the prefixing in `out:`). Introduce a cleanup-oriented version of error prefixing so we can port those functions too.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-libglnx-errors.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test-libglnx-errors.c b/tests/test-libglnx-errors.c
index 721818b..4e91e02 100644
--- a/tests/test-libglnx-errors.c
+++ b/tests/test-libglnx-errors.c
@@ -125,6 +125,48 @@ test_error_errno (void)
g_assert_cmpint (fd, ==, -1);
}
+static void
+test_error_auto_nothrow (GError **error)
+{
+ GLNX_AUTO_PREFIX_ERROR("foo", error);
+ /* Side effect to avoid otherwise empty function */
+ g_assert_no_error (*error);
+}
+
+static void
+test_error_auto_throw (GError **error)
+{
+ GLNX_AUTO_PREFIX_ERROR("foo", error);
+ (void) glnx_throw (error, "oops");
+}
+
+static void
+test_error_auto_throw_recurse (GError **error)
+{
+ GLNX_AUTO_PREFIX_ERROR("foo", error);
+
+ if (TRUE)
+ {
+ GLNX_AUTO_PREFIX_ERROR("bar", error);
+ (void) glnx_throw (error, "oops");
+ }
+}
+
+static void
+test_error_auto (void)
+{
+ g_autoptr(GError) error = NULL;
+ test_error_auto_nothrow (&error);
+ g_assert_no_error (error);
+ test_error_auto_throw (&error);
+ g_assert_nonnull (error);
+ g_assert_cmpstr (error->message, ==, "foo: oops");
+ g_clear_error (&error);
+ test_error_auto_throw_recurse (&error);
+ g_assert_nonnull (error);
+ g_assert_cmpstr (error->message, ==, "foo: bar: oops");
+}
+
int main (int argc, char **argv)
{
int ret;
@@ -133,6 +175,7 @@ int main (int argc, char **argv)
g_test_add_func ("/error-throw", test_error_throw);
g_test_add_func ("/error-errno", test_error_errno);
+ g_test_add_func ("/error-auto", test_error_auto);
ret = g_test_run();