[gnome-builder] testui: add test output panel for unit test output



commit 179ff6eec32917fe4d0f6116f800d04b64e883b5
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 20 17:18:47 2019 -0800

    testui: add test output panel for unit test output
    
    This allows us to have the PTY used for running unit tests visible to
    the user so they can actually determine what the heck happened.

 po/POTFILES.in                             |  1 +
 src/plugins/testui/gbp-test-output-panel.c | 69 ++++++++++++++++++++++++++++++
 src/plugins/testui/gbp-test-output-panel.h | 34 +++++++++++++++
 src/plugins/testui/gbp-test-tree-addin.c   | 51 ++++++++++++++++++++--
 src/plugins/testui/meson.build             |  1 +
 5 files changed, 152 insertions(+), 4 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 91c14efc2..015fb5a66 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -332,6 +332,7 @@ src/plugins/sysroot/gbp-sysroot-toolchain-provider.c
 src/plugins/terminal/gbp-terminal-application-addin.c
 src/plugins/terminal/gbp-terminal-workspace-addin.c
 src/plugins/terminal/gtk/menus.ui
+src/plugins/testui/gbp-test-output-panel.c
 src/plugins/testui/gbp-test-tree-addin.c
 src/plugins/todo/gbp-todo-panel.c
 src/plugins/todo/gbp-todo-workspace-addin.c
