Ejemplo n.º 1
0
static void
register_all_viewers (GjsContext *ctx)
{
  GDir *dir;
  const gchar *name;
  gchar *path;
  GError *error = NULL;

  dir = g_dir_open (SUSHI_PKGDATADIR "/js/viewers", 0, &error);

  if (dir == NULL) {
    g_warning ("Can't open module directory: %s\n", error->message);
    g_error_free (error);
    return;
  }
 
  name = g_dir_read_name (dir);

  while (name != NULL) {
    path = g_build_filename (SUSHI_PKGDATADIR "/js/viewers",
                             name, NULL);
    if (!gjs_context_eval_file (ctx,
                                path,
                                NULL,
                                &error)) {
      g_warning ("Unable to parse viewer %s: %s", name, error->message);
      g_clear_error (&error);
    }

    g_free (path);
    name = g_dir_read_name (dir);
  }

  g_dir_close (dir);
}
Ejemplo n.º 2
0
static void
setup(GjsTestJSFixture *fix,
      gconstpointer     test_data)
{
    gboolean success;
    GError *error = NULL;
    int code;
    char *filename;
    char *search_path[2];

    search_path[0] = g_build_filename(top_srcdir, "test", "modules", NULL);
    search_path[1] = NULL;

    fix->context = gjs_context_new_with_search_path(search_path);
    g_free(search_path[0]);

    /* Load jsUnit.js directly into global scope, rather than
     * requiring each test to import it as a module, among other
     * things this lets us test importing modules without relying on
     * importing a module, but also it's just less typing to have
     * "assert*" without a prefix.
     */
    filename = g_build_filename(top_srcdir, "modules", "jsUnit.js", NULL);
    success = gjs_context_eval_file(fix->context, filename, &code, &error);
    g_free(filename);

    if (!success)
        g_error("%s", error->message);
}
Ejemplo n.º 3
0
static EthosPlugin*
ethos_js_plugin_loader_load (EthosPluginLoader  *plugin_loader,
                             EthosPluginInfo    *plugin_info,
                             GError            **error)
{
	EthosJSPluginLoaderPrivate *priv;
	EthosPlugin                *plugin = NULL;
	const gchar                *filename,
	                           *module;
	gchar                      *dirname,
				   *basename,
				   *scriptname;
	gboolean                    success = FALSE;
	gint                        exit_status = 0;

	g_return_val_if_fail (ETHOS_IS_JS_PLUGIN_LOADER (plugin_loader), NULL);
	g_return_val_if_fail (ETHOS_IS_PLUGIN_INFO (plugin_info), NULL);

	priv = ETHOS_JS_PLUGIN_LOADER (plugin_loader)->priv;

	if (!(filename = ethos_plugin_info_get_filename (plugin_info))) {
		g_set_error (error, ETHOS_ERROR, ETHOS_ERROR_PLUGIN,
		             "Missing filename, cannot locate module");
		return NULL;
	}

	if (!(module = ethos_plugin_info_get_module (plugin_info))) {
		g_set_error (error, ETHOS_ERROR, ETHOS_ERROR_PLUGIN,
		             "Missing module name");
		return NULL;
	}

	dirname = g_path_get_dirname (filename);
	basename = g_strconcat (module, ".js", NULL);
	scriptname = g_build_filename (dirname, basename, NULL);

	if (!gjs_context_eval_file (priv->context,
	                            scriptname,
	                            &exit_status,
	                            error))
	        goto cleanup;

	if (priv->created_plugin) {
		plugin = priv->created_plugin;
		priv->created_plugin = NULL;
	}

cleanup:
	g_free (dirname);
	g_free (basename);
	g_free (scriptname);

	return plugin;
}
Ejemplo n.º 4
0
static void
test(GjsTestJSFixture *fix,
     gconstpointer     test_data)
{
    GError *error = NULL;
    gboolean success;
    int code;

    success = gjs_context_eval_file(fix->context, (const char*)test_data, &code, &error);
    if (!success)
        g_error("%s", error->message);
    g_assert(error == NULL);
    g_assert_cmpint(code, ==, 0);
}
Ejemplo n.º 5
0
static void
test(GjsTestJSFixture *fix,
     gconstpointer     test_data)
{
    GError *error = NULL;
    gboolean success;
    int code;

    success = gjs_context_eval_file(fix->context, (const char*)test_data, &code, &error);
    if (!success)
        g_error("%s", error->message);
    g_assert(error == NULL);
    if (code != 0)
        g_error("Test script returned code %d; assertions will be in gjs.log", code);
}