tests: Port some bits of C to new style
authorColin Walters <walters@verbum.org>
Wed, 13 Sep 2017 16:09:51 +0000 (12:09 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 13 Sep 2017 19:32:36 +0000 (19:32 +0000)
Where we can; perhaps after updating libglnx we should use the
new test error macro?

Closes: #1169
Approved by: jlebon

tests/libostreetest.c
tests/test-libarchive-import.c

index bc4c49f617610b4681f251eed7621a2ab493b1b5..f1a01e681ca25b1c72619766dc05d85a55800acd 100644 (file)
@@ -33,9 +33,7 @@
 gboolean
 ot_test_run_libtest (const char *cmd, GError **error)
 {
-  gboolean ret = FALSE;
   const char *srcdir = g_getenv ("G_TEST_SRCDIR");
-  int estatus;
   g_autoptr(GPtrArray) argv = g_ptr_array_new ();
   g_autoptr(GString) cmdstr = g_string_new ("");
 
@@ -50,53 +48,39 @@ ot_test_run_libtest (const char *cmd, GError **error)
   g_ptr_array_add (argv, cmdstr->str);
   g_ptr_array_add (argv, NULL);
 
+  int estatus;
   if (!g_spawn_sync (NULL, (char**)argv->pdata, NULL, G_SPAWN_SEARCH_PATH,
                      NULL, NULL, NULL, NULL, &estatus, error))
-    goto out;
-
+    return FALSE;
   if (!g_spawn_check_exit_status (estatus, error))
-    goto out;
+    return FALSE;
 
-  ret = TRUE;
- out:
-  return ret;
+  return TRUE;
 }
 
 OstreeRepo *
 ot_test_setup_repo (GCancellable *cancellable,
                     GError **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GFile) repo_path = g_file_new_for_path ("repo");
-  glnx_unref_object OstreeRepo* ret_repo = NULL;
-
   if (!ot_test_run_libtest ("setup_test_repository archive", error))
-    goto out;
-
-  ret_repo = ostree_repo_new (repo_path);
+    return NULL;
 
+  g_autoptr(GFile) repo_path = g_file_new_for_path ("repo");
+  g_autoptr(OstreeRepo) ret_repo = ostree_repo_new (repo_path);
   if (!ostree_repo_open (ret_repo, cancellable, error))
-    goto out;
+    return NULL;
 
-  ret = TRUE;
- out:
-  if (ret)
-    return g_steal_pointer (&ret_repo);
-  return NULL;
+  return g_steal_pointer (&ret_repo);
 }
 
 OstreeSysroot *
 ot_test_setup_sysroot (GCancellable *cancellable,
                        GError **error)
 {
-  gboolean ret = FALSE;
-  g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
-  glnx_unref_object OstreeSysroot *ret_sysroot = NULL;
-  struct statfs stbuf;
-
   if (!ot_test_run_libtest ("setup_os_repository \"archive\" \"syslinux\"", error))
-    goto out;
+    return FALSE;
 
+  struct statfs stbuf;
   { g_autoptr(GString) buf = g_string_new ("mutable-deployments");
     if (statfs ("/", &stbuf) < 0)
       return glnx_null_throw_errno (error);
@@ -113,11 +97,6 @@ ot_test_setup_sysroot (GCancellable *cancellable,
     g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
   }
 
-  ret_sysroot = ostree_sysroot_new (sysroot_path);
-
-  ret = TRUE;
- out:
-  if (ret)
-    return g_steal_pointer (&ret_sysroot);
-  return NULL;
+  g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
+  return ostree_sysroot_new (sysroot_path);
 }
index 6047d359971f0480e96974507db072f3a21bd371..77c2dd30f24947d7a454ab5ad808032a8c45881c 100644 (file)
@@ -260,34 +260,31 @@ import_write_and_ref (OstreeRepo      *repo,
                       OstreeRepoCommitModifier *modifier,
                       GError         **error)
 {
-  gboolean ret = FALSE;
-  glnx_unref_object GFile *root = NULL;
-  g_autofree char *commit_checksum = NULL;
-  glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
+  g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new ();
 
   if (!ostree_repo_prepare_transaction (repo, NULL, NULL, error))
-    goto out;
+    return FALSE;
 
   if (!ostree_repo_import_archive_to_mtree (repo, opts, a, mtree, modifier,
                                             NULL, error))
-    goto out;
+    return FALSE;
 
+  g_autoptr(GFile) root = NULL;
   if (!ostree_repo_write_mtree (repo, mtree, &root, NULL, error))
-    goto out;
+    return FALSE;
 
+  g_autofree char *commit_checksum = NULL;
   if (!ostree_repo_write_commit (repo, NULL, "", "", NULL,
                                  OSTREE_REPO_FILE (root),
                                  &commit_checksum, NULL, error))
-    goto out;
+    return FALSE;
 
   ostree_repo_transaction_set_ref (repo, NULL, ref, commit_checksum);
 
   if (!ostree_repo_commit_transaction (repo, NULL, NULL, error))
-    goto out;
+    return FALSE;
 
-  ret = TRUE;
-out:
-  return ret;
+  return TRUE;
 }
 
 static void
@@ -413,7 +410,7 @@ test_libarchive_xattr_callback (gconstpointer data)
   GError *error = NULL;
   g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
   OstreeRepoImportArchiveOptions opts = { 0 };
-  OstreeRepoCommitModifier *modifier = NULL;
+  g_autoptr(OstreeRepoCommitModifier) modifier = NULL;
   char buf[7] = { 0 };
 
   if (skip_if_no_xattr (td))
@@ -452,8 +449,6 @@ test_libarchive_xattr_callback (gconstpointer data)
   g_assert_cmpstr (buf, ==, "mydata");
 
  out:
-  if (modifier)
-    ostree_repo_commit_modifier_unref (modifier);
   g_assert_no_error (error);
 }
 
@@ -543,7 +538,7 @@ test_libarchive_selinux (gconstpointer data)
   g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
   OstreeRepoImportArchiveOptions opts = { 0 };
   glnx_unref_object OstreeSePolicy *sepol = NULL;
-  OstreeRepoCommitModifier *modifier = NULL;
+  g_autoptr(OstreeRepoCommitModifier) modifier = NULL;
   char buf[64] = { 0 };
 
   if (skip_if_no_xattr (td))
@@ -591,8 +586,6 @@ test_libarchive_selinux (gconstpointer data)
   g_assert_cmpstr (buf, ==, "system_u:object_r:etc_t:s0");
 
  out:
-  if (modifier)
-    ostree_repo_commit_modifier_unref (modifier);
   g_assert_no_error (error);
 }