Has anyone combined Test::Unit with CGI?

Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?

Specifically, I’m thinking:

Create your Test::Unit test case file. Just as it auto-magically
runs the test runner by simply requiring ‘test/unit’ and defining
a class that inherits from Test::Unit::TestCase, I’m thinking if
you require ‘cgi’ – well, if a class named “CGI” is defined – that
the Test::Unit test runner generates its output as a HTML
document.

Perhaps this is too magical: if your testing a CGI script, it’ll
have a CGI class defined and you may not want the output in HTML.
So, maybe defining a flag would be necessary.

I’m just thinking of an easy way of turning a Test::Unit test
case (or suite) into something that can be published to the web
… or, in my case, run the test cases as a CGI script – each hit
to the CGI runs the test cases and sends the results as HTML
back to the browser.

If anyone has already done this, please speak up! I’d love to
use whatever you’ve got. Otherwise, I’m going to start working
on this now.

– Dossy

···


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I’ve heard of a webunit, but I have not had the chance
to use it yet.

···

On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:

Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?


Jim Freeze
If only I had something clever to say for my comment…
~

Dossy dossy@panoptic.com wrote in message news:20020715023521.GH24646@panoptic.com

Just as it auto-magically
runs the test runner by simply requiring ‘test/unit’ and defining
a class that inherits from Test::Unit::TestCase, I’m thinking if
you require ‘cgi’ – well, if a class named “CGI” is defined – that
the Test::Unit test runner generates its output as a HTML
document.

Would something like this work:

print "Content-type: text/html\r\n"
print "\r\n"
print “

… run tests, do output here …

print “

It would make your shell run test output uglier, but I think this
should work online. Alternatively, you could have two seperate entry
points to the application, one of which was a cgi:

run_my_tests.rb
cgi_run_my_tests.rb

I don’t think it’s simple to autodetect whether a script is running
within a cgi enviroment. Look at the code for the QueryExtension
module within cgi for the enviroment checking code.

~ Patrick

I’m not talking of combining them in that way.

I’m talking more like a test/unit/ui/web/testrunner.rb … which I’ve
got something that “works” for me now already … no unit tests for
it, though. Just a mad copy-and-paste from
test/unit/ui/console/testrunner.rb and test/unit.rb …

– Dossy

···

On 2002.07.15, Jim Freeze jim@freeze.org wrote:

On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:

Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?

I’ve heard of a webunit, but I have not had the chance
to use it yet.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I think webunit is a different beast - it is modeled tightly off httpunit
(java testing framework for testing http responses IIRC).


Signed,
Holden Glova

···

On Mon, 15 Jul 2002 15:13, Jim Freeze wrote:

On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:

Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?

I’ve heard of a webunit, but I have not had the chance
to use it yet.

Would something like this work:

print "Content-type: text/html\r\n"
print "\r\n"
print “

… run tests, do output here …

print “

This is what the initial version of mine did. Of course,

 isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …

Now, where my code is at … can pretty much handle everything the
right way, IMHO. :wink:

I don’t think it’s simple to autodetect whether a script is running
within a cgi enviroment. Look at the code for the QueryExtension
module within cgi for the enviroment checking code.

I test for ENV[‘GATEWAY_INTERFACE’].nil? which is Good Enough for me.

– Dossy

···

On 2002.07.15, Patrick May patrick-may@monmouth.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

If anyone is keen to try my changes out …

See what it does here:

http://panoptic.com/ruby/test_unit/tc_web_testrunner.cgi

See how it does it here:

http://panoptic.com/ruby/test_unit/tc_web_testrunner.cgi.txt
http://panoptic.com/ruby/test_unit/web_testrunner.rb.txt

Yes, it’s just mostly copy-and-paste. Yes, I don’t have unit
tests for my changes (yet). Yes, I crammed this together in
probably under an hour – it could use lots of cleaning up, and
some snazzier styling to boot.

I may be inclined to clean things up if there’s interest from
anyone but myself. :wink:

– Dossy

···

On 2002.07.15, Dossy dossy@panoptic.com wrote:

On 2002.07.15, Jim Freeze jim@freeze.org wrote:

On Mon, Jul 15, 2002 at 11:35:25AM +0900, Dossy wrote:

Doing some Test::Unit work on my CGI scripts, I wondered if anyone
had done any work combining Test::Unit with CGI?

I’ve heard of a webunit, but I have not had the chance
to use it yet.

I’m not talking of combining them in that way.

I’m talking more like a test/unit/ui/web/testrunner.rb … which I’ve
got something that “works” for me now already … no unit tests for
it, though. Just a mad copy-and-paste from
test/unit/ui/console/testrunner.rb and test/unit.rb …


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

What about using…

print "Content-type: text/plain\r\n"
print “\r\n”

Would that work?

···

On Mon, Jul 15, 2002 at 08:10:22PM +0900, Dossy wrote:

On 2002.07.15, Patrick May patrick-may@monmouth.com wrote:

Would something like this work:

print "Content-type: text/html\r\n"
print "\r\n"
print “

… run tests, do output here …

print “

This is what the initial version of mine did. Of course,

 isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …

Rob | I prefer plaintext email…

“Erm, I don’t want to expose too much of my code, as I’m writing it
fairly plainly at present and I’m sure to be told how all of my
routines can be compressed down into one line with no alphanumeric
characters in them.” [ Ross Clement in comp.lang.perl.misc ]

http://www.w3.org/TR/REC-html40/appendix/changes.html#h-A.3.1

Obsolete elements

The following elements are obsolete: LISTING, PLAINTEXT, and XMP. For
all of them, authors should use the PRE element instead.

···

Dossy (dossy@panoptic.com) wrote:

This is what the initial version of mine did. Of course,

 isn’t
enough – you really want because the expected and actual strings
are guarded with “< … >” and therefore those < and > need to be
HTML escaped as < and > … unless you use …


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04