Hacker News new | past | comments | ask | show | jobs | submit login

Wouldn't this example do the incorrect thing in the event of a grep error (exit code 2)?



I guess testing specifically for an exit code of 1 isn't as easy to remember.

  (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.


Depends on what you mean by wrong. If the tests can’t run successfully because they detect an error or because they have an error, it still is a valuable signal to raise to the developer.

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?


What would happen is the test would pass, as the logical not of 2 is 0.

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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: