linux 3.5.6-1.fc17.x86_64 GNU bash, version 4.2.37 Hello,
I have the following bash script file. That I am using to test my program. However, I want to be able to test with and without valgrind. So I get the argument from the command line 'valgrind' and compare in the if statement. However, my test cases will get bigger over time, and I will have to repeat a lot of code in the if-else. Is there a way to minimize this if-else?
Many thanks for any suggestions,
#!/bin/bash # Abort on error set -e echo $1 if [ "$1" == "valgrind" ]; then echo "TEST STARTED RUNNING WITH VALGRIND" echo "TEST CREATE DATABASE" valgrind ./db db.dat c echo "TEST CREATE DATABASE OK" echo "TEST INSERT" valgrind ./db db.dat s 1 steve [email protected] valgrind ./db db.dat s 2 ben [email protected] valgrind ./db db.dat s 3 lisa [email protected] echo "TEST INSERT OK" echo "TEST LIST" valgrind ./db db.dat l echo "TEST LIST OK" echo "TEST DELETE" valgrind ./db db.dat d 2 echo "TEST DELETE OK" echo "TEST LIST" valgrind ./db db.dat l echo "TEST LIST OK" echo "TEST FETCH" valgrind ./db db.dat g 2 valgrind ./db db.dat g 3 echo "TEST FETCH OK" echo "TEST COMPLETED OK" else echo "TEST STARTED" echo "TEST CREATE DATABASE" ./db db.dat c echo "TEST CREATE DATABASE OK" echo "TEST INSERT" ./db db.dat s 1 steve [email protected] ./db db.dat s 2 ben [email protected] ./db db.dat s 3 lisa [email protected] echo "TEST INSERT OK" echo "TEST LIST" ./db db.dat l echo "TEST LIST OK" echo "TEST DELETE" ./db db.dat d 2 echo "TEST DELETE OK" echo "TEST LIST" ./db db.dat l echo "TEST LIST OK" echo "TEST FETCH" ./db db.dat g 2 ./db db.dat g 3 echo "TEST FETCH OK" echo "TEST COMPLETED OK" fi