github.com/mshitrit/go-mutesting@v0.0.0-20210528084812-ff81dcaedfea/scripts/exec/test-mutated-package.sh (about) 1 #!/bin/bash 2 3 # This exec script implements 4 # - the replacement of the original file with the mutation, 5 # - the execution of all tests originating from the package of the mutated file, 6 # - and the reporting if the mutation was killed. 7 8 if [ -z ${MUTATE_CHANGED+x} ]; then echo "MUTATE_CHANGED is not set"; exit 1; fi 9 if [ -z ${MUTATE_ORIGINAL+x} ]; then echo "MUTATE_ORIGINAL is not set"; exit 1; fi 10 if [ -z ${MUTATE_PACKAGE+x} ]; then echo "MUTATE_PACKAGE is not set"; exit 1; fi 11 12 function clean_up { 13 if [ -f $MUTATE_ORIGINAL.tmp ]; 14 then 15 mv $MUTATE_ORIGINAL.tmp $MUTATE_ORIGINAL 16 fi 17 } 18 19 function sig_handler { 20 clean_up 21 22 exit $GOMUTESTING_RESULT 23 } 24 trap sig_handler SIGHUP SIGINT SIGTERM 25 26 export GOMUTESTING_DIFF=$(diff -u $MUTATE_ORIGINAL $MUTATE_CHANGED) 27 28 mv $MUTATE_ORIGINAL $MUTATE_ORIGINAL.tmp 29 cp $MUTATE_CHANGED $MUTATE_ORIGINAL 30 31 export MUTATE_TIMEOUT=${MUTATE_TIMEOUT:-10} 32 33 if [ -n "$TEST_RECURSIVE" ]; then 34 TEST_RECURSIVE="/..." 35 fi 36 37 GOMUTESTING_TEST=$(go test -timeout $(printf '%ds' $MUTATE_TIMEOUT) $MUTATE_PACKAGE$TEST_RECURSIVE 2>&1) 38 export GOMUTESTING_RESULT=$? 39 40 if [ "$MUTATE_DEBUG" = true ] ; then 41 echo "$GOMUTESTING_TEST" 42 fi 43 44 clean_up 45 46 case $GOMUTESTING_RESULT in 47 0) # tests passed -> FAIL 48 echo "$GOMUTESTING_DIFF" 49 50 exit 1 51 ;; 52 1) # tests failed -> PASS 53 if [ "$MUTATE_DEBUG" = true ] ; then 54 echo "$GOMUTESTING_DIFF" 55 fi 56 57 exit 0 58 ;; 59 2) # did not compile -> SKIP 60 if [ "$MUTATE_VERBOSE" = true ] ; then 61 echo "Mutation did not compile" 62 fi 63 64 if [ "$MUTATE_DEBUG" = true ] ; then 65 echo "$GOMUTESTING_DIFF" 66 fi 67 68 exit 2 69 ;; 70 *) # Unkown exit code -> SKIP 71 echo "Unknown exit code" 72 echo "$GOMUTESTING_DIFF" 73 74 exit $GOMUTESTING_RESULT 75 ;; 76 esac