Add test/runner.c
This commit is contained in:
parent
5a640234c3
commit
a59c411138
3 changed files with 48 additions and 22 deletions
3
Makefile
3
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
|
||||
|
|
|
@ -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 $@
|
||||
|
|
45
test/runner.c
Normal file
45
test/runner.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Add table
Reference in a new issue