Skip to content

Commit ebd194c

Browse files
committed
transform test scripts to use bats-assert functions
1 parent 05954bd commit ebd194c

File tree

88 files changed

+2950
-2859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2950
-2859
lines changed
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
11
#!/usr/bin/env bash
2+
load bats-extra.bash
23

34
# local version: 1.7.0.1
45

56
@test 'basic' {
67
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
78
run bash acronym.sh 'Portable Network Graphics'
8-
(( status == 0 ))
9-
[[ "$output" == 'PNG' ]]
9+
assert_success
10+
assert_output 'PNG'
1011
}
1112

1213
@test 'lowercase words' {
1314
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
1415
run bash acronym.sh 'Ruby on Rails'
15-
(( status == 0 ))
16-
[[ "$output" == 'ROR' ]]
16+
assert_success
17+
assert_output 'ROR'
1718
}
1819

1920
@test 'punctuation' {
2021
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
2122
run bash acronym.sh 'First In, First Out'
22-
(( status == 0 ))
23-
[[ "$output" == 'FIFO' ]]
23+
assert_success
24+
assert_output 'FIFO'
2425
}
2526

2627
@test 'all caps word' {
2728
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
2829
run bash acronym.sh 'GNU Image Manipulation Program'
29-
(( status == 0 ))
30-
[[ "$output" == 'GIMP' ]]
30+
assert_success
31+
assert_output 'GIMP'
3132
}
3233

3334
@test 'punctuation without whitespace' {
3435
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
3536
run bash acronym.sh 'Complementary metal-oxide semiconductor'
36-
(( status == 0 ))
37-
[[ "$output" == 'CMOS' ]]
37+
assert_success
38+
assert_output 'CMOS'
3839
}
3940

4041
@test 'very long abbreviation' {
4142
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
4243
run bash acronym.sh 'Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me'
43-
(( status == 0 ))
44-
[[ "$output" == 'ROTFLSHTMDCOALM' ]]
44+
assert_success
45+
assert_output 'ROTFLSHTMDCOALM'
4546
}
4647

4748
@test "consecutive delimiters" {
4849
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
4950
run bash acronym.sh "Something - I made up from thin air"
50-
(( status == 0 ))
51-
[[ "$output" == "SIMUFTA" ]]
51+
assert_success
52+
assert_output "SIMUFTA"
5253
}
5354

5455
@test "apostrophes" {
5556
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5657
run bash acronym.sh "Halley's Comet"
57-
(( status == 0 ))
58-
[[ "$output" == "HC" ]]
58+
assert_success
59+
assert_output "HC"
5960
}
6061

6162
@test "underscore emphasis" {
6263
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
6364
run bash acronym.sh "The Road __Not__ Taken"
64-
(( status == 0 ))
65-
[[ "$output" == "TRNT" ]]
65+
assert_success
66+
assert_output "TRNT"
6667
}
6768

6869
# bash-specific test: Focus the student's attention on the effects of
@@ -72,6 +73,6 @@
7273
@test "contains shell globbing character" {
7374
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
7475
run bash acronym.sh "Two * Words"
75-
(( status == 0 ))
76-
[[ "$output" == "TW" ]]
76+
assert_success
77+
assert_output "TW"
7778
}
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
load bats-extra.bash
23

34
# local version: 2.0.0.0
45

@@ -7,113 +8,113 @@
78
@test "encode yes" {
89
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
910
run bash affine_cipher.sh encode 5 7 "yes"
10-
(( status == 0 ))
11-
[[ $output == "xbt" ]]
11+
assert_success
12+
assert_output "xbt"
1213
}
1314

1415
@test "encode no" {
1516
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
1617
run bash affine_cipher.sh encode 15 18 "no"
17-
(( status == 0 ))
18-
[[ $output == "fu" ]]
18+
assert_success
19+
assert_output "fu"
1920
}
2021

2122
@test "encode OMG" {
2223
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
2324
run bash affine_cipher.sh encode 21 3 "OMG"
24-
(( status == 0 ))
25-
[[ $output == "lvz" ]]
25+
assert_success
26+
assert_output "lvz"
2627
}
2728

2829
@test "encode O M G" {
2930
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
3031
run bash affine_cipher.sh encode 25 47 "O M G"
31-
(( status == 0 ))
32-
[[ $output == "hjp" ]]
32+
assert_success
33+
assert_output "hjp"
3334
}
3435

