Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: using Test::* modules for generic testing of non perl stuff?

by linux454 (Pilgrim)
on Oct 19, 2004 at 15:28 UTC ( #400560=note: print w/replies, xml ) Need Help??


in reply to Re: using Test::* modules for generic testing of non perl stuff?
in thread using Test::* modules for generic testing of non perl stuff?

Something I whipped up just this morning. It should work with Test::Harness, it may be missing some of the Test::More methods, let me know if I've mised the mark or something else needs to be added.
#!/bin/bash # This is a shell library for interfacing with Perl's Test::Harness fr +amework # Copyright 2004. Michael Grubb SHOULD_PRINT_PLAN=0 TEST_PLAN=0 TEST_COUNTER=0 MATCH_PROG=/bin/egrep MATCH_ARGS="-q" plan() { if [ "${1}" == "no_plan" ] ; then SHOULD_PRINT_PLAN=1 TEST_PLAN=0 else TEST_PLAN="${1}" SHOULD_PRINT_PLAN=1 _printPlan SHOULD_PRINT_PLAN=0 fi } endtests() { _printPlan } ok() { _updatePlan if [ $1 != 0 ]; then echo -n "not " fi echo "ok ${TEST_COUNTER} ${2} # \$1 is '$1'" } is() { _updatePlan if [ $1 != ${2} ] ; then echo -n "not " fi echo "ok ${TEST_COUNTER} ${3} # expecting '$1' got '$2'" } match() { _updatePlan echo "$2" | ${MATCH_PROG} ${MATCH_ARGS} ${1} rv=$? if [ $rv -ne 0 ] ; then echo -n "not " fi echo -n "ok ${TEST_COUNTER} ${3} " if [ $rv -ne 0 ] ; then echo "# '$2' did not match '$1'" else echo fi } diag() { echo "# $1" 1>&2 } _updatePlan() { TEST_COUNTER=$((${TEST_COUNTER}+1)) if [ ${SHOULD_PRINT_PLAN} ] ; then TEST_PLAN=${TEST_COUNTER} ; fi } _printPlan() { if [ ${SHOULD_PRINT_PLAN} -eq 1 ] ; then echo "1..${TEST_PLAN}" fi }

And here is a script that shows it's usage:

#!/bin/bash . ./Test.sh plan "no_plan" diag "# TEST_PLAN=$TEST_PLAN" ok 0 "Test 1" ok 0 "Test 2" ok 2 "Test 3" is "this" "this" is "this" "that" is 1 0 is 0 1 is 1 1 match "^ab[cd]efg$" "abcefg" match "^ab[cd]efg$" "abdefg" match "^ab[cd]efg$" "abcdefg" match "^ab[cd]efg$" "abhefg" endtests # only needed when "no_plan" is used
Hope this helps. Oh, and by default the "match" function uses egrep -q but you can override that if you set MATCH_PROG and MATCH_ARGS after you source Test.sh. Let me know if this is useful. Also note that getting Test::Harness to run this is an excercise left to the reader.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-07-31 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?