Skip to content

Commit d141727

Browse files
Merge branch 'main' into highlight-emulated-grep
2 parents 5e52e0a + da95248 commit d141727

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

internal/assertions/ordered_lines_assertion.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ func (a OrderedLinesAssertion) Run(result executable.ExecutableResult, logger *l
6666

6767
if len(a.ExpectedOutputLines) == 0 {
6868
logger.Successf("✓ No output found")
69-
} else {
70-
logger.Successf("✓ Stdout contains %s in order", english.Plural(len(a.ExpectedOutputLines), "expected line", "expected lines"))
69+
}
70+
71+
if len(a.ExpectedOutputLines) > 1 {
72+
logger.Successf("✓ Stdout contains %d expected lines in order", len(a.ExpectedOutputLines))
7173
}
7274

7375
return nil

internal/grep/file_search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func searchFiles(pattern string, files []string, opts fileSearchOptions) Result
4242

4343
return Result{
4444
ExitCode: exitCode,
45-
Stdout: []byte(strings.Join(stdout, "\n")),
46-
Stderr: []byte(strings.Join(stderr, "\n")),
45+
Stdout: []byte(linesToProgramOutput(stdout)),
46+
Stderr: []byte(linesToProgramOutput(stderr)),
4747
}
4848
}
4949

internal/grep/stdin_search.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func searchStdin(pattern string, input string, searchOptions searchOptions) Resu
5454

5555
return Result{
5656
ExitCode: exitCode,
57-
Stdout: []byte(strings.Join(stdout, "\n")),
58-
Stderr: []byte(strings.Join(stderr, "\n")),
57+
Stdout: []byte(linesToProgramOutput(stdout)),
58+
Stderr: []byte(linesToProgramOutput(stderr)),
5959
}
6060
}
6161

internal/grep/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package grep
2+
3+
import "strings"
4+
5+
// linesToProgramOutput converts lines produced by emulated grep to the actual output string
6+
func linesToProgramOutput(lines []string) string {
7+
result := strings.Join(lines, "\n")
8+
9+
// Add newline in case of non-empty output
10+
if result != "" {
11+
result += "\n"
12+
}
13+
14+
return result
15+
}

internal/test_helpers/fixtures/multiple_matches/success

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,24 @@
33
[your_program] 1
44
[tester::#CJ0] ✓ Received exit code 0.
55
[tester::#CJ0] ✓ Found line "1"
6-
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
76
[tester::#CJ0] $ echo -ne "cherry" | ./your_grep.sh -o -E '\d'
87
[tester::#CJ0] ✓ Received exit code 1.
98
[tester::#CJ0] ✓ No output found
109
[tester::#CJ0] $ echo -ne "apple_suffix" | ./your_grep.sh -o -E '^apple'
1110
[your_program] apple
1211
[tester::#CJ0] ✓ Received exit code 0.
1312
[tester::#CJ0] ✓ Found line "apple"
14-
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
1513
[tester::#CJ0] $ echo -ne "prefix_apple" | ./your_grep.sh -o -E '^apple'
1614
[tester::#CJ0] ✓ Received exit code 1.
1715
[tester::#CJ0] ✓ No output found
1816
[tester::#CJ0] $ echo -ne "cat" | ./your_grep.sh -o -E 'ca?t'
1917
[your_program] cat
2018
[tester::#CJ0] ✓ Received exit code 0.
2119
[tester::#CJ0] ✓ Found line "cat"
22-
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
2320
[tester::#CJ0] $ echo -ne "I see 42 dogs" | ./your_grep.sh -o -E '^I see \d+ (cat|dog)s?$'
2421
[your_program] I see 42 dogs
2522
[tester::#CJ0] ✓ Received exit code 0.
2623
[tester::#CJ0] ✓ Found line "I see 42 dogs"
27-
[tester::#CJ0] ✓ Stdout contains 1 expected line in order
2824
[tester::#CJ0] Test passed.
2925

3026
[tester::#SS2] Running tests for Stage #SS2 (ss2)

internal/test_helpers/fixtures/printing_matches/extra_empty_line

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Debug = true
55
[your_program] banana123
66
[tester::#KU5] ✓ Received exit code 0.
77
[tester::#KU5] ✓ Found line "banana123"
8-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
98
[tester::#KU5] $ echo -ne "cherry" | ./your_grep.sh -E '\d'
109
[your_program] 
1110
[tester::#KU5] ✓ Received exit code 1.

internal/test_helpers/fixtures/printing_matches/success

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,24 @@
33
[your_program] banana123
44
[tester::#KU5] ✓ Received exit code 0.
55
[tester::#KU5] ✓ Found line "banana123"
6-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
76
[tester::#KU5] $ echo -ne "cherry" | ./your_grep.sh -E '\d'
87
[tester::#KU5] ✓ Received exit code 1.
98
[tester::#KU5] ✓ No output found
109
[tester::#KU5] $ echo -ne "apple_suffix" | ./your_grep.sh -E '^apple'
1110
[your_program] apple_suffix
1211
[tester::#KU5] ✓ Received exit code 0.
1312
[tester::#KU5] ✓ Found line "apple_suffix"
14-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
1513
[tester::#KU5] $ echo -ne "prefix_apple" | ./your_grep.sh -E '^apple'
1614
[tester::#KU5] ✓ Received exit code 1.
1715
[tester::#KU5] ✓ No output found
1816
[tester::#KU5] $ echo -ne "cat" | ./your_grep.sh -E 'ca+t'
1917
[your_program] cat
2018
[tester::#KU5] ✓ Received exit code 0.
2119
[tester::#KU5] ✓ Found line "cat"
22-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
2320
[tester::#KU5] $ echo -ne "ptest" | ./your_grep.sh -E '[pineapple]'
2421
[your_program] ptest
2522
[tester::#KU5] ✓ Received exit code 0.
2623
[tester::#KU5] ✓ Found line "ptest"
27-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
2824
[tester::#KU5] Test passed.
2925

3026
[tester::#PZ6] Running tests for Stage #PZ6 (pz6)

internal/test_helpers/fixtures/printing_matches/unexpected_output

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Debug = true
55
[your_program] banana123
66
[tester::#KU5] ✓ Received exit code 0.
77
[tester::#KU5] ✓ Found line "banana123"
8-
[tester::#KU5] ✓ Stdout contains 1 expected line in order
98
[tester::#KU5] $ echo -ne "cherry" | ./your_grep.sh -E '\d'
109
[your_program] cherry
1110
[tester::#KU5] ✓ Received exit code 1.

0 commit comments

Comments
 (0)