mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-12 21:48:50 +02:00
Add --enable-installed-tests configure option
See https://live.gnome.org/GnomeGoals/InstalledTests for more information. The tests now support being run both uninstalled and installed, so 'make check' works for those who want it. For tests which need data files, the way this works is they look in the compiled in value of SRCDIR by default, and the generated tests use "env G_TEST_DATA=" to override that. This patch only converts glib/tests for now; if this patch looks good, I'll do the rest of the tests. https://bugzilla.gnome.org/show_bug.cgi?id=699079
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ TAGS
|
|||||||
*.stp
|
*.stp
|
||||||
*.exe
|
*.exe
|
||||||
*.def
|
*.def
|
||||||
|
*.test
|
||||||
|
|
||||||
# autofoo stuff here
|
# autofoo stuff here
|
||||||
compile
|
compile
|
||||||
|
@ -258,7 +258,12 @@ AC_ARG_ENABLE(modular_tests,
|
|||||||
AS_HELP_STRING([--disable-modular-tests],
|
AS_HELP_STRING([--disable-modular-tests],
|
||||||
[Disable build of test programs (default: no)]),,
|
[Disable build of test programs (default: no)]),,
|
||||||
[enable_modular_tests=yes])
|
[enable_modular_tests=yes])
|
||||||
AM_CONDITIONAL(BUILD_MODULAR_TESTS, test x$enable_modular_tests = xyes)
|
AC_ARG_ENABLE(installed_tests,
|
||||||
|
AS_HELP_STRING([--enable-installed-tests],
|
||||||
|
[Install test programs (default: no)]),,
|
||||||
|
[enable_installed_tests=no])
|
||||||
|
AM_CONDITIONAL(BUILD_MODULAR_TESTS, test x$enable_modular_tests = xyes || test x$enable_installed_tests=xyes)
|
||||||
|
AM_CONDITIONAL(BUILDOPT_INSTALL_TESTS, test x$enable_installed_tests = xyes)
|
||||||
|
|
||||||
AC_MSG_CHECKING([whether to enable garbage collector friendliness])
|
AC_MSG_CHECKING([whether to enable garbage collector friendliness])
|
||||||
AS_IF([test "x$enable_gc_friendly" = "xyes"], [
|
AS_IF([test "x$enable_gc_friendly" = "xyes"], [
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
include $(top_srcdir)/Makefile.decl
|
include $(top_srcdir)/Makefile.decl
|
||||||
NULL =
|
NULL =
|
||||||
|
|
||||||
|
insttestdir=$(pkglibexecdir)/installed-tests
|
||||||
|
|
||||||
bookmark_test_files = \
|
bookmark_test_files = \
|
||||||
bookmarks/fail-01.xbel \
|
bookmarks/fail-01.xbel \
|
||||||
bookmarks/fail-02.xbel \
|
bookmarks/fail-02.xbel \
|
||||||
@ -66,6 +68,11 @@ AM_CFLAGS = $(GLIB_WARN_CFLAGS)
|
|||||||
LDADD = $(top_builddir)/glib/libglib-2.0.la -lm
|
LDADD = $(top_builddir)/glib/libglib-2.0.la -lm
|
||||||
|
|
||||||
TEST_PROGS += \
|
TEST_PROGS += \
|
||||||
|
1bit-emufutex \
|
||||||
|
gwakeup \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
all_test_programs = \
|
||||||
array-test \
|
array-test \
|
||||||
asyncqueue \
|
asyncqueue \
|
||||||
atomic \
|
atomic \
|
||||||
@ -86,7 +93,6 @@ TEST_PROGS += \
|
|||||||
fileutils \
|
fileutils \
|
||||||
gdatetime \
|
gdatetime \
|
||||||
gvariant \
|
gvariant \
|
||||||
gwakeup \
|
|
||||||
hash \
|
hash \
|
||||||
hmac \
|
hmac \
|
||||||
hook \
|
hook \
|
||||||
@ -137,11 +143,43 @@ TEST_PROGS += \
|
|||||||
unicode \
|
unicode \
|
||||||
uri \
|
uri \
|
||||||
1bit-mutex \
|
1bit-mutex \
|
||||||
1bit-emufutex \
|
|
||||||
642026 \
|
642026 \
|
||||||
642026-ec
|
642026-ec
|
||||||
|
|
||||||
noinst_PROGRAMS = $(TEST_PROGS) test-spawn-echo
|
if OS_UNIX
|
||||||
|
all_test_programs += unix
|
||||||
|
all_test_programs += include
|
||||||
|
endif
|
||||||
|
|
||||||
|
extra_test_binaries = test-spawn-echo
|
||||||
|
|
||||||
|
if BUILD_MODULAR_TESTS
|
||||||
|
TEST_PROGS += $(all_test_programs)
|
||||||
|
noinst_PROGRAMS = $(TEST_PROGS) $(extra_test_binaries)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if BUILDOPT_INSTALL_TESTS
|
||||||
|
insttest_PROGRAMS = $(all_test_programs) $(extra_test_binaries)
|
||||||
|
testmetadir = $(datadir)/installed-tests/$(PACKAGE)
|
||||||
|
testmeta_DATA = $(all_test_programs:=.test)
|
||||||
|
|
||||||
|
testdatadir=$(insttestdir)
|
||||||
|
testdata_DATA = $(test_files)
|
||||||
|
|
||||||
|
testdata_SCRIPTS = $(test_script_files)
|
||||||
|
|
||||||
|
bookmarksdir=$(insttestdir)/bookmarks
|
||||||
|
bookmarks_DATA = $(bookmark_test_files)
|
||||||
|
|
||||||
|
markupsdir=$(insttestdir)/markups
|
||||||
|
markups_DATA = $(all_markup_test_files)
|
||||||
|
endif
|
||||||
|
|
||||||
|
%.test: % Makefile
|
||||||
|
$(AM_V_GEN) (echo '[Test]' > $@.tmp; \
|
||||||
|
echo 'Type=session' >> $@.tmp; \
|
||||||
|
echo 'Exec=env G_TEST_DATA=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$<' >> $@.tmp; \
|
||||||
|
mv $@.tmp $@)
|
||||||
|
|
||||||
atomic_CFLAGS = $(AM_CFLAGS)
|
atomic_CFLAGS = $(AM_CFLAGS)
|
||||||
if HAVE_GCC
|
if HAVE_GCC
|
||||||
@ -164,9 +202,6 @@ endif
|
|||||||
|
|
||||||
if OS_UNIX
|
if OS_UNIX
|
||||||
|
|
||||||
TEST_PROGS += unix
|
|
||||||
TEST_PROGS += include
|
|
||||||
|
|
||||||
# some testing of gtester functionality
|
# some testing of gtester functionality
|
||||||
XMLLINT = xmllint
|
XMLLINT = xmllint
|
||||||
|
|
||||||
|
@ -268,6 +268,7 @@ main (int argc, char *argv[])
|
|||||||
GError *error;
|
GError *error;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
const gchar *datapath;
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
@ -278,12 +279,18 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
dir = g_dir_open (SRCDIR "/bookmarks", 0, &error);
|
if (g_getenv ("G_TEST_DATA"))
|
||||||
|
datapath = g_getenv ("G_TEST_DATA");
|
||||||
|
else
|
||||||
|
datapath = SRCDIR;
|
||||||
|
path = g_build_filename (datapath, "bookmarks", NULL);
|
||||||
|
dir = g_dir_open (path, 0, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
while ((name = g_dir_read_name (dir)) != NULL)
|
while ((name = g_dir_read_name (dir)) != NULL)
|
||||||
{
|
{
|
||||||
path = g_strdup_printf ("/bookmarks/parse/%s", name);
|
path = g_strdup_printf ("/bookmarks/parse/%s", name);
|
||||||
g_test_add_data_func_full (path, g_build_filename (SRCDIR, "bookmarks", name, NULL),
|
g_test_add_data_func_full (path, g_build_filename (datapath, "bookmarks", name, NULL),
|
||||||
test_file, g_free);
|
test_file, g_free);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static const gchar *datapath;
|
||||||
|
|
||||||
static GKeyFile *
|
static GKeyFile *
|
||||||
load_data (const gchar *data,
|
load_data (const gchar *data,
|
||||||
GKeyFileFlags flags)
|
GKeyFileFlags flags)
|
||||||
@ -1337,10 +1339,13 @@ test_load_fail (void)
|
|||||||
{
|
{
|
||||||
GKeyFile *file;
|
GKeyFile *file;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
file = g_key_file_new ();
|
file = g_key_file_new ();
|
||||||
error = NULL;
|
error = NULL;
|
||||||
g_assert (!g_key_file_load_from_file (file, SRCDIR "/keyfile.c", 0, &error));
|
path = g_build_filename (datapath, "keyfile.c", NULL);
|
||||||
|
g_assert (!g_key_file_load_from_file (file, path, 0, &error));
|
||||||
|
g_free (path);
|
||||||
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
|
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
g_assert (!g_key_file_load_from_file (file, "/nosuchfile", 0, &error));
|
g_assert (!g_key_file_load_from_file (file, "/nosuchfile", 0, &error));
|
||||||
@ -1395,6 +1400,7 @@ test_page_boundary (void)
|
|||||||
GKeyFile *file;
|
GKeyFile *file;
|
||||||
GError *error;
|
GError *error;
|
||||||
gint i;
|
gint i;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
#define GROUP "main_section"
|
#define GROUP "main_section"
|
||||||
#define KEY_PREFIX "fill_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw_"
|
#define KEY_PREFIX "fill_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw_"
|
||||||
@ -1407,7 +1413,9 @@ test_page_boundary (void)
|
|||||||
file = g_key_file_new ();
|
file = g_key_file_new ();
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
g_key_file_load_from_file (file, SRCDIR "/pages.ini", G_KEY_FILE_NONE, &error);
|
path = g_build_filename (datapath, "pages.ini", NULL);
|
||||||
|
g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
for (i = FIRST_KEY; i <= LAST_KEY; i++)
|
for (i = FIRST_KEY; i <= LAST_KEY; i++)
|
||||||
@ -1569,8 +1577,13 @@ test_roundtrip (void)
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
if (g_getenv ("G_TEST_DATA"))
|
||||||
|
datapath = g_getenv ("G_TEST_DATA");
|
||||||
|
else
|
||||||
|
datapath = SRCDIR;
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
g_setenv ("XDG_DATA_HOME", SRCDIR, TRUE);
|
g_setenv ("XDG_DATA_HOME", datapath, TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
@ -11,14 +11,19 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
static const gchar *datapath;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_basic (void)
|
test_basic (void)
|
||||||
{
|
{
|
||||||
GMappedFile *file;
|
GMappedFile *file;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
|
path = g_build_filename (datapath, "empty", NULL);
|
||||||
|
file = g_mapped_file_new (path, FALSE, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_mapped_file_ref (file);
|
g_mapped_file_ref (file);
|
||||||
@ -32,9 +37,12 @@ test_empty (void)
|
|||||||
{
|
{
|
||||||
GMappedFile *file;
|
GMappedFile *file;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
|
path = g_build_filename (datapath, "empty", NULL);
|
||||||
|
file = g_mapped_file_new (path, FALSE, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
g_assert (g_mapped_file_get_contents (file) == NULL);
|
g_assert (g_mapped_file_get_contents (file) == NULL);
|
||||||
@ -82,7 +90,7 @@ test_writable (void)
|
|||||||
char *srcpath;
|
char *srcpath;
|
||||||
gchar *tmp_copy_path;
|
gchar *tmp_copy_path;
|
||||||
|
|
||||||
srcpath = g_build_filename (SRCDIR, "4096-random-bytes", NULL);
|
srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
|
||||||
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
|
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
|
||||||
|
|
||||||
g_file_get_contents (srcpath, &contents, &len, &error);
|
g_file_get_contents (srcpath, &contents, &len, &error);
|
||||||
@ -129,7 +137,7 @@ test_writable_fd (void)
|
|||||||
char *srcpath;
|
char *srcpath;
|
||||||
gchar *tmp_copy_path;
|
gchar *tmp_copy_path;
|
||||||
|
|
||||||
srcpath = g_build_filename (SRCDIR, "4096-random-bytes", NULL);
|
srcpath = g_build_filename (datapath, "4096-random-bytes", NULL);
|
||||||
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
|
tmp_copy_path = g_build_filename (g_get_user_runtime_dir (), "glib-test-4096-random-bytes", NULL);
|
||||||
|
|
||||||
g_file_get_contents (srcpath, &contents, &len, &error);
|
g_file_get_contents (srcpath, &contents, &len, &error);
|
||||||
@ -174,9 +182,12 @@ test_gbytes (void)
|
|||||||
GMappedFile *file;
|
GMappedFile *file;
|
||||||
GBytes *bytes;
|
GBytes *bytes;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
file = g_mapped_file_new (SRCDIR "/empty", FALSE, &error);
|
path = g_build_filename (datapath, "empty", NULL);
|
||||||
|
file = g_mapped_file_new (path, FALSE, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
bytes = g_mapped_file_get_bytes (file);
|
bytes = g_mapped_file_get_bytes (file);
|
||||||
@ -189,6 +200,11 @@ test_gbytes (void)
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
if (g_getenv ("G_TEST_DATA"))
|
||||||
|
datapath = g_getenv ("G_TEST_DATA");
|
||||||
|
else
|
||||||
|
datapath = SRCDIR;
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/mappedfile/basic", test_basic);
|
g_test_add_func ("/mappedfile/basic", test_basic);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
static int depth = 0;
|
static int depth = 0;
|
||||||
static GString *string;
|
static GString *string;
|
||||||
|
static const gchar *datapath;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
indent (int extra)
|
indent (int extra)
|
||||||
@ -277,6 +278,11 @@ main (int argc, char *argv[])
|
|||||||
const gchar *name;
|
const gchar *name;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
|
||||||
|
if (g_getenv ("G_TEST_DATA"))
|
||||||
|
datapath = g_getenv ("G_TEST_DATA");
|
||||||
|
else
|
||||||
|
datapath = SRCDIR;
|
||||||
|
|
||||||
g_setenv ("LANG", "en_US.utf-8", TRUE);
|
g_setenv ("LANG", "en_US.utf-8", TRUE);
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
|
|
||||||
@ -292,7 +298,9 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
dir = g_dir_open (SRCDIR "/markups", 0, &error);
|
path = g_build_filename (datapath, "markups", NULL);
|
||||||
|
dir = g_dir_open (path, 0, &error);
|
||||||
|
g_free (path);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
while ((name = g_dir_read_name (dir)) != NULL)
|
while ((name = g_dir_read_name (dir)) != NULL)
|
||||||
{
|
{
|
||||||
@ -300,7 +308,7 @@ main (int argc, char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
path = g_strdup_printf ("/markup/parse/%s", name);
|
path = g_strdup_printf ("/markup/parse/%s", name);
|
||||||
g_test_add_data_func_full (path, g_build_filename (SRCDIR, "markups", name, NULL),
|
g_test_add_data_func_full (path, g_build_filename (datapath, "markups", name, NULL),
|
||||||
test_parse, g_free);
|
test_parse, g_free);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#define pipe(fds) _pipe(fds, 4096, _O_BINARY)
|
#define pipe(fds) _pipe(fds, 4096, _O_BINARY)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char *argv0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
debug (void)
|
debug (void)
|
||||||
{
|
{
|
||||||
@ -119,7 +121,7 @@ static void
|
|||||||
test_message (void)
|
test_message (void)
|
||||||
{
|
{
|
||||||
gchar* argv[] = {
|
gchar* argv[] = {
|
||||||
"./protocol",
|
argv0,
|
||||||
NULL,
|
NULL,
|
||||||
"--GTestSubprocess",
|
"--GTestSubprocess",
|
||||||
"-p", "/glib/testing/protocol/debug",
|
"-p", "/glib/testing/protocol/debug",
|
||||||
@ -239,7 +241,7 @@ test_error (void)
|
|||||||
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||||
{
|
{
|
||||||
gchar* argv[] = {
|
gchar* argv[] = {
|
||||||
"./protocol",
|
argv0,
|
||||||
NULL,
|
NULL,
|
||||||
"--GTestSubprocess",
|
"--GTestSubprocess",
|
||||||
"-p", tests[i],
|
"-p", tests[i],
|
||||||
@ -336,6 +338,8 @@ int
|
|||||||
main (int argc,
|
main (int argc,
|
||||||
char**argv)
|
char**argv)
|
||||||
{
|
{
|
||||||
|
argv0 = argv[0];
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
/* we use ourself as the testcase, these are the ones we need internally */
|
/* we use ourself as the testcase, these are the ones we need internally */
|
||||||
|
Reference in New Issue
Block a user