Unit Testing bash scripts

后端 未结 16 686
暖寄归人
暖寄归人 2020-11-30 18:51

We have a system that has some bash scripts running besides Java code. Since we are trying to Test Everything That Could Possibly Break, and those bash scripts may break, we

16条回答
  •  [愿得一人]
    2020-11-30 19:05

    Why do you say that it's "hard" to test bash scripts?

    What's wrong with test wrappers like:

     #!/bin/bash
     set -e
     errors=0
     results=$($script_under_test $args<&1
         let errors+=1
         }
    
     echo "$results" | grep -q $expected1 || {
          echo "Test Failed.  Expected $expected1"
          let errors+=1
     }
     # and so on, et cetera, ad infinitum, ad nauseum
     [ "$errors" -gt 0 ] && {
          echo "There were $errors errors found"
          exit 1
     }
    

提交回复
热议问题