Laboratory Exercises For Computer Science 153

"Hints for testing and debugging the CGI project

"Hints for testing and debugging the CGI project

Redefining getenv

The fact that the getenv procedure that is used to recover the query string is not standard and not available in Chez Scheme makes it a little difficult to test pieces of your program with the Chez Scheme interactive interface. Even if you switch to SCM, it's still a little awkward to test without installing the partially developed CGI program on the Web -- something you may be reluctant to do, especially while it may contain errors.

One way to work around both of these problems is to supply your own definition of getenv, filling in the gap in Chez Scheme and overriding SCM's built-in definition. Since this temporary version of getenv will be used only during testing, it doesn't have to recover a genuine query string; a more convenient arrangement would be to have it ignore its argument and return the same string constant every time it is invoked.

With this arrangement, you can put a semicolon at the beginning of the line

#!/usr/local/bin/scm -q

at the beginning of the program, to comment it out, and then execute the program as if it were any other Scheme program. Inspect the output to make sure that all of the HTML markup is correct and that all of the pieces are present.

A form interface

Subsequently, when the program is essentially finished and you want to test it on-line, you'll remove the semicolon from the first line and the fake definition of getenv. Because it's a nuisance to have to type in the query string yourself, as part of the URL, you may find it useful to copy the ``form interface'' at form-test.html into your own public_html directory, make it accessible with the command

chmod 755 ~/public_html/form-test.html

and then load it into the browser with the URL

http://www.yourserver.edu/~yourname/form-test.html

To transmit a query string to cgi-project.cgi, type in a year number and a month number and press the button marked Submit. The form will automatically generate the URL containing the query string and request the document from the server.


This document is available on the World Wide Web as

http://www.math.grin.edu/~walker/courses/153/project-cgi-hints.html

created April 20, 1997 by John David Stone
last revised January 12, 1998 by Henry M. Walker