Hacker News new | past | comments | ask | show | jobs | submit login
Bats: TAP-compatible testing for Bash (github.com/sstephenson)
41 points by sstephenson on Dec 30, 2011 | hide | past | favorite | 13 comments



Hi there,

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


Thanks for pointing me to the TAP Producers list; added Sharness too (http://git.io/sharness). I'm sure it can be used with Jenkins as well.


You could also try wvtest, which is a bit lighter weight and works with any shell, not just bash: https://github.com/apenwarr/wvtest


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.


FWIW here's a vaguely doctest-like tool I wrote: https://github.com/darius/tush

May be unsuitable for you, as you say -- it looks like it takes less typing/punctuation to write the example tests, though.


Wow, I really like the literate style. Great stuff.


Thanks!


Another test framework written in (pure) shell is Sharness: http://git.io/sharness

It was derived from the Git test harness. I'm already using it for a couple of my projects.


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.

This is also known as the UNIX philosophy :)


I doubt that all of git commit is implemented in main. So I'm sure that there is still plenty of use for unit tests.


As a matter of fact, all automated tests of the Git project are powered by a shell-based TAP harness, which tests executable commands only.

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.




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

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

Search: