Running phpunit in a loop and let it inform you when you broke something

Flattr this
Tweet this: Running phpunit in a loop and let it inform you when you broke something
Dent this: Running phpunit in a loop and let it inform you when you broke something
Datum: 15.08.2010 10:20:42

When refactoring code or tests I like working until I break something. When my phpunit tests switch from green to red, I want to know it immediately without restarting the tests manually each time I change something, because that's annoying and a waste of time.
So after thinking about running the test-suite after each save in Netbeans, which I didn't find a way to do it and for unittests which run longer than some seconds, it wouldn't probably be such a good solution if after saving some changes the testsuite will take minutes to run. So I came up with another simple solution:

while true; do phpunit; if [ $? -ne 0 ]; then break; else sleep 5; fi; done;

This one-liner runs phpunit in a loop, displays the output eatch time, sleeps for 5 seconds after finishing the run and stopfs if something breaks, so you'll see the last report.
I tweeted that already some time ago, but it was annoying to be distracted by the continous output.
So I had to make it less distracting. Now it outputs the lastest phpunit-output only if it fails and thus is much less distractive.

while true; do FOO=`/usr/bin/phpunit`; if [ $? -ne 0 ]; then echo $FOO; break; else sleep 5; fi; done;

But, it wasn't perfect yet. Since I sometimes didn't notice, when tests failed, I needed some harder way to notify me whie I am focused on coding.
So I came up with this version, which plays a sound (from openoffice) via vlc if a test fails:

while true; do FOO=`/usr/bin/phpunit`; if [ $? -ne 0 ]; then echo $FOO; vlc --play-and-exit "/usr/lib/openoffice/basis3.2/share/gallery/sounds/ups.wav" 2> /dev/null & ; break; else sleep 5; fi; done;

And if you prefer a popup instead of a hell output and sound you can use xmessage for that:

while true; do FOO=`/usr/bin/phpunit`; if [ $? -ne 0 ]; then xmessage -center "$FOO" & break; else sleep 5; fi; done;

This will look somehow like that:

error popup from phpunit via xmessage

Trackbacks (0)

Trackbackurl: http://www.robo47.net/trackback/blogentry/201

Es sind keine Trackbacks vorhanden.


Kommentare (0)

Es sind noch keine Kommentare vorhanden.

Die Kommentare zu diesem Beitrag sind gesperrt.

You liked it ? Link it on your homepage or blog: