Unit testing for shell scripts

前端 未结 6 541
暖寄归人
暖寄归人 2020-12-04 06:17

Pretty much every product I\'ve worked on over the years has involved some level of shell scripts (or batch files, PowerShell etc. on Windows). Even though we wrote the bul

6条回答
  •  鱼传尺愫
    2020-12-04 06:58

    Wondering why nobody mentioned BATS. It's up-to-date and TAP-compliant.

    Describe:

    #!/usr/bin/env bats
    
    @test "addition using bc" {
      result="$(echo 2+2 | bc)"
      [ "$result" -eq 4 ]
    }
    

    Run:

    $ bats addition.bats
     ✓ addition using bc
    
    1 tests, 0 failures
    

提交回复
热议问题