Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to write good bash code using TDD?

How to write good bash code using TDD?

1. Understand the bash pitfalls
2. Use shellcheck
3. Emphasise on functional code
4. Discover the simplest concepts
5. Explore their optimal composition
6. Use containers for integration testing
7. Stop when the fun stops

https://github.com/gerhard/bash is meant to capture the mechanics and reasoning behind test-driven bash code. It also conveys the process behind evolving a good bash codebase.

Gerhard Lazu

March 17, 2016
Tweet

More Decks by Gerhard Lazu

Other Decks in Technology

Transcript

  1. $ false $ echo $? 1 $ true $ echo

    $? 0 $ : $ echo $? 0
  2. $ test -f ./missing $ echo $? 1 $ [

    -f ./missing ] $ echo $? 1
  3. $ [[ foobar =~ bar ]] $ echo $? 0

    $ [[ foobar =~ ^bar ]] $ echo $? 1
  4. ||

  5. $ cf push &>/dev/null $ echo $? 1 $ cf

    push >&- || echo "Call 222333" Call 222333 $ echo $? 0
  6. if

  7. if cf push >&- then true else echo "Call 222333"

    fi if ! cf push >&- then echo "Call 222333" fi