Hacker News new | ask | show | jobs
by chubot 4012 days ago
I do smoke tests in bash for sure, but writing exhaustive test cases may be better done with unit tests in the language.

You can do something like:

  curl http://localhost/ > actual.json
  diff -u actual.json <<EOF
  {"expected": "json"}
  EOF
  check $? -eq 0
Where check() is a simple wrapper around "test". Or you could write a 2 line "check-eq" function that does the diff too, and that would get you pretty far.

I guess the meta-point is that bash is "just enough". My goal is to deliver working software, and a smoke test written in 10 lines of bash can help tremendously (i.e. reduce trivial errors that cause havoc with a deployment.)

I actually started a bash test framework, probably 2-3 years ago. But honestly, I haven't needed it as much as I thought. Sometimes I copy and paste some functions like "check" into new projects. It ends up being different for each project, so it's perhaps not worth generalizing.

The point is to be lazy, and put off all non-essential tasks, and writing a general test framework for bash proved to be something non-essential. There are existing bash test frameworks out there for sure, but I haven't really found the need to check them out.

Hope that helps.

1 comments

It does actually, thank you very much for taking the time to reply in such detail. Bash testing (or rather, zsh in my case) is definitely something I'll have to consider moving forward.