Open cassamajor opened 9 months ago
Good spotting, @cassamajor! Have you read The Power of Go: Tests? You're certainly thinking like someone who has.
Can you suggest a suitable change to catch this bug?
I haven't, but it's on my list to read!
Unfortunately, I am not familiar with testscript, and I do not know a suitable fix.
The problem is that these stdout
assertions are not exclusive: that's to say, they specify that the output from the command should contain X, but they don't also say that it shouldn't contain anything else!
We can see from the code in match.go that the matcher's default text is the empty string, and as far as strings.Contains
is concerned, every input line contains the empty string!
Therefore, we need to test that the output contains the lines expected to match, but we also need to test, as you've shown, that it doesn't contain lines that shouldn't match.
We can add that with a negative assertion, using the !
character. Can you see how to fix it?
Here is the
Main
function for match:Let's remove the ability to process arguments
Executing the tests will still pass.
Let's also modify
matches_lines_from_stdin.txtar
to add one additional line that should matchTests still pass, even though we haven't added a
stdout
directive to match the new line.