Use /bin/echo in tests rather than shell builtin

This commit is contained in:
Nathan Fisher 2024-02-11 23:20:28 -05:00
parent cc8ecc55b7
commit b1e5c75295
3 changed files with 14 additions and 10 deletions

View file

@ -20,9 +20,9 @@ There is a simple test harness which can be invoked via `make test`. If you wish
to port this software to an untested platform the tests will greatly assist in to port this software to an untested platform the tests will greatly assist in
that process. that process.
> Note: if your OS uses **dash** as `/bin/sh` then the builtin echo command will not > Note: if your OS uses **dash** as `/bin/sh` then the builtin echo command will not
> be up to the task of printing the escape sequences used by the test runner. If this > be up to the task of printing the escape sequences used by the test runner. In
> bothers you, you can call `make` with the `SHELL` environment variable overridden > this case, be sure to set the `ECHO` variable to `/bin/echo` in the *config.mk*
> by calling `make SHELL=/bin/bash all test`. > file.
## Contributing ## Contributing
Contributions are always welcome and can be made via pull request or `git send-email`, Contributions are always welcome and can be made via pull request or `git send-email`,

View file

@ -5,6 +5,10 @@ libdir = $(DESTDIR)$(PREFIX)/lib
sharedir = $(DESTDIR)$(PREFIX)/share sharedir = $(DESTDIR)$(PREFIX)/share
mandir = $(sharedir)/man mandir = $(sharedir)/man
docdir = $(sharedir)/doc/haggis docdir = $(sharedir)/doc/haggis
# We need an `echo` program that doesn't screw with terminal escape sequences.
# This only matters if /bin/sh is a symlink to dash, as the echo builtin in dash
# will screw with them and pass them as printed characters.
ECHO = /bin/echo
# Comment this line if your OS ships libmd as part of libc # Comment this line if your OS ships libmd as part of libc
# (NetBSD, OpenBSD) # (NetBSD, OpenBSD)
LIBS += -lmd LIBS += -lmd

View file

@ -82,24 +82,24 @@ total != echo $(tests) | wc -w | awk '{ print $$1 }'
.PHONY: test .PHONY: test
test: $(tests) output test: $(tests) output
@echo -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n" @$(ECHO) -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n"
@idx=1 ; success=0 ; fail=0; skip=0; for t in $(tests) ; \ @idx=1 ; success=0 ; fail=0; skip=0; for t in $(tests) ; \
do printf "[%02i/$(total)] %-25s" $${idx} $${t} ; \ do printf "[%02i/$(total)] %-25s" $${idx} $${t} ; \
idx=$$(expr $${idx} + 1) ; \ idx=$$(expr $${idx} + 1) ; \
./$${t} ; \ ./$${t} ; \
retval=$$? ; \ retval=$$? ; \
if [ $${retval} -eq 0 ] ; \ if [ $${retval} -eq 0 ] ; \
then echo -e '\e[0;32mSuccess\e[0m' ; \ then $(ECHO) -e '\e[0;32mSuccess\e[0m' ; \
success=$$(expr $${success} + 1) ; \ success=$$(expr $${success} + 1) ; \
elif [ $${retval} -eq 255 ] ; \ elif [ $${retval} -eq 255 ] ; \
then echo Skipped ; \ then $(ECHO) Skipped ; \
skip=$$(expr $${skip} + 1) ; \ skip=$$(expr $${skip} + 1) ; \
else echo -e '\e[0;31mFailure\e[0m' ; \ else $(ECHO) -e '\e[0;31mFailure\e[0m' ; \
fail=$$(expr $${fail} + 1) ; \ fail=$$(expr $${fail} + 1) ; \
fi ; done || true ; \ fi ; done || true ; \
if [ $${fail} == 0 ] ; \ if [ $${fail} -eq 0 ] ; \
then echo -e '\nResults: \e[0;32mOk\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \ then $(ECHO) -e '\nResults: \e[0;32mOk\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
else echo -e '\nResults: \e[0;31mFAILED\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \ else $(ECHO) -e '\nResults: \e[0;31mFAILED\e[0m.' "$${success} succeeded; $${fail} failed; $${skip} skipped" ; \
fi fi
output: output: