summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2022-03-20 17:55:33 (EDT)
committer P. J. McDermott <pj@pehjota.net>2022-03-20 17:55:33 (EDT)
commit64b024858ecb68ca89008325c33f73f12a0c2abc (patch)
treebb51e8814de29f7212047a3c01817e49d7de8816
parent3d7338aa51b1f77b4c92df55132b9d42bd39b836 (diff)
downloadatsign-64b024858ecb68ca89008325c33f73f12a0c2abc.zip
atsign-64b024858ecb68ca89008325c33f73f12a0c2abc.tar.gz
atsign-64b024858ecb68ca89008325c33f73f12a0c2abc.tar.bz2
Add --disable-tests to shrink executable size
-rw-r--r--TODO2
-rw-r--r--configure.ac25
-rw-r--r--src/main.c26
-rwxr-xr-xtests/disabled.sh2
-rw-r--r--tests/local.mk14
5 files changed, 58 insertions, 11 deletions
diff --git a/TODO b/TODO
index 4dd587d..cb5596e 100644
--- a/TODO
+++ b/TODO
@@ -2,8 +2,6 @@ spaces between specifiers in strptime() formats -- strftime()?
format printing: copy format to another buffer, skipping certain char
test with other libc's (newlib? musl? fbsd? obsd?)
`./@ 7:00 PM` doesn't work with musl strptime()
---disable-tests to shrink executable size
- find strtol() in configure
maybe sscanf() instead of strtol()
formats test
test other times
diff --git a/configure.ac b/configure.ac
index 011b7d5..335b927 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,31 @@ if ${funcs_missing}; then
AC_MSG_ERROR([required functions are missing])
fi
+AC_ARG_ENABLE([tests],
+ [AS_HELP_STRING([--enable-tests],
+ [include test suite support in executable])],
+ [case "${enableval}" in yes|no) tests=${enableval};;
+ *) AC_MSG_ERROR(
+ [bad value ${enableval} for tests option]);;
+ esac],
+ [
+ tests=no
+ test -d "${srcdir}/.git" && tests=yes
+ ]
+)
+if test x"${tests}" = x'yes'; then
+ AC_DEFINE([ENABLE_TESTS], [1],
+ [Define to 1 to include test suite support])
+ AC_CHECK_FUNCS(
+ [strtol],
+ [],
+ [AC_MSG_ERROR([required functions are missing])])
+else
+ AC_DEFINE([ENABLE_TESTS], [0],
+ [Define to 1 to include test suite support])
+fi
+AM_CONDITIONAL([ENABLE_TESTS], [test x"${tests}" = x'yes'])
+
AX_CFLAGS_WARN_ALL() dnl Adds -Wall or equivalent
AX_CHECK_COMPILE_FLAG([-Wpedantic], [AX_APPEND_FLAG([-Wpedantic])])
AX_CHECK_COMPILE_FLAG([-Wextra], [AX_APPEND_FLAG([-Wextra])])
diff --git a/src/main.c b/src/main.c
index 7339166..572daf6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -79,6 +79,7 @@ _print_help(const char *program_name)
#endif
}
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
static struct tm *
_set_now(char buf[])
{
@@ -117,6 +118,7 @@ _set_now(char buf[])
return tm_p;
}
+#endif
static void
_list_formats(const struct tm *tm)
@@ -203,7 +205,9 @@ _concat_args(int argc, char * const argv[])
int
main(int argc, char * const argv[])
{
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
bool dbg;
+#endif
bool fmt;
int opt;
char *buf;
@@ -212,14 +216,27 @@ main(int argc, char * const argv[])
time_t arg;
double dif;
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
dbg = false;
+#endif
fmt = false;
optind = 1;
opterr = 0;
+ now = time(NULL);
+ now_tm = localtime(&now);
+
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
while ((opt = getopt_long(argc, argv, "FhVd:", LONGOPTS_, NULL)) > 0) {
#else
+ while ((opt = getopt_long(argc, argv, "FhV:", LONGOPTS_, NULL)) > 0) {
+#endif
+#else
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
while ((opt = getopt(argc, argv, "FhVd:")) > 0) {
+#else
+ while ((opt = getopt(argc, argv, "FhV:")) > 0) {
+#endif
#endif
switch (opt) {
case 'F':
@@ -231,6 +248,7 @@ main(int argc, char * const argv[])
case 'V':
_print_version();
return EXIT_SUCCESS;
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
case 'd':
dbg = true;
now_tm = _set_now(optarg);
@@ -238,6 +256,7 @@ main(int argc, char * const argv[])
return EXIT_FAILURE;
}
break;
+#endif
default:
_print_usage(stderr, argv[0]);
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
@@ -253,11 +272,6 @@ main(int argc, char * const argv[])
argc -= optind;
argv += optind;
- if (dbg == false) {
- now = time(NULL);
- now_tm = localtime(&now);
- }
-
if (fmt == true) {
_list_formats(now_tm);
return EXIT_SUCCESS;
@@ -274,11 +288,13 @@ main(int argc, char * const argv[])
}
free(buf);
+#if defined(ENABLE_TESTS) && ENABLE_TESTS
if (dbg == true) {
dif = datetime_diff_epoch(arg);
printf("%" PRId64 "\n", (int64_t) dif);
return EXIT_SUCCESS;
}
+#endif
now = time(NULL);
dif = difftime(arg, now);
diff --git a/tests/disabled.sh b/tests/disabled.sh
new file mode 100755
index 0000000..53caf82
--- /dev/null
+++ b/tests/disabled.sh
@@ -0,0 +1,2 @@
+printf 'Test suite support disabled\n' 1>&2
+exit 1
diff --git a/tests/local.mk b/tests/local.mk
index 95671bc..0f8fb45 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -1,5 +1,11 @@
-TESTS = \
+tests = \
%reldir%/parse.sh
+if ENABLE_TESTS
+TESTS = $(tests)
+else
+TESTS = %reldir%/disabled.sh
+endif
+
TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = \
AM_TAP_AWK='$(AWK)' \
@@ -7,7 +13,7 @@ SH_LOG_DRIVER = \
TOP_BUILDDIR="$(abs_top_builddir)" \
$(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
EXTRA_DIST += \
- $(TESTS) \
+ $(tests) \
+ %reldir%/disabled.sh \
$(top_srcdir)/build-aux/tap-driver.sh \
- %reldir%/aux/tap-functions.sh \
- %reldir%/parse.sh
+ %reldir%/aux/tap-functions.sh