[gnome-builder] tests: specify required plugins when defining tests



commit fd5cf8eba0749c37088f870b56220ad9dd435639
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 19 17:24:35 2017 -0700

    tests: specify required plugins when defining tests
    
    This will disable plugins (and enable necessary plugins) before running
    the particular async test.

 libide/application/ide-application-tests.c |   62 +++++++++++++++++++++++++--
 libide/application/ide-application-tests.h |    3 +-
 libide/buildsystem/ide-build-system.c      |   13 +++++-
 tests/meson.build                          |    2 +-
 tests/test-ide-back-forward-list.c         |    3 +-
 tests/test-ide-buffer-manager.c            |    3 +-
 tests/test-ide-buffer.c                    |    3 +-
 tests/test-ide-context.c                   |    8 +--
 tests/test-ide-indenter.c                  |    3 +-
 tests/test-vim.c                           |   21 ++--------
 10 files changed, 86 insertions(+), 35 deletions(-)
---
diff --git a/libide/application/ide-application-tests.c b/libide/application/ide-application-tests.c
index 5affc23..7b55f4d 100644
--- a/libide/application/ide-application-tests.c
+++ b/libide/application/ide-application-tests.c
@@ -28,10 +28,11 @@
 
 typedef struct
 {
-  IdeApplication               *self;
-  gchar                        *name;
-  IdeApplicationTest            test_func;
-  IdeApplicationTestCompletion  test_completion;
+  IdeApplication                *self;
+  gchar                         *name;
+  gchar                        **required_plugins;
+  IdeApplicationTest             test_func;
+  IdeApplicationTestCompletion   test_completion;
 } AsyncTest;
 
 static void ide_application_run_next_test (IdeApplication *self);
@@ -73,6 +74,46 @@ ide_application_run_tests_cb (GObject      *object,
 }
 
 static void
