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

Bang.sh - Bash Script no Velho Oeste

Bang.sh - Bash Script no Velho Oeste

Numa cidade sem lei do Faroeste, todos possuem revólveres engatilhados pronto para atirar naqueles que escrevem códigos ilegíveis e difíceis de manter. Bang.sh é um framework escrito em Bash Script que pretende torná-lo o gatilho mais rápido do Oeste: garanta a pontaria através de testes unitários - incluindo mocking; dispare exceções como se fossem balas e as trate como damas de um Saloon; desfrute de um options parser e uma série de funções utilitárias que dão mais conforto que a maioria dos hotéis da cidade. De forma totalmente modular, desenvolva e teste seus scripts e se torne um Xerife no Velho Oeste!

Gustavo Dutra

August 07, 2014
Tweet

More Decks by Gustavo Dutra

Other Decks in Technology

Transcript

  1. $ ./todo add “My first todo" ! ! $ cat

    ~/.todolist My first todo
  2. function todo.config.load () { if b.path.file? "$1"; then _todo.config.load_from_file "$1"

    else _todo.config.load_default_config fi } ./modules/config.sh
  3. function todo.config.load () { if b.path.file? "$1"; then _todo.config.load_from_file "$1"

    else _todo.config.load_default_config fi } ./modules/config.sh
  4. function todo.config.load () { if b.path.file? "$1"; then _todo.config.load_from_file "$1"

    else _todo.config.load_default_config fi } ./modules/config.sh
  5. function _todo.config.load_from_file () { for line in $(cat "$1"); do

    # file=/Users/gustavo/.todolist local option="$(echo $line | cut -f1 -d=)" local value="$(echo $line | cut -f2 -d=)" ! b.set "todo.config.$option" "$value" done } ./modules/config.sh
  6. function _todo.config.load_from_file () { for line in $(cat "$1"); do

    # file=/Users/gustavo/.todolist local option="$(echo $line | cut -f1 -d=)" local value="$(echo $line | cut -f2 -d=)" ! b.set "todo.config.$option" "$value" done } ./modules/config.sh
  7. function _todo.config.load_from_file () { for line in $(cat “$1"); do

    # file=/Users/gustavo/.todolist local option="$(echo $line | cut -f1 -d=)" local value="$(echo $line | cut -f2 -d=)" ! b.set "todo.config.$option" "$value" done } ./modules/config.sh
  8. function _todo.config.load_from_file () { for line in $(cat "$1"); do

    # file=/Users/gustavo/.todolist local option="$(echo $line | cut -f1 -d=)" local value="$(echo $line | cut -f2 -d=)" ! b.set "todo.config.$option" "$value" done } ./modules/config.sh
  9. function todo.config.load () { if b.path.file? "$1"; then _todo.config.load_from_file "$1"

    else _todo.config.load_default_config fi } ./modules/config.sh
  10. function todo.config.load () { if b.path.file? "$1"; then _todo.config.load_from_file "$1"

    else _todo.config.load_default_config fi } ./modules/config.sh
  11. ./todo • Load bang.sh • Require modules (task, path, config)

    • Read the ~/.todorc the file and set options • Run the task
  12. ! function b.test.load_configuration_from_file () { local filename=$(mktemp -t config_file.XXXX) echo

    "file=some/path" > "$filename" ! b.unittest.assert_equal "" \ ”$(b.get todo.config.file)” ! todo.config.load "$filename" ! b.unittest.assert_equal "some/path" \ ”$(b.get todo.config.file)" ! rm “$filename" } ./tests/modules/config_test.sh
  13. ! function b.test.load_configuration_from_file () { local filename=$(mktemp -t config_file.XXXX) echo

    "file=some/path" > "$filename" ! b.unittest.assert_equal "" \ ”$(b.get todo.config.file)” ! todo.config.load "$filename" ! b.unittest.assert_equal "some/path" \ ”$(b.get todo.config.file)" ! rm “$filename" } ./tests/modules/config_test.sh
  14. ! function b.test.load_configuration_from_file () { local filename=$(mktemp -t config_file.XXXX) echo

    "file=some/path" > "$filename" ! b.unittest.assert_equal "" \ ”$(b.get todo.config.file)” ! todo.config.load "$filename" ! b.unittest.assert_equal "some/path" \ ”$(b.get todo.config.file)" ! rm “$filename" } ./tests/modules/config_test.sh
  15. ! function b.test.load_configuration_from_file () { local filename=$(mktemp -t config_file.XXXX) echo

    "file=some/path" > "$filename" ! b.unittest.assert_equal "" \ ”$(b.get todo.config.file)” ! todo.config.load "$filename" ! b.unittest.assert_equal "some/path" \ ”$(b.get todo.config.file)" ! rm “$filename" } ./tests/modules/config_test.sh
  16. ! function b.test.load_configuration_from_file () { local filename=$(mktemp -t config_file.XXXX) echo

    "file=some/path" > "$filename" ! b.unittest.assert_equal "" \ ”$(b.get todo.config.file)” ! todo.config.load "$filename" ! b.unittest.assert_equal "some/path" \ ”$(b.get todo.config.file)" ! rm “$filename" } ./tests/modules/config_test.sh
  17. function b.unittest.setup () { b.set 'todo.config.file' "$(mktemp -t config_file.XXXX)" }

    ! function b.unittest.teardown () { rm $(b.get 'todo.config.file') } ! function b.test.adds_a_todo_to_the_file () { local config_file=$(b.get 'todo.config.file') ! b.unittest.assert_equal "" "$(cat $config_file)" b.task.run "add" "My todo item" b.unittest.assert_equal "My todo item" "$(cat $config_file)" } ./tests/tasks/add_test.sh
  18. function b.unittest.setup () { b.set 'todo.config.file' "$(mktemp -t config_file.XXXX)" }

    ! function b.unittest.teardown () { rm $(b.get 'todo.config.file') } ! function b.test.adds_a_todo_to_the_file () { local config_file=$(b.get 'todo.config.file') ! b.unittest.assert_equal "" "$(cat $config_file)" b.task.run "add" "My todo item" b.unittest.assert_equal "My todo item" "$(cat $config_file)" } ./tests/tasks/add_test.sh
  19. function b.unittest.setup () { b.set 'todo.config.file' "$(mktemp -t config_file.XXXX)" }

    ! function b.unittest.teardown () { rm $(b.get 'todo.config.file') } ! function b.test.adds_a_todo_to_the_file () { local config_file=$(b.get 'todo.config.file') ! b.unittest.assert_equal "" "$(cat $config_file)" b.task.run "add" "My todo item" b.unittest.assert_equal "My todo item" "$(cat $config_file)" } ./tests/tasks/add_test.sh
  20. function b.unittest.setup () { b.set 'todo.config.file' "$(mktemp -t config_file.XXXX)" }

    ! function b.unittest.teardown () { rm $(b.get 'todo.config.file') } ! function b.test.adds_a_todo_to_the_file () { local config_file=$(b.get 'todo.config.file') ! b.unittest.assert_equal "" "$(cat $config_file)" b.task.run "add" "My todo item" b.unittest.assert_equal "My todo item" "$(cat $config_file)" } ./tests/tasks/add_test.sh
  21. • http://commons.wikimedia.org/wiki/File%3AWild_west_show.jpg • http://www.flickr.com/photos/us_mission_canada/8513394054 • http://commons.wikimedia.org/wiki/File:Cowboy_Action_Shooting.JPG • http://en.wikipedia.org/wiki/ File:Warner_Brothers_television_westerns_stars_1959.JPG •

    "Women's cowboy boots" by Pete unseth - Own work. Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http:// commons.wikimedia.org/wiki/File:Women %27s_cowboy_boots.JPG#mediaviewer/File:Women%27s_cowboy_boots.JPG • http://commons.wikimedia.org/wiki/File:Saint-L %C3%B4_Railway_station_destroyed.jpg • http://www.flickr.com/photos/matthigh/2982689681 • http://www.flickr.com/photos/kirillsimonov/5442124915/