patternbashMinor
Script for automating regression testing
Viewed 0 times
scriptautomatingfortestingregression
Problem
I am writing a simple script to automate my regression testing. I am new to bash scripting and my goal is achieve the most efficient and clean code. I have written a simple function to allow me to select which subject I would like to test. This will loop until I select the exit option. Again, this is quite simple; however I am looking for some feedback on how I can improve.
BIO=biology
showMenu () {
echo "What subject would like to regression test?"
echo "1) Physics"
echo "2) Sociology"
echo "3) Biology"
echo "4) Quit"
}
while [ 0 ]
do
showMenu
read CHOICE
case "$CHOICE" in
"1")
read SUBJECT
SUBJECT=physics
echo "LOG: REGRESSION TESTING $SUBJECT" $SUBJECT
GENERATE_CSS=`lessc /home/developer/oer.exports/css/ccap-$BIO.less > /home/developer/oer.exports/css/ccap-$BIO.css`
echo "LOG: CSS GENERATION COMPLETE"
GENERATE_PDF=`python collectiondbk2pdf.py -v -s ccap-$BIO -d ./test-ccap/col$SUBJECT $SUBJECT.pdf -t tempdir/$SUBJECT`
echo "LOG: GENERATING $SUBJECT PDF WITH $BIO CSS STYLE"
;;
"2")
read SUBJECT
SUBJECT=sociology
echo "LOG: REGRESSION TESTING SOCIOLOGY" $SUBJECT
GENERATE_CSS=`lessc /home/developer/oer.exports/css/ccap-$BIO.less > /home/developer/oer.exports/css/ccap-$BIO.css`
echo "LOG: CSS GENERATION COMPLETE"
GENERATE_PDF=`python collectiondbk2pdf.py -v -s ccap-$BIO -d ./test-ccap/col$SUBJECT $SUBJECT.pdf -t tempdir/$SUBJECT`
echo "LOG: GENERATING $SUBJECT PDF WITH $BIO CSS STYLE"
;;
"3")
echo "Biology"
DIFF=`diffpdf -a --debug=2 /tmp/pdf/diff bio.pdf bio_slicer.pdf`
echo "LOG: DIFF DEV vs STAGING NOW AVAILABLE FOR PDF VIEW. "
;;
"4")
echo "Exiting now..."
exit
;;
esac
doneSolution
while :is a standard idiom for "loop forever" in bash. The colon (:) is a synonym fortrue.
- Prefer
$(command)to `command("backticks"). The former allows you to nest; the latter does not.
- Though in your case, you don't need the backticks at all. These are for capturing the output of the command, which you don't use anywhere.
- It isn't clear why you have the read SUBJECT
inside each case -- you throw away the value in the very next statement.
- Don't do this: lessc ccap-$BIO.less > ccap-$BIO.css
. (It's a classic mistake in shell scripting; everyone's been bit by it.) This will nuke the file -- it will be truncated by the shell, overwriting the contents before lessc has the chance to read it.
Aside from your code: if your goal is to regenerate the output files whenever one of the input files has changed, you should consider learning make`. With a 10-20 line makefile, you can automatically regenerate whichever of the output files need updating whenever one of the input files change.
Context
StackExchange Code Review Q#17656, answer score: 2
Revisions (0)
No revisions yet.