From 9ac0c8f505e4095a1943b544395ed0805d949315 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Fri, 16 Aug 2019 08:00:00 -0400 Subject: [PATCH] force students to handle positional parameters safely --- exercises/acronym/.meta/version | 2 +- exercises/acronym/acronym_test.sh | 7 +++++++ exercises/acronym/example.sh | 5 ++--- exercises/pig-latin/.meta/version | 2 +- exercises/pig-latin/example.sh | 2 +- exercises/pig-latin/pig_latin_test.sh | 8 ++++++++ exercises/proverb/.meta/version | 2 +- exercises/proverb/proverb_test.sh | 24 ++++++++++++++++++++++++ exercises/word-count/.meta/version | 2 +- exercises/word-count/example.sh | 2 +- exercises/word-count/word_count_test.sh | 9 +++++++++ 11 files changed, 56 insertions(+), 9 deletions(-) diff --git a/exercises/acronym/.meta/version b/exercises/acronym/.meta/version index bd8bf882..943f9cbc 100644 --- a/exercises/acronym/.meta/version +++ b/exercises/acronym/.meta/version @@ -1 +1 @@ -1.7.0 +1.7.1 diff --git a/exercises/acronym/acronym_test.sh b/exercises/acronym/acronym_test.sh index 388d39f6..d2dd2370 100644 --- a/exercises/acronym/acronym_test.sh +++ b/exercises/acronym/acronym_test.sh @@ -62,3 +62,10 @@ [[ "$status" -eq 0 ]] [[ "$output" == "TRNT" ]] } + +@test "contains shell globbing character" { + [[ $BATS_RUN_SKIPPED == true ]] || skip + run bash acronym.sh "Two * Words" + [[ "$status" -eq 0 ]] + [[ "$output" == "TW" ]] +} diff --git a/exercises/acronym/example.sh b/exercises/acronym/example.sh index f8013b30..2ff87558 100644 --- a/exercises/acronym/example.sh +++ b/exercises/acronym/example.sh @@ -5,9 +5,8 @@ if [ "$#" -ne 1 ]; then exit 1 fi -phrase=$(echo "$1" | tr '-' ' ') -set -f -- junk $phrase -shift +phrase=$(echo "$1" | tr -s '*-' ' ') +set -f -- $phrase shopt -s extglob for word; do diff --git a/exercises/pig-latin/.meta/version b/exercises/pig-latin/.meta/version index 26aaba0e..6085e946 100644 --- a/exercises/pig-latin/.meta/version +++ b/exercises/pig-latin/.meta/version @@ -1 +1 @@ -1.2.0 +1.2.1 diff --git a/exercises/pig-latin/example.sh b/exercises/pig-latin/example.sh index 6ed28e15..04e2ff18 100644 --- a/exercises/pig-latin/example.sh +++ b/exercises/pig-latin/example.sh @@ -19,4 +19,4 @@ translate() { fi } -main "$@" \ No newline at end of file +main "$@" diff --git a/exercises/pig-latin/pig_latin_test.sh b/exercises/pig-latin/pig_latin_test.sh index e64bf4b0..4e5d9640 100644 --- a/exercises/pig-latin/pig_latin_test.sh +++ b/exercises/pig-latin/pig_latin_test.sh @@ -157,3 +157,11 @@ [[ $status -eq 0 ]] [[ $output == "ickquay astfay unray" ]] } + +# danger this way lies +@test "shell globbing" { + [[ $BATS_RUN_SKIPPED == true ]] || skip + run bash pig_latin.sh "pig*" + [[ $status -eq 0 ]] + [[ $output == "ig*pay" ]] +} diff --git a/exercises/proverb/.meta/version b/exercises/proverb/.meta/version index 9084fa2f..524cb552 100644 --- a/exercises/proverb/.meta/version +++ b/exercises/proverb/.meta/version @@ -1 +1 @@ -1.1.0 +1.1.1 diff --git a/exercises/proverb/proverb_test.sh b/exercises/proverb/proverb_test.sh index df12f997..1a47807a 100644 --- a/exercises/proverb/proverb_test.sh +++ b/exercises/proverb/proverb_test.sh @@ -75,3 +75,27 @@ END [[ $status -eq 0 ]] [[ $output == "$expected" ]] } + +@test "items with whitespace" { + [[ $BATS_RUN_SKIPPED == true ]] || skip + expected=$(cat <