3536
@test "encode mindblowingly" {
3637
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
3738
run bash affine_cipher.sh encode 11 15 "mindblowingly"
38-
(( status == 0 ))
39-
[[ $output == "rzcwa gnxzc dgt" ]]
39+
assert_success
40+
assert_output "rzcwa gnxzc dgt"
4041
}
4142

4243
@test "encode numbers" {
4344
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
4445
run bash affine_cipher.sh encode 3 4 "Testing,1 2 3, testing."
45-
(( status == 0 ))
46-
[[ $output == "jqgjc rw123 jqgjc rw" ]]
46+
assert_success
47+
assert_output "jqgjc rw123 jqgjc rw"
4748
}
4849

4950
@test "encode deep thought" {
5051
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5152
run bash affine_cipher.sh encode 5 17 "Truth is fiction."
52-
(( status == 0 ))
53-
[[ $output == "iynia fdqfb ifje" ]]
53+
assert_success
54+
assert_output "iynia fdqfb ifje"
5455
}
5556

5657
@test "encode all the letters" {
5758
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5859
run bash affine_cipher.sh encode 17 33 "The quick brown fox jumps over the lazy dog."
59-
(( status == 0 ))
60-
[[ $output == "swxtj npvyk lruol iejdc blaxk swxmh qzglf" ]]
60+
assert_success
61+
assert_output "swxtj npvyk lruol iejdc blaxk swxmh qzglf"
6162
}
6263

6364
@test "encode with a not coprime to m" {
6465
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
6566
run bash affine_cipher.sh encode 6 17 "This is a test."
66-
(( status == 1 ))
67-
[[ $output == "a and m must be coprime." ]]
67+
assert_failure
68+
assert_output "a and m must be coprime."
6869
}
6970

7071
# decode
7172

7273
@test "decode exercism" {
7374
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
7475
run bash affine_cipher.sh decode 3 7 "tytgn fjr"
75-
(( status == 0 ))
76-
[[ $output == "exercism" ]]
76+
assert_success
77+
assert_output "exercism"
7778
}
7879

7980
@test "decode a sentence" {
8081
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
8182
run bash affine_cipher.sh decode 19 16 "qdwju nqcro muwhn odqun oppmd aunwd o"
82-
(( status == 0 ))
83-
[[ $output == "anobstacleisoftenasteppingstone" ]]
83+
assert_success
84+
assert_output "anobstacleisoftenasteppingstone"
8485
}
8586

8687
@test "decode numbers" {
8788
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
8889
run bash affine_cipher.sh decode 25 7 "odpoz ub123 odpoz ub"
89-
(( status == 0 ))
90-
[[ $output == "testing123testing" ]]
90+
assert_success
91+
assert_output "testing123testing"
9192
}
9293

9394
@test "decode all the letters" {
9495
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
9596
run bash affine_cipher.sh decode 17 33 "swxtj npvyk lruol iejdc blaxk swxmh qzglf"
96-
(( status == 0 ))
97-
[[ $output == "thequickbrownfoxjumpsoverthelazydog" ]]
97+
assert_success
98+
assert_output "thequickbrownfoxjumpsoverthelazydog"
9899
}
99100

100101
@test "decode with no spaces in input" {
101102
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
102103
run bash affine_cipher.sh decode 17 33 "swxtjnpvyklruoliejdcblaxkswxmhqzglf"
103-
(( status == 0 ))
104-
[[ $output == "thequickbrownfoxjumpsoverthelazydog" ]]
104+
assert_success
105+
assert_output "thequickbrownfoxjumpsoverthelazydog"
105106
}
106107

107108
@test "decode with too many spaces" {
108109
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
109110
run bash affine_cipher.sh decode 15 16 "vszzm cly yd cg qdp"
110-
(( status == 0 ))
111-
[[ $output == "jollygreengiant" ]]
111+
assert_success
112+
assert_output "jollygreengiant"
112113
}
113114

114115
@test "decode with a not coprime to m" {
115116
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
116117
run bash affine_cipher.sh decode 13 5 "Test"
117-
(( status == 1 ))
118-
[[ $output == "a and m must be coprime." ]]
118+
assert_failure
119+
assert_output "a and m must be coprime."
119120
}

0 commit comments

Comments
 (0)