tests: Use gjs_context_eval_file to evaluate test scripts
GJS provides utilities to run scripts given a filename, using those utilities we can remove most of the logic implementing file loading. Additionally the REPL logic does not make much sense for a test runner and is unused, so remove it. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>
This commit is contained in:
parent
011ac6f83c
commit
b798efcc1d
@ -36,13 +36,6 @@
|
||||
#include "shell-global.h"
|
||||
#include "shell-global-private.h"
|
||||
|
||||
static char *command = NULL;
|
||||
|
||||
static GOptionEntry entries[] = {
|
||||
{ "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Program passed in as a string", "COMMAND" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -50,10 +43,8 @@ main(int argc, char **argv)
|
||||
GError *error = NULL;
|
||||
ShellGlobal *global;
|
||||
GjsContext *js_context;
|
||||
char *script;
|
||||
const char *filename;
|
||||
char *title;
|
||||
gsize len;
|
||||
int code;
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
@ -61,7 +52,6 @@ main(int argc, char **argv)
|
||||
/* pass unknown through to the JS script */
|
||||
g_option_context_set_ignore_unknown_options (context, TRUE);
|
||||
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||
g_error ("option parsing failed: %s", error->message);
|
||||
|
||||
@ -79,32 +69,21 @@ main(int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (command != NULL) {
|
||||
script = command;
|
||||
len = strlen (script);
|
||||
filename = "<command line>";
|
||||
} else if (argc <= 1) {
|
||||
script = g_strdup ("const Console = imports.console; Console.interact();");
|
||||
len = strlen (script);
|
||||
filename = "<stdin>";
|
||||
} else /*if (argc >= 2)*/ {
|
||||
error = NULL;
|
||||
if (!g_file_get_contents (argv[1], &script, &len, &error)) {
|
||||
g_printerr ("%s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
filename = argv[1];
|
||||
if (argc < 2) {
|
||||
g_printerr ("Missing filename");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
filename = argv[1];
|
||||
title = g_filename_display_basename (filename);
|
||||
g_set_prgname (title);
|
||||
g_free (title);
|
||||
|
||||
/* evaluate the script */
|
||||
error = NULL;
|
||||
if (!gjs_context_eval (js_context, script, len,
|
||||
filename, &code, &error)) {
|
||||
g_free (script);
|
||||
|
||||
/* evaluate the script */
|
||||
bool success = gjs_context_eval_file(js_context, filename, &code, &error);
|
||||
if (!success) {
|
||||
g_printerr ("%s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
@ -113,6 +92,5 @@ main(int argc, char **argv)
|
||||
gjs_context_gc (js_context);
|
||||
|
||||
g_object_unref (js_context);
|
||||
g_free (script);
|
||||
exit (code);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user