Why, for the love of Notch, do people keep porting everything that you're supposed to be doing in a real programming language to Bash? Yes, it's Turing complete, but the syntax is ugly and inconsistent, there is just about no support for data structures, and you have to fork a process to do practically anything!
Bats isn't a port of anything, and sometimes Bash is the right tool for the job.
I maintain two other projects written in Bash (rbenv and ruby-build). I looked, and couldn't find any suitable testing tools for Bash, so I created Bats.
My criteria for deciding what to work on in the open-source world is: do I need something that doesn't yet exist, or something whose existing implementations are unsuitable? If yes, I try to fill the void as best I can, and package it up nicely so others can use it too.
I also like contributing to projects if the vision and implementation are not too far off from what I would build myself. Otherwise, I find it hard to contribute to a project that is just too far off but might be able to do the same.
I could see this being very useful for testing little scripts and even small c command line applications i have written.
In the case of the small command line applications this is probably the ideal way to test them. Obviously if the application is even remotely complex you will want unit tests too which probably should be implemented in the language (so you can test your procedures directly) but there is a case for integration tests as well.
If you structure your program in a certain way, there's no need to distinguish between procedures and commands. See git and rbenv, which expose a single meta-command to your $PATH but are comprised internally of many smaller commands that invoke each other and communicate over standard I/O.
There are two other tools that produce TAP in Shell there, but I haven't used any of them. Before going to sleep I decided give it a try to use Bats in Jenkins. Here's the result:
15 comments
[ 2.9 ms ] story [ 37.6 ms ] threadI maintain two other projects written in Bash (rbenv and ruby-build). I looked, and couldn't find any suitable testing tools for Bash, so I created Bats.
My criteria for deciding what to work on in the open-source world is: do I need something that doesn't yet exist, or something whose existing implementations are unsuitable? If yes, I try to fill the void as best I can, and package it up nicely so others can use it too.
It was derived from the Git test harness. I'm already using it for a couple of my projects.
May be unsuitable for you, as you say -- it looks like it takes less typing/punctuation to write the example tests, though.
In the case of the small command line applications this is probably the ideal way to test them. Obviously if the application is even remotely complex you will want unit tests too which probably should be implemented in the language (so you can test your procedures directly) but there is a case for integration tests as well.
This is also known as the UNIX philosophy :)
To be fair, there are some dedicated C tools driving unit tests via CLI, but most of the tests are based on the final plumbing and porcelain commands.
Perhaps you could add this to the list of TAP Producers in testanything.org. Here's the link for the Shell producers entry.
http://testanything.org/wiki/index.php/TAP_Producers#SH_.2F_...
There are two other tools that produce TAP in Shell there, but I haven't used any of them. Before going to sleep I decided give it a try to use Bats in Jenkins. Here's the result:
http://www.kinoshita.eti.br/2011/12/30/testing-shell-code-an...
Thanks for sharing.
Cheers, Bruno P. Kinoshita