For Gauche 0.9.5

Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]

12.71 www.cgi.test - CGI testing

Module: www.cgi.test

This module defines a useful procedures to test CGI script. The test actually runs the named script, with specified enviornment variable settings, and retrieve the output. Your test procedure then examine whether the output is as expected or not.

Function: cgi-test-enviornment-ref envvar-name
Function: (setter cgi-test-enviornment-ref) envvar-name value

The module keeps a table of default values of enviornment variables with which the cgi script will be run. These procedures allow the programmer to get/set those default values.

Note that you can override these default values and/or pass additional environment variables for each call of cgi script. The following environment variables are set by default.

Function: call-with-cgi-script script proc :key (environment ()) (parameters #f)

Runs a script with given enviornment, and calls proc with one argument, an input port which is connected to the pipe of script’s standard output. The argument script should be a list of program name and its arguments. Each element are passed to x->string first to stringify. The script is run under the enviornment given by enviornment variable and the default test environment described above. The environment argument must be an associative list, in which each key (car) is the name of the enviornment variable and its cdr is the value. Both are passed to x->string first. If the same environment variable appears in environment and the default test enviornment, the one in environment is used. Additionally, if an associative list is given to the parameters argument, a query string is built from it and passed the script. The actual method to pass the query string depends on the value of REQUEST_METHOD environment variable in the setting. If REQUEST_METHOD is either GET or HEAD, the query string is put in an environment variable QUERY_STRING. If it is POST, the query string is fed to the standard input of the script. In the latter case, CONTENT_TYPE is set to application/x-www-form-urlencoded and CONTENT_LENGTH are set to the length of QUERY_STRING automatically. If REQUEST_METHOD is other values, parameters is ignored. You can bypass this mechanism and set up enviornment variable QUERY_STRING directly, if you wish.

Function: run-cgi-script->header&body script reader :key environment parameters

A convenient wrapper of call-with-cgi-script. The script, environment and parameters are passed to call-with-cgi-script as they are. The output of the script is parsed by run-cgi-script->header&body. First, the RFC2822 header fields are parsed by rfc822-read-headers (see RFC822 message parsing). Then, the reader is called with an input port which is piped to the script’s output. Run-cgi-script->header&body returns two values, the list of headers (as parsed by rfc822-read-headers), and the return value of reader.

Function: run-cgi-script->sxml script :key environment parameters

This is a procedure that uses ssax:xml->sxml (see Functional XML parser) as the reader in run-cgi-script->header&body. Useful when you’re testing a cgi script that produces well-formed HTML and/or XML document.

Function: run-cgi-script->string script :key environment parameters
Function: run-cgi-script->string-list script :key environment parameters

These procedures use port->string and port->string-list (see Input utility functions) as the reader in run-cgi-script->header&body, respectively.

An example:

(run-cgi-script->string-list "bbs.cgi"
                             :environment '((REMOTE_ADDR . ""))
                             :parameters '((command . "view")
                                           (page . 1234)))

Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]