summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2023-03-18 12:43:22 +0100
committerVivien Kraus <vivien@planete-kraus.eu>2023-03-18 15:19:25 +0100
commitca7a01bd4efca9cba9169a9f8792bd7da427553a (patch)
tree2cf81839054e6ce396f1a03e8e72eb41b56c1d72
parent59011ddd2b058c3797b0eaed2eb3bc01db1e96ea (diff)
Add a program to run unit tests.
This is not possible in a Gtk application, because glib does not play nice with the check library.
-rw-r--r--Makefile.am1
-rw-r--r--bootstrap.conf2
-rw-r--r--guix.scm32
-rw-r--r--src/disfluid/Makefile.am21
-rw-r--r--src/disfluid/run-unit-tests.c65
5 files changed, 116 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 515465e..af53e3f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,6 +7,7 @@ LTV_AGE = 0
DLL_VERSION = $$(expr $(LTV_CURRENT) - $(LTV_AGE))
bin_PROGRAMS =
+libexec_PROGRAMS =
lib_LTLIBRARIES =
noinst_LTLIBRARIES =
include_HEADERS =
diff --git a/bootstrap.conf b/bootstrap.conf
index 8de9c9d..9c3997c 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -91,5 +91,5 @@ bootstrap_post_import_hook ()
--with-tests \
--tests-base=tests/libprog \
--tests-makefile-name=Makefile.am \
- relocatable-prog gettext-h locale setlocale stdbool attribute
+ relocatable-prog gettext-h locale setlocale stdbool attribute execv
}
diff --git a/guix.scm b/guix.scm
index 475946b..7592051 100644
--- a/guix.scm
+++ b/guix.scm
@@ -301,10 +301,34 @@
(("#!/gnu/store/.*/bin/sh")
"#!/bin/sh")))
(with-directory-excursion "tests/libprog"
- (substitute* '("test-verify.sh" "test-select-out.sh" "test-select-in.sh"
- "test-xalloc-die.sh" "test-setlocale1.sh"
- "test-binary-io.sh" "test-ftruncate.sh"
- "test-init.sh" "test-setlocale2.sh" "test-perror.sh")
+ (substitute* '(
+ "executable-shell-script"
+ "test-binary-io.sh"
+ "test-execv.sh"
+ "test-execve.sh"
+ "test-fflush2.sh"
+ "test-fseek.sh"
+ "test-fseek2.sh"
+ "test-fseeko.sh"
+ "test-fseeko2.sh"
+ "test-fseeko3.sh"
+ "test-fseeko4.sh"
+ "test-ftell.sh"
+ "test-ftell2.sh"
+ "test-ftello.sh"
+ "test-ftello2.sh"
+ "test-ftello4.sh"
+ "test-ftruncate.sh"
+ "test-init.sh"
+ "test-lseek.sh"
+ "test-perror.sh"
+ "test-select-in.sh"
+ "test-select-out.sh"
+ "test-setlocale1.sh"
+ "test-setlocale2.sh"
+ "test-verify.sh"
+ "test-xalloc-die.sh"
+ )
(("#!/gnu/store/.*/bin/sh")
"#!/bin/sh"))))
(invoke "sh" "-c" "grep '/gnu/store/' -R disfluid-* && exit 1 ; true")
diff --git a/src/disfluid/Makefile.am b/src/disfluid/Makefile.am
index f9a4646..555d455 100644
--- a/src/disfluid/Makefile.am
+++ b/src/disfluid/Makefile.am
@@ -1,4 +1,5 @@
bin_PROGRAMS += %D%/disfluid
+libexec_PROGRAMS += %D%/disfluid-run-unit-tests
%C%_disfluid_SOURCES = \
%D%/main.c
@@ -14,6 +15,26 @@ bin_PROGRAMS += %D%/disfluid
src/adwaita/libdisfluid-adwaita.la \
$(LIBTHREAD) \
$(LTLIBINTL) \
+ $(POSIX_SPAWN_LIB) \
+ $(SETLOCALE_LIB) \
+ $(SETLOCALE_NULL_LIB) \
+ @INTL_MACOSX_LIBS@
+
+%C%_disfluid_run_unit_tests_SOURCES = \
+ %D%/run-unit-tests.c
+%C%_disfluid_run_unit_tests_CPPFLAGS = \
+ -I libprog -I $(srcdir)/libprog \
+ -I include -I $(srcdir)/include \
+ -DLOCALEDIR=\"$(localedir)\" \
+ -DINSTALLDIR=\"$(bindir)\" \
+ -DGETTEXT_PACKAGE=\"$(PACKAGE)\"
+%C%_disfluid_run_unit_tests_LDADD = \
+ libprog/libgnu.la \
+ src/libdisfluid/libdisfluid.la \
+ src/adwaita/libdisfluid-adwaita.la \
+ $(LIBTHREAD) \
+ $(LTLIBINTL) \
+ $(POSIX_SPAWN_LIB) \
$(SETLOCALE_LIB) \
$(SETLOCALE_NULL_LIB) \
@INTL_MACOSX_LIBS@
diff --git a/src/disfluid/run-unit-tests.c b/src/disfluid/run-unit-tests.c
new file mode 100644
index 0000000..80aec25
--- /dev/null
+++ b/src/disfluid/run-unit-tests.c
@@ -0,0 +1,65 @@
+#include <config.h>
+#include "attribute.h"
+#include <disfluid.h>
+
+#include <unistd.h>
+#include <locale.h>
+#include "gettext.h"
+#include "progname.h"
+#include "relocatable.h"
+
+#include <glib.h>
+
+#define _(String) gettext (String)
+#define N_(String) (String)
+
+int
+main (int argc, char *argv[])
+{
+ (void) argc;
+ set_program_name (argv[0]);
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, relocate (LOCALEDIR));
+ textdomain (PACKAGE);
+ size_t n_tests, n_errors;
+ char *tests_output = disfluid_run_tests (&n_tests, &n_errors);
+ const char *bindir = relocate (INSTALLDIR);
+ char *disfluid_exec = malloc (strlen (bindir) + strlen ("/disfluid") + 1);
+ if (disfluid_exec == NULL)
+ {
+ abort ();
+ }
+ strcpy (disfluid_exec, bindir);
+ strcat (disfluid_exec, "/disfluid");
+ const char *arg_0 = disfluid_exec;
+ char *arg_1 = NULL;
+ if (asprintf (&arg_1, "--%s=%lu", _("n-tests-run"), n_tests) < 0)
+ {
+ abort ();
+ }
+ char *arg_2 = NULL;
+ if (asprintf (&arg_2, "--%s=%lu", _("n-tests-errors"), n_errors) < 0)
+ {
+ abort ();
+ }
+ char *arg_3 = NULL;
+ if (asprintf (&arg_3, "--%s=%s", _("tests-output"), tests_output) < 0)
+ {
+ abort ();
+ }
+ char *args[] = { (char *) arg_0, arg_1, arg_2, arg_3 };
+ int error = execv (disfluid_exec, args);
+ free (arg_1);
+ free (arg_2);
+ free (arg_3);
+ free (tests_output);
+ if (error)
+ {
+ fprintf (stderr, "%s:%d: cannot execute %s.\n", __FILE__, __LINE__,
+ disfluid_exec);
+ free (disfluid_exec);
+ return EXIT_FAILURE;
+ }
+ free (disfluid_exec);
+ return EXIT_SUCCESS;
+}