test rule in Makefile

* add tests/earth.sh
 * add to Makefile all the necessary rules for `make test`

Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
Daniel Santos 2022-03-15 13:36:40 +00:00
parent ad3f14edbd
commit b559d657c3
2 changed files with 64 additions and 0 deletions

View File

@ -65,3 +65,47 @@ run: decimal-to-earth
mem: decimal-to-earth
valgrind --leak-check=full --show-leak-kinds=all -s decimal-to-earth 999
decimal-to-earth_test-1: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -o $@ $^
earth-to-decimal_test-1: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -o $@ $^
decimal-to-earth_test-2: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -DFROM_UNITS_ON_THE_END -o $@ $^
earth-to-decimal_test-2: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -DTO_UNITS_ON_THE_END -o $@ $^
decimal-to-earth_test-3: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -DTO_UNITS_ON_THE_END -o $@ $^
earth-to-decimal_test-3: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -DFROM_UNITS_ON_THE_END -o $@ $^
decimal-to-earth_test-4: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -DFROM_UNITS_ON_THE_END -DTO_UNITS_ON_THE_END -o $@ $^
earth-to-decimal_test-4: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -DFROM_UNITS_ON_THE_END -DTO_UNITS_ON_THE_END -o $@ $^
decimal-to-earth_test-5: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -DTO_FIRST_NUMBER_VOID -o $@ $^
earth-to-decimal_test-5: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -DFROM_FIRST_NUMBER_VOID -o $@ $^
decimal-to-earth_test-6: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"0123456789\" -DFROM_FIRST_NUMBER_VOID -DFROM_INFINITE_BASE -DTO_NUMERICALS=\"12345\" -DTO_INFINITE_BASE -o $@ $^
earth-to-decimal_test-6: $(DEP)
$(CC) $(CFLAGS) -DFROM_NUMERICALS=\"12345\" -DTO_NUMERICALS=\"0123456789\" -DTO_FIRST_NUMBER_VOID -DTO_INFINITE_BASE -DFROM_INFINITE_BASE -o $@ $^
.PHONY: build-tests
build-tests: decimal-to-earth_test-1 earth-to-decimal_test-1 decimal-to-earth_test-2 earth-to-decimal_test-2 decimal-to-earth_test-3 earth-to-decimal_test-3 decimal-to-earth_test-4 earth-to-decimal_test-4 decimal-to-earth_test-5 earth-to-decimal_test-5 decimal-to-earth_test-6 earth-to-decimal_test-6
.PHONY: test
test:
tests/earth.sh

20
tests/earth.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
current_branch=$(git rev-parse --abbrev-ref HEAD)
git checkout stable
make build-tests
for i in {1..6} ; do \mv decimal-to-earth_test-${i} decimal-to-earth_test-${i}_stable; \mv earth-to-decimal_test-${i} earth-to-decimal_test-${i}_stable; done
git checkout ${current_branch}
make build-tests
for i in {1..6}; do for n in {1..1000}; do [[ "$(decimal-to-earth_test-${i} $n)" == "$(decimal-to-earth_test-${i}_stable $n)" ]] || echo "[X] failed: decimal-to-earth_test-${i} $n" ; done; echo " * decimal-to-earth_test-${i} clean"; done
for i in {1..6}; do for n in {1..1000}; do num=$(decimal-to-earth_test-${i} ${n}); [[ "$(earth-to-decimal_test-${i} ${num})" == "$(earth-to-decimal_test-${i}_stable ${num})" ]] || echo "[X] failed: earth-to-decimal_test-${i} ${num}" ; done; echo " * earth-to-decimal_test-${i} clean"; done
echo
echo "----"
echo -e "----\n * void: decimal-to-earth_test-1 0 -> " $([[ "$(decimal-to-earth_test-1 0)" == "$(decimal-to-earth_test-1_stable 0)" ]] && echo clean || echo failed)
echo "----"
echo -e "----\n * out of domain: decimal-to-earth_test-1 abc -> " $([[ "$(decimal-to-earth_test-1 abc)" == "$(decimal-to-earth_test-1_stable abc)" ]] && echo clean || echo failed)