[gnome-builder] tests: add/remove tests
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tests: add/remove tests
- Date: Tue, 12 Jul 2022 06:39:21 +0000 (UTC)
commit c3e54c15504645f9811837c6117245ba2d90d454
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 23:33:07 2022 -0700
tests: add/remove tests
- Some are now part of upstream libraries, can drop them
- Others are new tests we need in-tree
src/tests/meson.build | 50 ++------
src/tests/test-completion-fuzzy.c | 70 -----------
src/tests/test-run-context.c | 237 ++++++++++++++++++++++++++++++++++++++
src/tests/test-shortcuts.c | 128 ++++++++++++++++++++
src/tests/test-shortcuts.json | 14 +++
src/tests/test-snippet-parser.c | 71 ------------
6 files changed, 388 insertions(+), 182 deletions(-)
---
diff --git a/src/tests/meson.build b/src/tests/meson.build
index ad23b8890..21a5b5666 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -1,33 +1,3 @@
-template_libdir = dependency('template-glib-1.0').get_variable('libdir')
-dazzle_libdir = dependency('libdazzle-1.0').get_variable('libdir')
-gsv_libdir = dependency('gtksourceview-4').get_variable('libdir')
-
-typelib_dirs = [
- '@0@/src/libide'.format(meson.project_build_root()),
- '@0@/src/gstyle'.format(meson.project_build_root()),
- join_paths(template_libdir, 'girepository-1.0'),
- join_paths(dazzle_libdir, 'girepository-1.0'),
- join_paths(gsv_libdir, 'girepository-1.0'),
-]
-
-test_env = [
- 'GI_TYPELIB_PATH="@0@:$(GI_TYPELIB_PATH)"'.format(':'.join(typelib_dirs)),
- 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
- 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
- 'G_DEBUG=gc-friendly',
- 'GSETTINGS_BACKEND=memory',
- 'GSETTINGS_SCHEMA_DIR=@0@/data/gsettings'.format(meson.project_build_root()),
- 'PYTHONDONTWRITEBYTECODE=yes',
- 'MALLOC_CHECK_=2',
- 'NO_AT_BRIDGE=1',
-]
-
-test_cflags = [
- '-DTEST_DATA_DIR="@0@/data/"'.format(meson.current_source_dir()),
- '-I' + join_paths(meson.project_source_root(), 'src'),
-]
-
-
test_libide_core = executable('test-libide-core', 'test-libide-core.c',
c_args: test_cflags,
dependencies: [ libide_core_dep ],
@@ -42,13 +12,6 @@ test_libide_io = executable('test-libide-io', 'test-libide-io.c',
test('test-libide-io', test_libide_io, env: test_env)
-test_snippet_parser = executable('test-snippet-parser', 'test-snippet-parser.c',
- c_args: test_cflags,
- dependencies: [ libide_sourceview_dep ],
-)
-test('test-snippet-parser', test_snippet_parser, env: test_env)
-
-
test_line_reader = executable('test-line-reader', 'test-line-reader.c',
c_args: test_cflags,
dependencies: [ libide_io_dep ],
@@ -79,7 +42,7 @@ test('test-task', test_task, env: test_env)
test_subprocess_launcher = executable('test-subprocess-launcher', 'test-subprocess-launcher.c',
c_args: test_cflags,
- dependencies: [ libide_threading_dep ],
+ dependencies: [ libide_threading_dep, libide_io_dep ],
)
test('test-subprocess-launcher', test_subprocess_launcher, env: test_env)
@@ -104,9 +67,14 @@ test_compile_commands = executable('test-compile-commands', 'test-compile-comman
)
test('test-compile-commands', test_compile_commands, env: test_env)
+test_shortcuts = executable('test-shortcuts', 'test-shortcuts.c',
+ c_args: test_cflags,
+ dependencies: [ libgtk_dep, libide_gui_dep ],
+)
+test('test-shortcuts', test_shortcuts, env: test_env, depends: [libide_gir])
-test_completion_fuzzy = executable('test-completion-fuzzy', 'test-completion-fuzzy.c',
+test_run_context = executable('test-run-context', 'test-run-context.c',
c_args: test_cflags,
- dependencies: [ libide_sourceview_dep ],
+ dependencies: [ libide_foundry_dep ],
)
-test('test-completion-fuzzy', test_completion_fuzzy, env: test_env)
+test('test-run-context', test_run_context, env: test_env)
diff --git a/src/tests/test-run-context.c b/src/tests/test-run-context.c
new file mode 100644
index 000000000..ff2ee85b5
--- /dev/null
+++ b/src/tests/test-run-context.c
@@ -0,0 +1,237 @@
+/* test-run-context.c
+ *
+ * Copyright 2022 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
+ */
+
+#include "config.h"
+
+#include <unistd.h>
+
+#include <libide-foundry.h>
+
+static int
+sort_strv_strcmpptr (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ const char *stra = *(const char **)a;
+ const char *strb = *(const char **)b;
+
+ return g_strcmp0 (stra, strb);
+}
+
+static char **
+sort_strv (const char * const *strv)
+{
+ char **copy = g_strdupv ((char **)strv);
+ gsize n_elements = g_strv_length (copy);
+ g_qsort_with_data (copy, n_elements, sizeof (char *), sort_strv_strcmpptr, NULL);
+ return copy;
+}
+
+static void
+compare_strv_unordered (const gchar * const *strv,
+ const gchar * const *expected_strv)
+{
+ char **strv_sorted;
+ char **expected_strv_sorted;
+
+ if (expected_strv == NULL)
+ {
+ g_assert_true (strv == NULL || strv[0] == NULL);
+ return;
+ }
+
+ g_assert_nonnull (strv);
+
+ g_assert_cmpint (g_strv_length ((char **)strv), ==, g_strv_length ((char **)expected_strv));
+
+ strv_sorted = sort_strv (strv);
+ expected_strv_sorted = sort_strv (strv);
+
+ for (guint i = 0; strv_sorted[i]; i++)
+ g_assert_cmpstr (strv_sorted[i], ==, expected_strv_sorted[i]);
+
+ g_strfreev (strv_sorted);
+ g_strfreev (expected_strv_sorted);
+}
+
+static void
+test_run_context_environ (void)
+{
+ IdeRunContext *run_context;
+
+ run_context = ide_run_context_new ();
+
+ ide_run_context_setenv (run_context, "FOO", "BAR");
+ compare_strv_unordered (ide_run_context_get_environ (run_context),
+ IDE_STRV_INIT ("FOO=BAR"));
+ g_assert_cmpstr (ide_run_context_getenv (run_context, "FOO"), ==, "BAR");
+
+ ide_run_context_setenv (run_context, "FOO", "123");
+ compare_strv_unordered (ide_run_context_get_environ (run_context),
+ IDE_STRV_INIT ("FOO=123"));
+
+ ide_run_context_setenv (run_context, "ABC", "DEF");
+ compare_strv_unordered (ide_run_context_get_environ (run_context),
+ IDE_STRV_INIT ("FOO=123", "ABC=DEF"));
+
+ ide_run_context_unsetenv (run_context, "FOO");
+ compare_strv_unordered (ide_run_context_get_environ (run_context),
+ IDE_STRV_INIT ("ABC=DEF"));
+
+ g_assert_finalize_object (run_context);
+}
+
+static void
+test_run_context_argv (void)
+{
+ IdeRunContext *run_context;
+
+ run_context = ide_run_context_new ();
+
+ ide_run_context_prepend_argv (run_context, "1");
+ ide_run_context_prepend_argv (run_context, "0");
+ ide_run_context_append_argv (run_context, "2");
+ ide_run_context_append_args (run_context, IDE_STRV_INIT ("3", "4"));
+ ide_run_context_prepend_args (run_context, IDE_STRV_INIT ("a", "b"));
+
+ g_assert_true (g_strv_equal (ide_run_context_get_argv (run_context),
+ IDE_STRV_INIT ("a", "b", "0", "1", "2", "3", "4")));
+
+ g_assert_finalize_object (run_context);
+}
+
+static void
+test_run_context_default_handler (void)
+{
+ IdeRunContext *run_context;
+ IdeSubprocessLauncher *launcher;
+ g_autoptr(GError) error = NULL;
+
+ run_context = ide_run_context_new ();
+
+ ide_run_context_set_argv (run_context, IDE_STRV_INIT ("wrapper", "--"));
+ ide_run_context_set_environ (run_context, IDE_STRV_INIT ("USER=nobody"));
+
+ ide_run_context_push (run_context, NULL, NULL, NULL);
+ ide_run_context_set_cwd (run_context, "/home/user");
+ ide_run_context_set_argv (run_context, IDE_STRV_INIT ("ls", "-lsah"));
+ ide_run_context_setenv (run_context, "USER", "user");
+ ide_run_context_setenv (run_context, "UID", "1000");
+ ide_run_context_take_fd (run_context, dup (STDOUT_FILENO), STDOUT_FILENO);
+
+ launcher = ide_run_context_end (run_context, &error);
+ g_assert_no_error (error);
+ g_assert_true (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+
+ g_assert_true (g_strv_equal (ide_subprocess_launcher_get_argv (launcher),
+ IDE_STRV_INIT ("wrapper", "--", "env", "USER=user", "UID=1000", "ls",
"-lsah")));
+ g_assert_true (g_strv_equal (ide_subprocess_launcher_get_environ (launcher),
+ IDE_STRV_INIT ("USER=nobody")));
+
+ g_assert_finalize_object (launcher);
+ g_assert_finalize_object (run_context);
+}
+
+static gboolean
+custom_handler (IdeRunContext *run_context,
+ const char * const *argv,
+ const char * const *env,
+ const char *cwd,
+ IdeUnixFDMap *unix_fd_map,
+ gpointer user_data,
+ GError **error)
+{
+ const char * const *subenv = ide_run_context_get_environ (run_context);
+
+ for (guint i = 0; subenv[i]; i++)
+ {
+ g_autofree char *arg = g_strdup_printf ("--env=%s", subenv[i]);
+ ide_run_context_prepend_argv (run_context, arg);
+ }
+
+ ide_run_context_prepend_args (run_context, argv);
+ ide_run_context_set_environ (run_context, env);
+
+ return TRUE;
+}
+
+static void
+test_run_context_custom_handler (void)
+{
+ IdeRunContext *run_context;
+ IdeSubprocessLauncher *launcher;
+ g_autoptr(GError) error = NULL;
+
+ run_context = ide_run_context_new ();
+
+ ide_run_context_set_argv (run_context, IDE_STRV_INIT ("ls", "-lsah"));
+ ide_run_context_setenv (run_context, "USER", "user");
+ ide_run_context_setenv (run_context, "UID", "1000");
+
+ ide_run_context_push (run_context, custom_handler, NULL, NULL);
+ ide_run_context_set_argv (run_context, IDE_STRV_INIT ("flatpak", "build"));
+
+ launcher = ide_run_context_end (run_context, &error);
+ g_assert_no_error (error);
+ g_assert_true (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+
+ g_assert_true (g_strv_equal (ide_subprocess_launcher_get_argv (launcher),
+ IDE_STRV_INIT ("flatpak", "build", "--env=UID=1000", "--env=USER=user", "ls",
"-lsah")));
+
+ g_assert_finalize_object (launcher);
+ g_assert_finalize_object (run_context);
+}
+
+static void
+test_run_context_push_shell (void)
+{
+ IdeRunContext *run_context;
+ IdeSubprocessLauncher *launcher;
+ GError *error = NULL;
+
+ run_context = ide_run_context_new ();
+ ide_run_context_push_shell (run_context, TRUE);
+ ide_run_context_setenv (run_context, "PATH", "path");
+ ide_run_context_append_argv (run_context, "which");
+ ide_run_context_append_argv (run_context, "foo");
+
+ launcher = ide_run_context_end (run_context, &error);
+ g_assert_no_error (error);
+ g_assert_nonnull (launcher);
+
+ g_assert_true (g_strv_equal (ide_subprocess_launcher_get_argv (launcher),
+ IDE_STRV_INIT ("/bin/sh", "--login", "-c", "env 'PATH=path' 'which' 'foo'")));
+
+ g_assert_finalize_object (launcher);
+ g_assert_finalize_object (run_context);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Ide/Foundry/RunContext/environ", test_run_context_environ);
+ g_test_add_func ("/Ide/Foundry/RunContext/argv", test_run_context_argv);
+ g_test_add_func ("/Ide/Foundry/RunContext/default_handler", test_run_context_default_handler);
+ g_test_add_func ("/Ide/Foundry/RunContext/custom_handler", test_run_context_custom_handler);
+ g_test_add_func ("/Ide/Foundry/RunContext/push_shell", test_run_context_push_shell);
+ return g_test_run ();
+}
diff --git a/src/tests/test-shortcuts.c b/src/tests/test-shortcuts.c
new file mode 100644
index 000000000..e917a2e33
--- /dev/null
+++ b/src/tests/test-shortcuts.c
@@ -0,0 +1,128 @@
+/* test-shortcuts.c
+ *
+ * Copyright 2022 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
+ */
+
+#include "config.h"
+
+#include <girepository.h>
+
+#include <libide-gui.h>
+
+#include "ide-shortcut-bundle-private.h"
+
+typedef struct
+{
+ guint open;
+} TestParseBundle;
+
+static void
+test_parse_bundle_open (GSimpleAction *action,
+ GVariant *param,
+ gpointer data)
+{
+ TestParseBundle *state = data;
+ state->open++;
+}
+
+static const GActionEntry actions[] = {
+ { "open", test_parse_bundle_open },
+};
+
+static void
+test_parse_bundle (void)
+{
+ GSimpleActionGroup *group;
+ IdeShortcutBundle *bundle;
+ GtkShortcut *shortcut;
+ GtkWidget *widget;
+ GError *error = NULL;
+ GFile *file;
+ gboolean r;
+ guint pos = 0;
+ TestParseBundle state = {0};
+
+ group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (group),
+ actions,
+ G_N_ELEMENTS (actions),
+ &state);
+
+ widget = gtk_window_new ();
+ gtk_widget_insert_action_group (widget, "test", G_ACTION_GROUP (group));
+
+ bundle = ide_shortcut_bundle_new ();
+ g_assert_nonnull (bundle);
+
+ file = g_file_new_build_filename (g_getenv ("G_TEST_SRCDIR"), "test-shortcuts.json", NULL);
+ g_assert_nonnull (file);
+ g_assert_true (g_file_query_exists (file, NULL));
+
+ r = ide_shortcut_bundle_parse (bundle, file, &error);
+ g_assert_no_error (error);
+ g_assert_true (r);
+
+ g_assert_true (G_IS_LIST_MODEL (bundle));
+ g_assert_true (g_list_model_get_item_type (G_LIST_MODEL (bundle)) == GTK_TYPE_SHORTCUT);
+ g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (bundle)), ==, 2);
+
+ shortcut = g_list_model_get_item (G_LIST_MODEL (bundle), pos++);
+ g_assert_nonnull (shortcut);
+ g_assert_true (GTK_IS_SHORTCUT (shortcut));
+ g_assert_false (gtk_shortcut_action_activate (gtk_shortcut_get_action (shortcut), 0, widget, NULL));
+ g_assert_cmpint (state.open, ==, 0);
+ g_object_unref (shortcut);
+
+ shortcut = g_list_model_get_item (G_LIST_MODEL (bundle), pos++);
+ g_assert_nonnull (shortcut);
+ g_assert_true (GTK_IS_SHORTCUT (shortcut));
+ g_assert_true (gtk_shortcut_action_activate (gtk_shortcut_get_action (shortcut), 0, widget, NULL));
+ g_assert_cmpint (state.open, ==, 1);
+ g_object_unref (shortcut);
+
+ shortcut = g_list_model_get_item (G_LIST_MODEL (bundle), pos++);
+ g_assert_null (shortcut);
+
+ gtk_window_destroy (GTK_WINDOW (widget));
+ g_assert_finalize_object (group);
+ g_assert_finalize_object (bundle);
+ g_assert_finalize_object (file);
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autofree char *path = NULL;
+ g_autoptr(GError) error = NULL;
+
+ g_assert_nonnull (g_getenv ("G_TEST_SRCDIR"));
+ g_assert_nonnull (g_getenv ("G_TEST_BUILDDIR"));
+
+ path = g_build_filename (g_getenv ("G_TEST_BUILDDIR"), "../", NULL);
+ g_irepository_prepend_search_path (path);
+ g_irepository_require (NULL, "Ide", PACKAGE_ABI_S, 0, &error);
+ g_assert_no_error (error);
+
+ gtk_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/Ide/ShortcutBundle/parse", test_parse_bundle);
+
+ return g_test_run ();
+}
diff --git a/src/tests/test-shortcuts.json b/src/tests/test-shortcuts.json
new file mode 100644
index 000000000..102ea0e52
--- /dev/null
+++ b/src/tests/test-shortcuts.json
@@ -0,0 +1,14 @@
+[
+ {
+ "action" : "test.open",
+ "when" : "!typeof(focus).is_a(typeof(Gtk.Window))",
+ "trigger" : "<ctrl>o",
+ "phase" : "bubble"
+ },
+ {
+ "action" : "test.open",
+ "when" : "focus != null",
+ "trigger" : "<ctrl>p",
+ "phase" : "capture"
+ }
+]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]