I’m stuck on Stage #OL9
I presume the tester cant read my output correctly, in the previous test where there was only one line everything worked
I’ve tried changing the print statement i many ways (removing newline, using just one print outside the loop etc.)
Here are my logs:
#OL9 where it fails
[tester::#OL9] Running tests for Stage #OL9 (File Search - Search a multi-line file)
[tester::#OL9] [setup] echo "watermelon" > "fruits-5243.txt"
[tester::#OL9] [setup] echo "plum" >> "fruits-5243.txt"
[tester::#OL9] [setup] echo "blueberry" >> "fruits-5243.txt"
[tester::#OL9] [setup] echo "strawberry" >> "fruits-5243.txt"
[tester::#OL9] $ ./your_program.sh -E .+berry fruits-5243.txt
[your_program] fruits-5243.txt:blueberry
[your_program] fruits-5243.txt:strawberry
[tester::#OL9] ✓ Received exit code 0.
[tester::#OL9] Expected 2 line(s) in output, only found 0 matching line(s). Missing match(es):
[tester::#OL9] ⨯ Line not found: "blueberry"
[tester::#OL9] ⨯ Line not found: "strawberry"
[tester::#OL9] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
#IS6, the previous test case that worked
[tester::#IS6] Running tests for Stage #IS6 (File Search - Search multiple files)
[tester::#IS6] [setup] echo "lemon" > "fruits-4555.txt"
[tester::#IS6] [setup] echo "blueberry" >> "fruits-4555.txt"
[tester::#IS6] [setup] echo "carrot" > "vegetables-2011.txt"
[tester::#IS6] [setup] echo "broccoli" >> "vegetables-2011.txt"
[tester::#IS6] $ ./your_program.sh -E le.+$ fruits-4555.txt vegetables-2011.txt
[your_program] fruits-4555.txt:lemon
[tester::#IS6] ✓ Received exit code 0.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] $ ./your_program.sh -E missing_fruit fruits-4555.txt vegetables-2011.txt
[tester::#IS6] ✓ Received exit code 1.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] $ ./your_program.sh -E carrot fruits-4555.txt vegetables-2011.txt
[your_program] vegetables-2011.txt:carrot
[tester::#IS6] ✓ Received exit code 0.
[tester::#IS6] ✓ Stdout contains 1 expected line(s)
[tester::#IS6] Test passed.
And here’s a snippet of my code, I’ve included the whole main but the part that matters is commented :
def main():
pattern = sys.argv[2]
if sys.argv[1] != "-E":
print("Expected first argument to be '-E'")
exit(1)
arguments = len(sys.argv)
if arguments == 3:
input_line = sys.stdin.read()
if checks (input_line, pattern) == True:
print(input_line)
exit(0)
else:
exit(1)
##The part which is relevant to the challenge
found = False
for file_name in sys.argv[3:]:
with open(file_name) as file:
for input_line in file:
input_line = input_line.rstrip("\n")
if checks(input_line, pattern): #Pattern matching
print(f"{file_name}:{input_line}")
found = True
if found:
exit(0)
else:
exit(1)
