diff --git a/Makefile b/Makefile index 89c3b19..3c77cce 100644 --- a/Makefile +++ b/Makefile @@ -83,12 +83,11 @@ install_shared: lib$(libname).so test: lib$(libname).a $(MAKE) -C test -testclean: +testclean: clean $(MAKE) -C test clean clean: rm -rf *.a *.so *.o - $(MAKE) -C test clean .PHONY: all shared static clean install install_include install_static \ install_shared testclean test diff --git a/test/Makefile b/test/Makefile index 0caba5f..3fb2d08 100644 --- a/test/Makefile +++ b/test/Makefile @@ -44,26 +44,8 @@ tests += parsemonth total != echo $(tests) | wc -w | awk '{ print $$1 }' .PHONY: test -test: $(tests) output - @echo -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n" - @idx=1 ; success=0 ; fail=0; skip=0; for t in $(tests) ; \ - do printf "[%02i/$(total)] %-25s" $${idx} $${t} ; \ - idx=$$(expr $${idx} + 1) ; \ - ./$${t} ; \ - retval=$$? ; \ - if [ $${retval} -eq 0 ] ; \ - then echo -e '\e[0;32mSuccess\e[0m' ; \ - success=$$(expr $${success} + 1) ; \ - elif [ $${retval} -eq 255 ] ; \ - then echo Skipped ; \ - skip=$$(expr $${skip} + 1) ; \ - else echo -e '\e[0;31mFailure\e[0m' ; \ - fail=$$(expr $${fail} + 1) ; \ - fi ; done || true ; \ - if [ $${fail} == 0 ] ; \ - 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" ; \ - fi +test: $(tests) runner output + ./runner $(tests) output: @ [-d $@ ] 2>/dev/null || install -d $@ diff --git a/test/runner.c b/test/runner.c new file mode 100644 index 0000000..57ef189 --- /dev/null +++ b/test/runner.c @@ -0,0 +1,45 @@ +#include +#include + +int main(int argc, char *argv[]) { + int i, pass = 0, fail = 0, skip = 0, total, ret, read = 0; + FILE *pipe; + char cmd[100], output[500]; + + total = argc-1; + printf("\n\t=== \033[0;33mRunning %i tests\033[0m ===\n", total); + for (i = 1; i < argc; i++) { + snprintf(cmd, 100, "./%s", argv[i]); + printf("%-25s", argv[i]); + pipe = popen(cmd, "w"); + read = fread(&output, 1, 500, pipe); + ret = pclose(pipe); + if (read) { + fail++; + printf("\033[0;31mFailed\033[0m\n"); + fprintf(stderr, "%s\n", &output); + continue; + } + switch (WEXITSTATUS(ret)) { + case 0: + pass++; + printf("\033[0;32mSuccess\033[0m\n"); + break; + case 255: + skip++; + printf("Skipped\n"); + break; + default: + fail++; + printf("\033[0;31mFailed\033[0m\n"); + } + } + if (fail) { + printf("\nResults: \033[0;31mFAILED\033[0m %i succeeded; %i failed; %i skipped\n", + pass, fail, skip); + } else { + printf("\nResults: \033[0;32mOk\033[0m %i succeeded; %i failed; %i skipped\n", + pass, fail, skip); + } + return 0; +}