[gnome-builder/wip/gtk4-port] libide/foundry: allow setting locality for unit tests



commit 1ab1686cd11d00d6dff44d1a3fbfa094eb547b8c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 7 16:58:47 2022 -0700

    libide/foundry: allow setting locality for unit tests
    
    This allows running the unit tests in either the runtime or pipeline
    environments. This can be a bit more convenient than spinning up a
    fake display for unit tests.
    
    We do want peope to be aware that unit tests should be automated in the
    CI, and therefore display access is not necessarily a given.

 .../org.gnome.builder.project.gschema.xml          | 10 +++++++++
 src/libide/foundry/ide-test.c                      | 25 ++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.project.gschema.xml 
b/data/gsettings/org.gnome.builder.project.gschema.xml
index b5f3d0144..5a653cba1 100644
--- a/data/gsettings/org.gnome.builder.project.gschema.xml
+++ b/data/gsettings/org.gnome.builder.project.gschema.xml
@@ -29,5 +29,15 @@
       <description>This allows sending something other than sigkill to stop the target application. That 
might be useful when you want to gracefully shutdown a server process.</description>
     </key>
 
+    <key name="unit-test-locality" type="s">
+      <choices>
+        <choice value="pipeline"/>
+        <choice value="runtime"/>
+      </choices>
+      <default>'pipeline'</default>
+      <summary>Unit Test Locality</summary>
+      <description>What environment to use when running unit tests</description>
+    </key>
+
   </schema>
 </schemalist>
diff --git a/src/libide/foundry/ide-test.c b/src/libide/foundry/ide-test.c
index 33d5c2305..55790ccc9 100644
--- a/src/libide/foundry/ide-test.c
+++ b/src/libide/foundry/ide-test.c
@@ -29,6 +29,7 @@
 #include "ide-run-context.h"
 #include "ide-foundry-enums.h"
 #include "ide-pipeline.h"
+#include "ide-runtime.h"
 #include "ide-test.h"
 
 struct _IdeTest
@@ -290,8 +291,12 @@ ide_test_run_async (IdeTest             *self,
 {
   g_autoptr(IdeRunContext) run_context = NULL;
   g_autoptr(IdeSubprocess) subprocess = NULL;
+  g_autoptr(GSettings) settings = NULL;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GError) error = NULL;
+  g_autofree char *locality = NULL;
+  IdeContext *context;
+  IdeRuntime *runtime;
 
   IDE_ENTRY;
 
@@ -306,8 +311,24 @@ ide_test_run_async (IdeTest             *self,
   if (ide_task_return_error_if_cancelled (task))
     IDE_EXIT;
 
-  run_context = ide_pipeline_create_run_context (pipeline, self->run_command);
-  ide_run_context_set_pty (run_context, pty);
+  context = ide_object_get_context (IDE_OBJECT (pipeline));
+  runtime = ide_pipeline_get_runtime (pipeline);
+  settings = ide_context_ref_project_settings (context);
+  locality = g_settings_get_string (settings, "unit-test-locality");
+
+  if (ide_str_equal0 (locality, "runtime"))
+    {
+      run_context = ide_run_context_new ();
+      ide_runtime_prepare_to_run (runtime, pipeline, run_context);
+      ide_run_command_prepare_to_run (self->run_command, run_context, context);
+    }
+  else /* "pipeline" */
+    {
+      run_context = ide_pipeline_create_run_context (pipeline, self->run_command);
+    }
+
+  if (pty != NULL)
+    ide_run_context_set_pty (run_context, pty);
 
   if (!(subprocess = ide_run_context_spawn (run_context, &error)))
     {


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