Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/stage_multiple_matches_multiple_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func testMultipleMatchesMultipleLines(stageHarness *test_case_harness.TestCaseHa
{
Pattern: fmt.Sprintf(`I saw \d+ (%s|%s)s?`, animal1, animal2),
InputLines: []string{
fmt.Sprintf("Yesterday I saw 3 %ss.", animal1),
fmt.Sprintf("Yesterday I saw 3 %s and I saw 45 %s.", animal1, animal2),
"Nothing interesting today.",
fmt.Sprintf("Last week I saw 12 %ss.", animal2),
},
Expand Down
7 changes: 7 additions & 0 deletions internal/stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ func TestStages(t *testing.T) {
StdoutFixturePath: "./test_helpers/fixtures/printing_matches/extra_empty_line",
NormalizeOutputFunc: normalizeTesterOutput,
},
"multiple_matches_pass": {
StageSlugs: []string{"cj0", "ss2", "bo4"},
CodePath: "./test_helpers/pass_all",
ExpectedExitCode: 0,
StdoutFixturePath: "./test_helpers/fixtures/multiple_matches/success",
NormalizeOutputFunc: normalizeTesterOutput,
},
}

tester_utils_testing.TestTesterOutput(t, testerDefinition, testCases)
Expand Down
114 changes: 114 additions & 0 deletions internal/test_helpers/fixtures/multiple_matches/success
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[tester::#CJ0] Running tests for Stage #CJ0 (cj0)
[tester::#CJ0] $ echo -ne "only1digit" | ./your_grep.sh -o -E '\d'
[your_program] 1
[tester::#CJ0] ✓ Received exit code 0.
[tester::#CJ0] ✓ Found line "1"
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
[tester::#CJ0] $ echo -ne "cherry" | ./your_grep.sh -o -E '\d'
[tester::#CJ0] ✓ Received exit code 1.
[tester::#CJ0] ✓ No output found
[tester::#CJ0] $ echo -ne "apple_suffix" | ./your_grep.sh -o -E '^apple'
[your_program] apple
[tester::#CJ0] ✓ Received exit code 0.
[tester::#CJ0] ✓ Found line "apple"
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
[tester::#CJ0] $ echo -ne "prefix_apple" | ./your_grep.sh -o -E '^apple'
[tester::#CJ0] ✓ Received exit code 1.
[tester::#CJ0] ✓ No output found
[tester::#CJ0] $ echo -ne "cat" | ./your_grep.sh -o -E 'ca?t'
[your_program] cat
[tester::#CJ0] ✓ Received exit code 0.
[tester::#CJ0] ✓ Found line "cat"
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
[tester::#CJ0] $ echo -ne "I see 42 dogs" | ./your_grep.sh -o -E '^I see \d+ (cat|dog)s?$'
[your_program] I see 42 dogs
[tester::#CJ0] ✓ Received exit code 0.
[tester::#CJ0] ✓ Found line "I see 42 dogs"
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
[tester::#CJ0] Test passed.

[tester::#SS2] Running tests for Stage #SS2 (ss2)
[tester::#SS2] $ echo -ne "a1b2c3" | ./your_grep.sh -o -E '\d'
[your_program] 1
[your_program] 2
[your_program] 3
[tester::#SS2] ✓ Received exit code 0.
[tester::#SS2] ✓ Found line "1"
[tester::#SS2] ✓ Found line "2"
[tester::#SS2] ✓ Found line "3"
[tester::#SS2] ✓ Stdout contains 3 expected lines in order
[tester::#SS2] $ echo -ne "pear_pineapple_watermelon" | ./your_grep.sh -o -E '(watermelon|pineapple|pear)'
[your_program] pear
[your_program] pineapple
[your_program] watermelon
[tester::#SS2] ✓ Received exit code 0.
[tester::#SS2] ✓ Found line "pear"
[tester::#SS2] ✓ Found line "pineapple"
[tester::#SS2] ✓ Found line "watermelon"
[tester::#SS2] ✓ Stdout contains 3 expected lines in order
[tester::#SS2] $ echo -ne "cherry" | ./your_grep.sh -o -E '\d'
[tester::#SS2] ✓ Received exit code 1.
[tester::#SS2] ✓ No output found
[tester::#SS2] $ echo -ne "xx, yy, zz" | ./your_grep.sh -o -E '\w\w'
[your_program] xx
[your_program] yy
[your_program] zz
[tester::#SS2] ✓ Received exit code 0.
[tester::#SS2] ✓ Found line "xx"
[tester::#SS2] ✓ Found line "yy"
[tester::#SS2] ✓ Found line "zz"
[tester::#SS2] ✓ Stdout contains 3 expected lines in order
[tester::#SS2] $ echo -ne "##$$%" | ./your_grep.sh -o -E '\w'
[tester::#SS2] ✓ Received exit code 1.
[tester::#SS2] ✓ No output found
[tester::#SS2] $ echo -ne "I see 3 tigers. Also, I see 4 pandas." | ./your_grep.sh -o -E 'I see \d+ (tiger|panda)s?'
[your_program] I see 3 tigers
[your_program] I see 4 pandas
[tester::#SS2] ✓ Received exit code 0.
[tester::#SS2] ✓ Found line "I see 3 tigers"
[tester::#SS2] ✓ Found line "I see 4 pandas"
[tester::#SS2] ✓ Stdout contains 2 expected lines in order
[tester::#SS2] Test passed.

[tester::#BO4] Running tests for Stage #BO4 (bo4)
[tester::#BO4] $ echo -ne "a1b\nno digits here\n2c3d" | ./your_grep.sh -o -E '\d'
[your_program] 1
[your_program] 2
[your_program] 3
[tester::#BO4] ✓ Received exit code 0.
[tester::#BO4] ✓ Found line "1"
[tester::#BO4] ✓ Found line "2"
[tester::#BO4] ✓ Found line "3"
[tester::#BO4] ✓ Stdout contains 3 expected lines in order
[tester::#BO4] $ echo -ne "I like plum\nnothing here\nwatermelon and plum are tasty" | ./your_grep.sh -o -E '(plum|watermelon)'
[your_program] plum
[your_program] watermelon
[your_program] plum
[tester::#BO4] ✓ Received exit code 0.
[tester::#BO4] ✓ Found line "plum"
[tester::#BO4] ✓ Found line "watermelon"
[tester::#BO4] ✓ Found line "plum"
[tester::#BO4] ✓ Stdout contains 3 expected lines in order
[tester::#BO4] $ echo -ne "abc\ndef\nghi" | ./your_grep.sh -o -E 'XYZ123'
[tester::#BO4] ✓ Received exit code 1.
[tester::#BO4] ✓ No output found
[tester::#BO4] $ echo -ne "dogdogdog\nelephant\ncat-cat-dog" | ./your_grep.sh -o -E 'cat'
[your_program] cat
[your_program] cat
[tester::#BO4] ✓ Received exit code 0.
[tester::#BO4] ✓ Found line "cat"
[tester::#BO4] ✓ Found line "cat"
[tester::#BO4] ✓ Stdout contains 2 expected lines in order
[tester::#BO4] $ echo -ne "Yesterday I saw 3 panda and I saw 45 tiger.\nNothing interesting today.\nLast week I saw 12 tigers." | ./your_grep.sh -o -E 'I saw \d+ (panda|tiger)s?'
[your_program] I saw 3 panda
[your_program] I saw 45 tiger
[your_program] I saw 12 tigers
[tester::#BO4] ✓ Received exit code 0.
[tester::#BO4] ✓ Found line "I saw 3 panda"
[tester::#BO4] ✓ Found line "I saw 45 tiger"
[tester::#BO4] ✓ Found line "I saw 12 tigers"
[tester::#BO4] ✓ Stdout contains 3 expected lines in order
[tester::#BO4] $ echo -ne "today is sunny\nno rains here\ntomorrow maybe rainy" | ./your_grep.sh -o -E 'cats and dogs'
[tester::#BO4] ✓ Received exit code 1.
[tester::#BO4] ✓ No output found
[tester::#BO4] Test passed.
24 changes: 14 additions & 10 deletions internal/test_helpers/pass_all/your_grep.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/sh
# GNU Grep:
# From -E extended-regexp to -P perl-regexp
if [ "$1" = "-E" ]; then
shift
set -- -P "$@"
fi
#!/bin/bash

# Build new arguments, replacing -E with -P in place
new_args=()
for arg in "$@"; do
if [ "$arg" = "-E" ]; then
new_args+=("-P")
else
new_args+=("$arg")
fi
done

if [ "$(uname)" = "Darwin" ]; then
exec ggrep "$@" # GNU grep from brew on macOS
exec ggrep "${new_args[@]}" # GNU grep from brew on macOS
else
exec "$(dirname "$0")/find_grep_linux.sh" "$@"
fi
exec "$(dirname "$0")/find_grep_linux.sh" "${new_args[@]}"
fi