int main(int argc, char **argv) { gjs_crash_after_timeout(60*7); /* give the unit tests 7 minutes to complete */ g_test_init(&argc, &argv, NULL); g_test_add_func("/gjs/context/construct/destroy", gjstest_test_func_gjs_context_construct_destroy); g_test_add_func("/gjs/context/construct/eval", gjstest_test_func_gjs_context_construct_eval); g_test_add_func("/gjs/jsapi/util/array", gjstest_test_func_gjs_jsapi_util_array); g_test_add_func("/gjs/jsapi/util/error/throw", gjstest_test_func_gjs_jsapi_util_error_throw); g_test_add_func("/gjs/jsapi/util/string/js/string/utf8", gjstest_test_func_gjs_jsapi_util_string_js_string_utf8); g_test_add_func("/gjs/jsutil/strip_shebang/no_shebang", gjstest_test_strip_shebang_no_advance_for_no_shebang); g_test_add_func("/gjs/jsutil/strip_shebang/have_shebang", gjstest_test_strip_shebang_advance_for_shebang); g_test_add_func("/gjs/jsutil/strip_shebang/only_shebang", gjstest_test_strip_shebang_return_null_for_just_shebang); g_test_add_func("/util/glib/strv/concat/null", gjstest_test_func_util_glib_strv_concat_null); g_test_add_func("/util/glib/strv/concat/pointers", gjstest_test_func_util_glib_strv_concat_pointers); gjs_test_add_tests_for_coverage (); g_test_run(); return 0; }
int main(int argc, char **argv) { g_type_init (); gjs_crash_after_timeout(60*7); /* give the unit tests 7 minutes to complete */ g_test_init(&argc, &argv, NULL); gjstest_add_all_tests(); g_test_run(); return 0; }
int main(int argc, char **argv) { /* These are relative to top_builddir */ 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; const char *name; GString *path; GDir *dir; size_t i; working_dir = g_get_current_dir(); if(g_path_is_absolute(argv[0])) gjs_unit_path = g_strdup(argv[0]); else gjs_unit_path = g_build_filename(working_dir, argv[0], NULL); gjs_unit_dir = g_path_get_dirname(gjs_unit_path); /* the gjs-unit executable will be in <top_builddir>/.libs */ top_builddir = g_build_filename(gjs_unit_dir, "..", NULL); top_srcdir = g_build_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); /* 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 = g_build_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_setenv("XDG_DATA_HOME", data_home, FALSE); g_setenv("GJS_PATH", path->str, FALSE); gjs_crash_after_timeout(60*7); /* give the unit tests 7 minutes to complete */ gjs_init_sleep_on_crash(); setlocale(LC_ALL, ""); g_test_init(&argc, &argv, NULL); g_type_init(); /* iterate through all 'test*.js' files in ${top_srcdir}/test/js */ js_test_dir = g_build_filename(top_srcdir, "test", "js", NULL); dir = g_dir_open(js_test_dir, 0, NULL); g_assert(dir != NULL); while ((name = g_dir_read_name(dir)) != NULL) { char *test_name; char *file_name; if (!(g_str_has_prefix(name, "test") && g_str_has_suffix(name, ".js"))) 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(test_name); /* not freeing file_name as it's needed while running the test */ } g_dir_close(dir); return g_test_run (); }
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; }