diff --git a/src/plugins/testui/gbp-test-output-panel.c b/src/plugins/testui/gbp-test-output-panel.c
new file mode 100644
index 000000000..f764ed9f6
--- /dev/null
+++ b/src/plugins/testui/gbp-test-output-panel.c
@@ -0,0 +1,69 @@
+/* gbp-test-output-panel.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-test-output-panel"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <libide-gui.h>
+#include <libide-editor.h>
+#include <libide-terminal.h>
+
+#include "gbp-test-output-panel.h"
+
+struct _GbpTestOutputPanel
+{
+  DzlDockWidget    parent_instance;
+  IdeTerminalPage *terminal;
+};
+
+G_DEFINE_TYPE (GbpTestOutputPanel, gbp_test_output_panel, DZL_TYPE_DOCK_WIDGET)
+
+static void
+gbp_test_output_panel_class_init (GbpTestOutputPanelClass *klass)
+{
+}
+
+static void
+gbp_test_output_panel_init (GbpTestOutputPanel *self)
+{
+  dzl_dock_widget_set_title (DZL_DOCK_WIDGET (self), _("Unit Test Output"));
+  dzl_dock_widget_set_icon_name (DZL_DOCK_WIDGET (self), "builder-unit-tests-symbolic");
+
+  self->terminal = g_object_new (IDE_TYPE_TERMINAL_PAGE,
+                                 "manage-spawn", FALSE,
+                                 "visible", TRUE,
+                                 NULL);
+  gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->terminal));
+}
+
+GtkWidget *
+gbp_test_output_panel_new (VtePty *pty)
+{
+  GbpTestOutputPanel *self;
+
+  g_return_val_if_fail (VTE_IS_PTY (pty), NULL);
+
+  self = g_object_new (GBP_TYPE_TEST_OUTPUT_PANEL, NULL);
+  ide_terminal_page_set_pty (self->terminal, pty);
+
+  return GTK_WIDGET (self);
+}
diff --git a/src/plugins/testui/gbp-test-output-panel.h b/src/plugins/testui/gbp-test-output-panel.h
new file mode 100644
index 000000000..98f2afe18
--- /dev/null
+++ b/src/plugins/testui/gbp-test-output-panel.h
@@ -0,0 +1,34 @@
+/* gbp-test-output-panel.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <dazzle.h>
+#include <vte/vte.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_TEST_OUTPUT_PANEL (gbp_test_output_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpTestOutputPanel, gbp_test_output_panel, GBP, TEST_OUTPUT_PANEL, DzlDockWidget)
+
+GtkWidget *gbp_test_output_panel_new (VtePty *pty);
+
+G_END_DECLS
diff --git a/src/plugins/testui/gbp-test-tree-addin.c b/src/plugins/testui/gbp-test-tree-addin.c
index f21f3f760..6b54fdeba 100644
--- a/src/plugins/testui/gbp-test-tree-addin.c
+++ b/src/plugins/testui/gbp-test-tree-addin.c
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <libide-editor.h>
 #include <libide-foundry.h>
 #include <libide-gui.h>
 #include <libide-tree.h>
@@ -31,13 +32,15 @@
 #include "ide-tree-private.h"
 
 #include "gbp-test-path.h"
+#include "gbp-test-output-panel.h"
 #include "gbp-test-tree-addin.h"
 
 struct _GbpTestTreeAddin
 {
-  GObject       parent_instance;
-  IdeTreeModel *model;
-  IdeTree      *tree;
+  GObject             parent_instance;
+  IdeTreeModel       *model;
+  IdeTree            *tree;
+  GbpTestOutputPanel *panel;
 };
 
 typedef struct
@@ -56,6 +59,40 @@ run_test_free (RunTest *state)
   g_slice_free (RunTest, state);
 }
 
+static void
+show_test_panel (GbpTestTreeAddin *self)
+{
+  IdeTestManager *test_manager;
+  IdeContext *context;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_TEST_TREE_ADDIN (self));
+
+  if (!(context = ide_object_get_context (IDE_OBJECT (self->model))) ||
+      !ide_context_has_project (context) ||
+      !(test_manager = ide_test_manager_from_context (context)))
+    return;
+
+  if (self->panel == NULL)
+    {
+      GtkWidget *surface;
+      GtkWidget *utils;
+      VtePty *pty;
+
+      pty = ide_test_manager_get_pty (test_manager);
+      self->panel = GBP_TEST_OUTPUT_PANEL (gbp_test_output_panel_new (pty));
+      g_signal_connect (self->panel,
+                        "destroy",
+                        G_CALLBACK (gtk_widget_destroyed),
+                        &self->panel);
+      surface = gtk_widget_get_ancestor (GTK_WIDGET (self->tree), IDE_TYPE_EDITOR_SURFACE);
+      utils = ide_editor_surface_get_utilities (IDE_EDITOR_SURFACE (surface));
+      gtk_container_add (GTK_CONTAINER (utils), GTK_WIDGET (self->panel));
+      gtk_widget_show (GTK_WIDGET (self->panel));
+      dzl_dock_item_present (DZL_DOCK_ITEM (self->panel));
+    }
+}
+
 static void
 gbp_test_tree_addin_build_paths_cb (GObject      *object,
                                     GAsyncResult *result,
@@ -282,6 +319,9 @@ gbp_test_tree_addin_unload (IdeTreeAddin *addin,
   self->tree = NULL;
   self->model = NULL;
 
+  if (self->panel != NULL)
+    gtk_widget_destroy (GTK_WIDGET (self->panel));
+
   context = ide_object_get_context (IDE_OBJECT (model));
 
   if (!ide_context_has_project (context))
@@ -338,6 +378,7 @@ gbp_test_tree_addin_node_activated (IdeTreeAddin *addin,
                                     IdeTree      *tree,
                                     IdeTreeNode  *node)
 {
+  GbpTestTreeAddin *self = (GbpTestTreeAddin *)addin;
   g_autoptr(IdeTask) task = NULL;
   g_autofree gchar *title = NULL;
   IdeTestManager *test_manager;
@@ -346,7 +387,7 @@ gbp_test_tree_addin_node_activated (IdeTreeAddin *addin,
   IdeTest *test;
 
   g_assert (IDE_IS_MAIN_THREAD ());
-  g_assert (GBP_IS_TEST_TREE_ADDIN (addin));
+  g_assert (GBP_IS_TEST_TREE_ADDIN (self));
   g_assert (IDE_IS_TREE (tree));
   g_assert (IDE_IS_TREE_NODE (node));
 
@@ -375,6 +416,8 @@ gbp_test_tree_addin_node_activated (IdeTreeAddin *addin,
 
   ide_tree_node_set_icon_name (node, "content-loading-symbolic");
 
+  show_test_panel (self);
+
   ide_test_manager_run_async (test_manager,
                               test,
                               NULL,
diff --git a/src/plugins/testui/meson.build b/src/plugins/testui/meson.build
index 2c4fad914..019c44e67 100644
--- a/src/plugins/testui/meson.build
+++ b/src/plugins/testui/meson.build
@@ -1,6 +1,7 @@
 plugins_sources += files([
   'testui-plugin.c',
   'gbp-test-path.c',
+  'gbp-test-output-panel.c',
   'gbp-test-tree-addin.c',
 ])
 


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