mardi 26 juillet 2016

How to test "main()" routine from "go test"?

I want to lock the user-facing command line API of my golang program by writing few anti-regression tests that would focus on testing my binary as a whole. What testing "binary as a whole" means is that go-test should:

  1. be able to feed STDIN to my binary
  2. be able to check that my binary produces correct STDOUT
  3. be able to ensure that error cases are handled properly by binary

However, it is not obvious to me what is the best practice to do that in go? If there is a good go test example, could you point me to it?

P.S. in the past I have been using autotools. And I am looking for something similar to AT_CHECK, for example:

AT_CHECK([echo "XXX" | my_binary -e arg1 -f arg2], [1], [],
  [-f and -e can't be used together])

Aucun commentaire:

Enregistrer un commentaire