tests: Load unit tests as modules

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
This commit is contained in:
Evan Welsh 2023-07-09 22:19:40 -07:00
parent 3f667be2e8
commit 26fa1046a3
7 changed files with 8 additions and 11 deletions

View File

@ -45,7 +45,7 @@ main(int argc, char **argv)
GjsContext *js_context; GjsContext *js_context;
const char *filename; const char *filename;
char *title; char *title;
int code; uint8_t code;
context = g_option_context_new (NULL); context = g_option_context_new (NULL);
@ -82,7 +82,7 @@ main(int argc, char **argv)
error = NULL; error = NULL;
/* evaluate the script */ /* evaluate the script */
bool success = gjs_context_eval_file(js_context, filename, &code, &error); bool success = gjs_context_eval_module_file(js_context, filename, &code, &error);
if (!success) { if (!success) {
g_printerr ("%s\n", error->message); g_printerr ("%s\n", error->message);
exit (1); exit (1);

View File

@ -1,5 +1,3 @@
/* exported assertArrayEquals */
const JsUnit = imports.jsUnit; const JsUnit = imports.jsUnit;
/** /**
@ -10,7 +8,7 @@ const JsUnit = imports.jsUnit;
* @param {T[]} array1 the first array * @param {T[]} array1 the first array
* @param {T[]} array2 the second array * @param {T[]} array2 the second array
*/ */
function assertArrayEquals(errorMessage, array1, array2) { export function assertArrayEquals(errorMessage, array1, array2) {
JsUnit.assertEquals(`${errorMessage} length`, array1.length, array2.length); JsUnit.assertEquals(`${errorMessage} length`, array1.length, array2.length);
for (let j = 0; j < array1.length; j++) for (let j = 0; j < array1.length; j++)
JsUnit.assertEquals(`${errorMessage} item ${j}`, array1[j], array2[j]); JsUnit.assertEquals(`${errorMessage} item ${j}`, array1[j], array2[j]);

View File

@ -3,7 +3,7 @@
// Test cases for SearchResult description match highlighter // Test cases for SearchResult description match highlighter
const JsUnit = imports.jsUnit; const JsUnit = imports.jsUnit;
const Pango = imports.gi.Pango; import Pango from 'gi://Pango';
const Environment = imports.ui.environment; const Environment = imports.ui.environment;
Environment.init(); Environment.init();

View File

@ -1,8 +1,7 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
// Test cases for Util.insertSorted // Test cases for Util.insertSorted
import * as Assertions from '../common/assertions.js';
const Assertions = imports.common.assertions;
// Needed so that Util can bring some UI stuff // Needed so that Util can bring some UI stuff
// we don't actually use // we don't actually use

View File

@ -4,7 +4,7 @@
const JsUnit = imports.jsUnit; const JsUnit = imports.jsUnit;
const Assertions = imports.common.assertions; import * as Assertions from '../common/assertions.js';
const Environment = imports.ui.environment; const Environment = imports.ui.environment;
Environment.init(); Environment.init();

View File

@ -3,7 +3,7 @@
// Test cases for MessageList markup parsing // Test cases for MessageList markup parsing
const JsUnit = imports.jsUnit; const JsUnit = imports.jsUnit;
const Pango = imports.gi.Pango; import Pango from 'gi://Pango';
const Environment = imports.ui.environment; const Environment = imports.ui.environment;
Environment.init(); Environment.init();

View File

@ -2,7 +2,7 @@
// Test cases for version comparison // Test cases for version comparison
const GObject = imports.gi.GObject; import GObject from 'gi://GObject';
const JsUnit = imports.jsUnit; const JsUnit = imports.jsUnit;
const Signals = imports.misc.signals; const Signals = imports.misc.signals;