Exercism: Bash version of the 'two-fer' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

3 years ago
  1. #!/usr/bin/env bash
  2. # local version: 1.2.0.1
  3. @test "no name given" {
  4. #[[ $BATS_RUN_SKIPPED == "true" ]] || skip
  5. # The above line controls whether to skip the test.
  6. # Normally, we skip every test except for the first one
  7. # (the first one is always commented out). This allows for
  8. # a person to focus on solving a test at a time: you can
  9. # comment out or delete the
  10. # `[[ $BATS_RUN_SKIPPED == "true" ]] || skip`
  11. # line to run the test when you are ready.
  12. #
  13. # You can also run all the tests by setting the
  14. # `$BATS_RUN_SKIPPED` environment variable, like this:
  15. #
  16. # $ BATS_RUN_SKIPPED=true bats two_fer_test.sh
  17. run bash two_fer.sh
  18. (( status == 0 ))
  19. [[ $output == "One for you, one for me." ]]
  20. }
  21. @test "a name given" {
  22. [[ $BATS_RUN_SKIPPED == "true" ]] || skip
  23. run bash two_fer.sh Alice
  24. (( status == 0 ))
  25. [[ $output == "One for Alice, one for me." ]]
  26. }
  27. @test "another name given" {
  28. [[ $BATS_RUN_SKIPPED == "true" ]] || skip
  29. run bash two_fer.sh Bob
  30. (( status == 0 ))
  31. [[ $output == "One for Bob, one for me." ]]
  32. }
  33. # bash-specific test: Focus the student's attention on the effects of
  34. # word splitting and filename expansion:
  35. # https://www.gnu.org/software/bash/manual/bash.html#Shell-Expansions
  36. @test "handle arg with spaces" {
  37. [[ $BATS_RUN_SKIPPED == "true" ]] || skip
  38. run bash two_fer.sh "John Smith" "Mary Ann"
  39. (( status == 0 ))
  40. [[ $output == "One for John Smith, one for me." ]]
  41. }
  42. @test "handle arg with glob char" {
  43. [[ $BATS_RUN_SKIPPED == "true" ]] || skip
  44. run bash two_fer.sh "* "
  45. (( status == 0 ))
  46. [[ $output == "One for * , one for me." ]]
  47. }