|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+#!/usr/bin/env bats
|
|
|
2
|
+
|
|
|
3
|
+
|
|
|
4
|
+@test "task2: Check that we have a debug output" {
|
|
|
5
|
+ run stat "$BATS_TEST_DIRNAME/../target/debug/task2"
|
|
|
6
|
+ [ "$status" -eq 0 ]
|
|
|
7
|
+}
|
|
|
8
|
+
|
|
|
9
|
+@test "task2: Output Long String: The quick ...." {
|
|
|
10
|
+ run "$BATS_TEST_DIRNAME/../target/debug/task2" 'q' '♥ The quick brown fox jumps over the lazy dog. ♥'
|
|
|
11
|
+ [[ "${lines[0]}" =~ "You asked me to count all 'q' in '♥ The quick brown fox jumps over the lazy dog. ♥'" ]]
|
|
|
12
|
+ [[ "${lines[1]}" =~ "Found 1 'q' in '♥ The quick brown fox jumps over the lazy dog. ♥'" ]]
|
|
|
13
|
+}
|
|
|
14
|
+
|
|
|
15
|
+@test "task2: Output Short String: ababab " {
|
|
|
16
|
+ run "$BATS_TEST_DIRNAME/../target/debug/task2" 'a' 'ababab'
|
|
|
17
|
+ [[ "${lines[0]}" =~ "You asked me to count all 'a' in 'ababab'" ]]
|
|
|
18
|
+ [[ "${lines[1]}" =~ "Found 3 'a' in 'ababab'" ]]
|
|
|
19
|
+}
|
|
|
20
|
+
|
|
|
21
|
+@test "task2: Output Error 1" {
|
|
|
22
|
+ run "$BATS_TEST_DIRNAME/../target/debug/task2"
|
|
|
23
|
+ [[ "${lines[0]}" =~ "not enough arguments" ]]
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+@test "task2: Output Error 2" {
|
|
|
27
|
+ run "$BATS_TEST_DIRNAME/../target/debug/task2"
|
|
|
28
|
+ [[ "${lines[0]}" =~ "not enough arguments" ]]
|
|
|
29
|
+}
|
|
|
30
|
+
|
|
|
31
|
+# wc output with white spaces is trimmed by xargs
|
|
|
32
|
+@test "task2: Output must be exact 2 line long" {
|
|
|
33
|
+ run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task2' 'a' 'b' 'c' | wc -l | xargs"
|
|
|
34
|
+ [ "$output" = "2" ]
|
|
|
35
|
+}
|
|
|
36
|
+
|
|
|
37
|
+# wc output with white spaces is trimmed by xargs
|
|
|
38
|
+@test "task2: Output must be exact 1 line long" {
|
|
|
39
|
+ run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task2' 'a' | wc -l | xargs"
|
|
|
40
|
+ [ "$output" = "1" ]
|
|
|
41
|
+}
|