I’m not sure if this is true for the other test cases, but I’ve noticed this behaviour in #A07 because it initially caused my test to fail when running the CLI but pass when I copy/paste and run the command to run locally. It seems the test runner is not appending a trailing newline, ie. either echo is being used with -n
or simply a string is being piped in without the newline that echo would normally append.
For clarity I’ve added print statements and run my code to show this behaviour:
❯ echo "cat" | ./your_grep.sh -E "cat$"
input: "cat\n"
pattern: "cat$"
result: Ok(true)
❯ codecrafters test
Initiating test run...
⚡ This is a turbo test run. https://codecrafters.io/turbo
Running tests. Logs should appear shortly...
[compile] Compiling grep-starter-rust v0.1.0 (/app)
[compile] Finished release [optimized] target(s) in 0.98s
[compile] Compilation successful.
Debug = true
[tester::#AO7] Running tests for Stage #AO7 (End of string anchor)
[tester::#AO7] $ echo "cat" | ./your_grep.sh -E "cat$"
[your_program] input: "cat"
[your_program] pattern: "cat$"
[your_program] result: Ok(false)
[tester::#AO7] expected exit code 0, got 1
[tester::#AO7] Test failed
View our article on debugging test failures: https://codecrafters.io/debug