Add test runner written in C
This commit is contained in:
parent
cc8ecc55b7
commit
96c6d02da2
2 changed files with 41 additions and 21 deletions
|
@ -81,30 +81,12 @@ tests += extract_hardlink_node
|
|||
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 $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(tests) output/*
|
||||
rm -rf $(tests) runner output/*
|
||||
|
|
38
test/runner.c
Normal file
38
test/runner.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, pass = 0, fail = 0, skip = 0, total, ret;
|
||||
FILE *pipe;
|
||||
char cmd[100];
|
||||
|
||||
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, "r");
|
||||
ret = pclose(pipe);
|
||||
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