+ide_application_tests_update_plugins (IdeApplication *self,
+                                      AsyncTest      *test)
+{
+  g_auto(GStrv) loaded = NULL;
+  PeasEngine *engine;
+
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (test != NULL);
+
+  engine = peas_engine_get_default ();
+  loaded = peas_engine_get_loaded_plugins (engine);
+
+  if (loaded != NULL)
+    {
+      for (guint i = 0; loaded[i]; i++)
+        {
+          PeasPluginInfo *info = peas_engine_get_plugin_info (engine, loaded[i]);
+
+          g_debug ("Unloading plugin %s", loaded[i]);
+          peas_engine_unload_plugin (engine, info);
+        }
+    }
+
+  if (test->required_plugins != NULL)
+    {
+      for (guint i = 0; test->required_plugins[i]; i++)
+        {
+          PeasPluginInfo *info = peas_engine_get_plugin_info (engine, test->required_plugins[i]);
+
+          g_debug ("Loading plugin %s [%p] for test", test->required_plugins[i], info);
+
+          if (info == NULL)
+            g_error ("No such plugin %s", test->required_plugins[i]);
+
+          peas_engine_load_plugin (engine, info);
+        }
+    }
+}
+
+static void
 ide_application_run_next_test (IdeApplication *self)
 {
   g_autoptr(GCancellable) cancellable = NULL;
@@ -86,8 +127,17 @@ ide_application_run_next_test (IdeApplication *self)
 
   test = self->test_funcs->data;
   test->self = g_object_ref (self);
+
+  /* ensure proper plugins are loaded */
+  ide_application_tests_update_plugins (self, test);
+
+  /* run the async test */
   test->test_func (cancellable, ide_application_run_tests_cb, test);
 
+  /* remove it from our todo list. this is safe to do after calling
+   * our async func because the finish cannot be called until we
+   * return from this function and yield to the main loop.
+   */
   self->test_funcs = g_list_delete_link (self->test_funcs, self->test_funcs);
 
   IDE_EXIT;
@@ -123,7 +173,8 @@ void
 ide_application_add_test (IdeApplication               *self,
                           const gchar                  *test_name,
                           IdeApplicationTest            test_func,
-                          IdeApplicationTestCompletion  test_completion)
+                          IdeApplicationTestCompletion  test_completion,
+                          const gchar * const          *required_plugins)
 {
   AsyncTest *test;
 
@@ -140,6 +191,7 @@ ide_application_add_test (IdeApplication               *self,
   test->name = g_strdup (test_name);
   test->test_func = test_func;
   test->test_completion = test_completion;
+  test->required_plugins = g_strdupv ((gchar **)required_plugins);
 
   self->test_funcs = g_list_append (self->test_funcs, test);
 
diff --git a/libide/application/ide-application-tests.h b/libide/application/ide-application-tests.h
index b1f7f3a..945ab16 100644
--- a/libide/application/ide-application-tests.h
+++ b/libide/application/ide-application-tests.h
@@ -32,7 +32,8 @@ typedef gboolean (*IdeApplicationTestCompletion) (GAsyncResult         *result,
 void ide_application_add_test (IdeApplication               *self,
                                const gchar                  *test_name,
                                IdeApplicationTest            test_func,
-                               IdeApplicationTestCompletion  test_completion);
+                               IdeApplicationTestCompletion  test_completion,
+                               const gchar * const          *required_plugins);
 
 G_END_DECLS
 
diff --git a/libide/buildsystem/ide-build-system.c b/libide/buildsystem/ide-build-system.c
index af27c26..d17f736 100644
--- a/libide/buildsystem/ide-build-system.c
+++ b/libide/buildsystem/ide-build-system.c
@@ -180,7 +180,7 @@ ide_build_system_new_async (IdeContext          *context,
 
   ide_object_new_for_extension_async (IDE_TYPE_BUILD_SYSTEM,
                                       sort_priority, (gpointer)build_system_hint,
-                                      G_PRIORITY_DEFAULT,
+                                      G_PRIORITY_LOW,
                                       cancellable,
                                       callback,
                                       user_data,
@@ -203,11 +203,20 @@ ide_build_system_new_finish (GAsyncResult  *result,
 {
   IdeObject *ret;
 
+  IDE_ENTRY;
+
   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
 
   ret = ide_object_new_finish (result, error);
 
-  return ret ? IDE_BUILD_SYSTEM (ret) : NULL;
+#ifdef IDE_ENABLE_TRACE
+  if (ret)
+    IDE_TRACE_MSG ("BuildSystem is %s", G_OBJECT_TYPE_NAME (ret));
+  else
+    IDE_TRACE_MSG ("BuildSystem creation failed");
+#endif
+
+  IDE_RETURN (IDE_BUILD_SYSTEM (ret));
 }
 
 void
diff --git a/tests/meson.build b/tests/meson.build
index e5455c7..1af558a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -10,7 +10,7 @@ ide_test_env = [
 #  'MALLOC_PERTURB_=$((${RANDOM:-256} % 256))',
 ]
 ide_test_cflags = [
-       '-DTEST_DATA_DIR="@0@/data"'.format(meson.current_source_dir()),
+  '-DTEST_DATA_DIR="@0@/data/"'.format(meson.current_source_dir()),
 ]
 
 ide_context = executable('test-ide-context',
diff --git a/tests/test-ide-back-forward-list.c b/tests/test-ide-back-forward-list.c
index e7c5d32..28e1ff7 100644
--- a/tests/test-ide-back-forward-list.c
+++ b/tests/test-ide-back-forward-list.c
@@ -143,6 +143,7 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -152,7 +153,7 @@ main (gint   argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/BackForwardList/basic", test_basic, NULL);
+  ide_application_add_test (app, "/Ide/BackForwardList/basic", test_basic, NULL, required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 
diff --git a/tests/test-ide-buffer-manager.c b/tests/test-ide-buffer-manager.c
index 408231d..0c72096 100644
--- a/tests/test-ide-buffer-manager.c
+++ b/tests/test-ide-buffer-manager.c
@@ -173,6 +173,7 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -182,7 +183,7 @@ main (gint   argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/BufferManager/basic", test_buffer_manager_basic, NULL);
+  ide_application_add_test (app, "/Ide/BufferManager/basic", test_buffer_manager_basic, NULL, 
required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 
diff --git a/tests/test-ide-buffer.c b/tests/test-ide-buffer.c
index e979664..856e2fd 100644
--- a/tests/test-ide-buffer.c
+++ b/tests/test-ide-buffer.c
@@ -104,6 +104,7 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -113,7 +114,7 @@ main (gint   argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/Buffer/basic", test_buffer_basic, NULL);
+  ide_application_add_test (app, "/Ide/Buffer/basic", test_buffer_basic, NULL, required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 
diff --git a/tests/test-ide-context.c b/tests/test-ide-context.c
index e2103ac..a61b883 100644
--- a/tests/test-ide-context.c
+++ b/tests/test-ide-context.c
@@ -55,13 +55,10 @@ test_new_async (GCancellable        *cancellable,
 {
   g_autofree gchar *path = NULL;
   g_autoptr(GFile) project_file = NULL;
-  const gchar *srcdir;
   GTask *task;
 
-  srcdir = g_getenv ("G_TEST_SRCDIR");
-
   task = g_task_new (NULL, cancellable, callback, user_data);
-  path = g_build_filename (srcdir, "data", "project1", "configure.ac", NULL);
+  path = g_build_filename (TEST_DATA_DIR, "project1", "configure.ac", NULL);
   project_file = g_file_new_for_path (path);
 
   ide_context_new_async (project_file,
@@ -74,6 +71,7 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -83,7 +81,7 @@ main (gint   argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/Context/new_async", test_new_async, NULL);
+  ide_application_add_test (app, "/Ide/Context/new_async", test_new_async, NULL, required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 
diff --git a/tests/test-ide-indenter.c b/tests/test-ide-indenter.c
index 72a4e36..b12746e 100644
--- a/tests/test-ide-indenter.c
+++ b/tests/test-ide-indenter.c
@@ -170,6 +170,7 @@ gint
 main (gint argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "c-pack-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -179,7 +180,7 @@ main (gint argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/CIndenter/basic", test_cindenter_basic, NULL);
+  ide_application_add_test (app, "/Ide/CIndenter/basic", test_cindenter_basic, NULL, required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 
diff --git a/tests/test-vim.c b/tests/test-vim.c
index 64c4bf1..66e52ee 100644
--- a/tests/test-vim.c
+++ b/tests/test-vim.c
@@ -36,19 +36,6 @@ struct {
 };
 
 static void
-load_vim_css (void)
-{
-  GtkCssProvider *provider;
-
-  provider = gtk_css_provider_new ();
-  gtk_css_provider_load_from_resource (provider, "/org/gnome/builder/keybindings/vim.css");
-  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
-                                             GTK_STYLE_PROVIDER (provider),
-                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-  g_clear_object (&provider);
-}
-
-static void
 new_context_cb (GObject      *object,
                 GAsyncResult *result,
                 gpointer      user_data)
@@ -109,10 +96,9 @@ test_vim_basic (GCancellable        *cancellable,
   g_autoptr(GFile) project_file = NULL;
   GTask *task;
 
-  load_vim_css ();
-
   task = g_task_new (NULL, cancellable, callback, user_data);
-  project_file = g_file_new_for_path (TEST_DATA_DIR"/project1/configure.ac");
+  project_file = g_file_new_for_path (TEST_DATA_DIR "/project1/configure.ac");
+  g_assert (g_file_query_exists (project_file, NULL));
   ide_context_new_async (project_file,
                          NULL,
                          new_context_cb,
@@ -193,6 +179,7 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
+  static const gchar *required_plugins[] = { "autotools-plugin", "directory-plugin", NULL };
   IdeApplication *app;
   gint ret;
 
@@ -202,7 +189,7 @@ main (gint   argc,
   ide_log_set_verbosity (4);
 
   app = ide_application_new ();
-  ide_application_add_test (app, "/Ide/Vim/basic", test_vim_basic, NULL);
+  ide_application_add_test (app, "/Ide/Vim/basic", test_vim_basic, NULL, required_plugins);
   ret = g_application_run (G_APPLICATION (app), argc, argv);
   g_object_unref (app);
 


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