Wouldn't this example do the incorrect thing in the event of a grep error (exit code 2)?
(grep -q notwanted /hay/stack ; test $? == 1) && echo "No violations found"
But you're right...the simpler format would do the wrong thing if, for example, the file didn't exist or had bad permissions or was a directory instead of a file.Consider what would happen if your unit test framework couldn’t compile the test files and failed with an error. Isn’t that also a test failure?
To address this: many CI pipelines allow you to specify which exot codes to succeed and fail on per job, or if it doesn't the one liner will need some boolean logic to check the exit code.