int main(int argc, char **argv) { char *js_test_dir; GSList *all_tests, *iter; GSList *all_registered_test_data = NULL; int retval; /* The tests are known to fail in the presence of the JIT; * we leak objects. * https://bugzilla.gnome.org/show_bug.cgi?id=616193 */ g_setenv("GJS_DISABLE_JIT", "1", FALSE); /* The fact that this isn't the default is kind of lame... */ g_setenv("GJS_DEBUG_OUTPUT", "stderr", FALSE); setlocale(LC_ALL, ""); g_test_init(&argc, &argv, NULL); if (g_getenv ("GJS_USE_UNINSTALLED_FILES") != NULL) { /* typelib path is handled by the environment */ js_test_dir = g_build_filename(g_getenv ("TOP_SRCDIR"), "installed-tests", "js", NULL); } else { g_irepository_prepend_search_path(INSTTESTDIR); js_test_dir = g_build_filename(INSTTESTDIR, "js", NULL); } const char *coverage_prefix = g_getenv("GJS_UNIT_COVERAGE_PREFIX"); const char *coverage_output_directory = g_getenv("GJS_UNIT_COVERAGE_OUTPUT"); all_tests = read_all_dir_sorted(js_test_dir); for (iter = all_tests; iter; iter = iter->next) { char *name = (char*) iter->data; char *test_name; char *file_name; GjsTestData *test_data; if (!(g_str_has_prefix(name, "test") && g_str_has_suffix(name, ".js"))) { g_free(name); continue; } if (g_str_has_prefix (name, "testCairo") && g_getenv ("GJS_TEST_SKIP_CAIRO")) continue; /* pretty print, drop 'test' prefix and '.js' suffix from test name */ test_name = g_strconcat("/js/", name + 4, NULL); test_name[strlen(test_name)-3] = '\0'; file_name = g_build_filename(js_test_dir, name, NULL); test_data = gjs_unit_test_data_new(coverage_prefix, coverage_output_directory, file_name); g_test_add(test_name, GjsTestJSFixture, test_data, setup, test, teardown); g_free(name); g_free(test_name); all_registered_test_data = g_slist_prepend(all_registered_test_data, test_data); /* not freeing file_name or test_data yet as it's needed while running the test */ } g_free(js_test_dir); g_slist_free(all_tests); retval = g_test_run (); g_slist_foreach(all_registered_test_data, (GFunc)gjs_unit_test_data_free, all_registered_test_data); g_slist_free(all_registered_test_data); return retval; }
int main(int argc, char **argv) { /* These may be absolute or relative to top_builddir, depending whether * GJS_TOP_SRCDIR is absolute or not */ const char * const path_directories[] = { GJS_TOP_SRCDIR"/modules", GJS_TOP_SRCDIR"/test/js/modules", ".libs:", NULL }; char *js_test_dir; char *working_dir; char *gjs_unit_path; char *gjs_unit_dir; char *top_builddir; char *data_home; GString *path; size_t i; GSList *all_tests, *iter; GSList *test_filenames = NULL; int retval; working_dir = g_get_current_dir(); gjs_unit_path = build_absolute_filename(argv[0], NULL); gjs_unit_dir = g_path_get_dirname(gjs_unit_path); g_free(gjs_unit_path); /* the gjs-unit executable will be in <top_builddir>/.libs */ top_builddir = g_path_get_dirname(gjs_unit_dir); g_free(gjs_unit_dir); top_srcdir = build_absolute_filename(top_builddir, GJS_TOP_SRCDIR, NULL); /* Normalize, not strictly necessary */ g_chdir(top_builddir); g_free(top_builddir); top_builddir = g_get_current_dir(); g_chdir(top_srcdir); g_free(top_srcdir); top_srcdir = g_get_current_dir(); g_chdir(working_dir); g_free(working_dir); /* we're always going to use uninstalled files, set up necessary * environment variables, but don't overwrite if already set */ data_home = g_build_filename(top_builddir, "test_user_data", NULL); path = g_string_new(NULL); for(i = 0; i < G_N_ELEMENTS(path_directories); i++) { char *directory; if (i != 0) g_string_append_c(path, ':'); directory = build_absolute_filename(top_builddir, path_directories[i], NULL); g_string_append(path, directory); g_free(directory); } g_setenv("TOP_SRCDIR", top_srcdir, FALSE); g_setenv("BUILDDIR", top_builddir, FALSE); g_free(top_builddir); g_setenv("XDG_DATA_HOME", data_home, FALSE); g_free(data_home); g_setenv("GJS_PATH", path->str, FALSE); g_string_free(path, TRUE); /* The tests are known to fail in the presence of the JIT; * we leak objects. * https://bugzilla.gnome.org/show_bug.cgi?id=616193 */ g_setenv("GJS_DISABLE_JIT", "1", FALSE); { const char *timeout_str = g_getenv("GJS_TEST_TIMEOUT"); if (timeout_str != NULL) { guint timeout = (guint)g_ascii_strtoull(timeout_str, NULL, 10); if (timeout > 0) gjs_crash_after_timeout(timeout); } } setlocale(LC_ALL, ""); g_test_init(&argc, &argv, NULL); /* iterate through all 'test*.js' files in ${top_srcdir}/test/js */ js_test_dir = g_build_filename(top_srcdir, "test", "js", NULL); all_tests = read_all_dir_sorted(js_test_dir); for (iter = all_tests; iter; iter = iter->next) { char *name = iter->data; char *test_name; char *file_name; if (!(g_str_has_prefix(name, "test") && g_str_has_suffix(name, ".js"))) { g_free(name); continue; } if (g_str_has_prefix (name, "testCairo") && g_getenv ("GJS_TEST_SKIP_CAIRO")) continue; /* pretty print, drop 'test' prefix and '.js' suffix from test name */ test_name = g_strconcat("/js/", name + 4, NULL); test_name[strlen(test_name)-3] = '\0'; file_name = g_build_filename(js_test_dir, name, NULL); g_test_add(test_name, GjsTestJSFixture, file_name, setup, test, teardown); g_free(name); g_free(test_name); test_filenames = g_slist_prepend(test_filenames, file_name); /* not freeing file_name yet as it's needed while running the test */ } g_free(js_test_dir); g_slist_free(all_tests); retval = g_test_run (); g_slist_foreach(test_filenames, (GFunc)g_free, test_filenames); g_slist_free(test_filenames); g_free(top_srcdir); return retval; }