You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by da...@apache.org on 2001/09/20 01:56:24 UTC
cvs commit: tcl-rivet/tests README makeconf.tcl rivet.test rivet1-test.tcl rivet2-test.tcl runtests.tcl template.conf.tcl
davidw 01/09/19 16:56:24
Added: tests README makeconf.tcl rivet.test rivet1-test.tcl
rivet2-test.tcl runtests.tcl template.conf.tcl
Log:
Added tests. These need cleaning up as well.
Revision Changes Path
1.1 tcl-rivet/tests/README
Index: README
===================================================================
Test Suite for Rivet
$Id: README,v 1.1 2001/09/19 23:56:24 davidw Exp $
These tests are intended to automate the testing of core Rivet
features. They are not complete at this point, and work on them would
be welcome.
How to run the tests:
The program 'runtest.tcl' is launched with the full path to the apache
web server. It then creates a minimal config file in the directory it
is launched from, and launches Apache with the generated config. We
are thusly able to manipulate the environment completely, and run the
tests directly in the tests/ directory...
Note that mod_so.c must be compiled into Apache for this to work.
1.1 tcl-rivet/tests/makeconf.tcl
Index: makeconf.tcl
===================================================================
#!/usr/bin/tclsh
proc getbinname { } {
global argv
set binname [ lindex $argv 0 ]
if { $binname == "" || ! [ file exists $binname ] } {
puts stderr "Please supply the full name and path of the Apache executable on the command line!"
exit 1
}
return $binname
}
# the modules we need and their '.c' names
array set module_assoc {
mod_log_config config_log_module
mod_mime mime_module
mod_negotiation negotiation_module
mod_dir dir_module
mod_access access_module
mod_auth auth_module
}
# get the modules that adre compiled into Apache directly, and return
# the _module name. Check also for the existence of mod_so, which we
# need to load mod_rivet.so in the directory above...
proc getcompiledin { binname } {
global module_assoc
set bin [ open [list | "$binname" -l ] r ]
set compiledin [ read $bin ]
close $bin
set modlist [ split $compiledin ]
set compiledin [list]
set mod_so_present 0
foreach entry $modlist {
if { [regexp {(.*)\.c$} $entry match modname] } {
if { $modname == "mod_so" } { set mod_so_present 1 }
if { [ info exists module_assoc($modname) ] } {
lappend compiledin $module_assoc($modname)
}
}
}
if { $mod_so_present == 0 } {
puts stderr "We need mod_so in Apache to run these tests"
exit 1
}
return $compiledin
}
# find the httpd.conf file
proc gethttpdconf { binname } {
set bin [ open [list | "$binname" -V ] r ]
set options [ read $bin ]
close $bin
regexp {SERVER_CONFIG_FILE="(.*?)"} "$options" match filename
if { ! [ file exists $filename ] } {
# see if we can find something by combining HTTP_ROOT + SERVER_CONFIG_FILE
regexp {HTTPD_ROOT="(.*?)"} "$options" match httpdroot
set completename "$httpdroot/$filename"
if { ! [ file exists $completename ] } {
puts stderr "neither '$filename' or '$completename' exists"
exit 1
}
return $completename
}
return $filename
}
# if we need to load some modules, find out how to do it from the
# 'real' conf file, with this proc
proc getloadmodules { conffile needtoget } {
set fl [ open $conffile r ]
set confdata [ read $fl ]
close $fl
set loadline [list]
foreach mod $needtoget {
if { ! [ regexp -line "^.*?(LoadModule\\s+$mod\\s+.+)\$" $confdata match line ] } {
puts stderr "No LoadModule line for $mod!"
exit 1
} else {
lappend loadline $line
}
}
return [join $loadline "\n"]
}
# compare what's compiled in with what we need
proc determinemodules { binname } {
global module_assoc
set compiledin [lsort [ getcompiledin $binname ]]
set conffile [ gethttpdconf $binname ]
foreach {n k} [ array get module_assoc ] {
lappend needed $k
}
set needed [lsort $needed]
set needtoget [list]
foreach mod $needed {
if { [ lsearch $compiledin $mod ] == -1 } {
lappend needtoget $mod
}
}
if { $needtoget == "" } {
return ""
} else {
return [ getloadmodules $conffile $needtoget ]
}
}
# dump out a config
proc makeconf { binname outfile } {
set CWD [ pwd ]
# replace with determinemodules
set LOADMODULES [ determinemodules $binname ]
set fl [ open "template.conf.tcl" r ]
set template [ read $fl ]
close $fl
set out [ subst $template ]
set of [ open $outfile w ]
puts $of "$out"
close $of
}
#makeconf [ getbinname ]
#puts [ determinemodules $binname ]
#gethttpdconf $binname
#getcompiledin $binname
1.1 tcl-rivet/tests/rivet.test
Index: rivet.test
===================================================================
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
# Rivet test suite, by David N. Welton <da...@apache.org>
# See README file for more information.
# $Id: rivet.test,v 1.1 2001/09/19 23:56:24 davidw Exp $
package require tcltest
package require http 2.1
set urlbase "http://localhost:8080/"
set testfilename1 "rivet1-test.ttml"
set testfilename2 "rivet2-test.ttml"
::tcltest::test hello-1.1 {hello world test} {
set page [ ::http::geturl "${urlbase}$testfilename1" ]
regexp -line {^Hello, World$} [ ::http::data $page ]
} 1
::tcltest::test i18n-1.1 {I18N test} {
set page [ ::http::geturl "${urlbase}$testfilename1" ]
regexp -line {^� � � � � � - El Burro Sabe M�s Que T�!$} [ ::http::data $page ]
} 1
::tcltest::test getvariables-1.1 {GET variables} {
set page [ ::http::geturl "${urlbase}$testfilename1?foobar=goober" ]
regexp -line {^VARS\(foobar\) = goober$} [ ::http::data $page ]
} 1
::tcltest::test getvariables-1.2 {GET variables + I18N} {
set page [ ::http::geturl "${urlbase}$testfilename1?M�s=T�" ]
regexp -line {^VARS\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test getvariables-1.3 {GET variables + I18N + encoding} {
set page [ ::http::geturl [ format "${urlbase}$testfilename1?%s" [ ::http::formatQuery M�s T� ] ] ]
regexp -line {^VARS\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test postvariables-1.1 {POST variables} {
set page [ ::http::geturl "${urlbase}$testfilename1" -query foobar=goober ]
regexp -line {^VARS\(foobar\) = goober$} [ ::http::data $page ]
} 1
::tcltest::test postvariables-1.2 {POST variables + I18N} {
set page [ ::http::geturl "${urlbase}$testfilename1" -query M�s=T� ]
regexp -line {^VARS\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test postvariables-1.3 {POST variables + I18N + encoding} {
set page [ ::http::geturl "${urlbase}$testfilename1" -query [ ::http::formatQuery M�s T� ] ]
regexp -line {^VARS\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test multivariables-1.1 {multiple variables: foo=1&foo=2} {
set page [ ::http::geturl "${urlbase}$testfilename1?foobar=1&foobar=2&foobar=foo+bar" ]
regexp -line {^VARS\(foobar\) = 1 2 foo bar$} [ ::http::data $page ]
} 1
::tcltest::test env-1.1 {Environment variable} {
set page [ ::http::geturl "${urlbase}$testfilename1" ]
regexp -line "^ENVS\\(DOCUMENT_NAME\\) = $testfilename1\$" [ ::http::data $page ]
} 1
::tcltest::test cookies-1.1 {Cookies} {
set page [ ::http::geturl "${urlbase}$testfilename1" -headers {Cookie "foo=bar"} ]
regexp -line {^COOKIES\(foo\) = bar$} [ ::http::data $page ]
} 1
::tcltest::test cookies-1.2 {Cookies + I18N} {
set page [ ::http::geturl "${urlbase}$testfilename1" -headers {Cookie "M�s=T�"} ]
regexp -line {^COOKIES\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test cookies-1.3 {Cookies + I18N + encoding} {
set page [ ::http::geturl "${urlbase}$testfilename1" -headers [ list Cookie [ ::http::formatQuery M�s T� ] ] ]
regexp -line {^COOKIES\(M�s\) = T�$} [ ::http::data $page ]
} 1
::tcltest::test cookies-1.4 {Multiple Cookies} {
set rslt 0
set page [ ::http::geturl "${urlbase}$testfilename1" -headers {Cookie "bop; foo=bar;doo=wah; shoo=be ;doooo=bee;dot=dow "} ]
set pgdata [ ::http::data $page ]
incr rslt [ regexp -line {^COOKIES\(foo\) = bar$} $pgdata ]
incr rslt [ regexp -line {^COOKIES\(doo\) = wah} $pgdata ]
incr rslt [ regexp -line {^COOKIES\(shoo\) = be} $pgdata ]
incr rslt [ regexp -line {^COOKIES\(doooo\) = bee} $pgdata ]
incr rslt [ regexp -line {^COOKIES\(dot\) = dow$} $pgdata ]
incr rslt [ regexp -line {^COOKIES\(bop\) = } $pgdata ]
} 6
::tcltest::test servercookies-1.1 {Cookies from Server} {
set rslt 0
set page [ ::http::geturl "${urlbase}$testfilename1" ]
upvar 0 $page state
array set statehash $state(meta)
regexp -line {mod=rivet; path=[^;]*; expires=01-01-2003} $statehash(Set-Cookie)
} 1
::tcltest::test tclfile-1.1 {Plain .tcl file} {
set page [ ::http::geturl "${urlbase}$testfilename2" ]
set pgdata [string trim [ ::http::data $page ] ]
} "� � � � � � - El Burro Sabe M�s Que T�!"
::tcltest::cleanupTests
1.1 tcl-rivet/tests/rivet1-test.tcl
Index: rivet1-test.tcl
===================================================================
<?
# $Id: rivet1-test.tcl,v 1.1 2001/09/19 23:56:24 davidw Exp $
# rivet page used with Rivet's rivet1-test
hgetvars
headers setcookie -name mod -value rivet -expires 01-01-2003
# hello-1.1
hputs "Hello, World\n"
# i18n-1.1
hputs "� � � � � � - El Burro Sabe M�s Que T�!\n"
if { [ var number ] > 0 } {
# get/post variables 1.1
if { [ var exists foobar ] } {
hputs "VARS(foobar) = [var get foobar]\n"
}
# get/post variables 1.{2,3}
if { [ var exists M�s ] } {
hputs "VARS(M�s) = [var get M�s]\n"
}
}
# env
hputs "ENVS(DOCUMENT_NAME) = $ENVS(DOCUMENT_NAME)\n"
# cookies
if { [ array exists COOKIES ] } {
foreach { ck } [ array names COOKIES ] {
hputs "COOKIES($ck) = $COOKIES($ck)\n"
}
}
?>
1.1 tcl-rivet/tests/rivet2-test.tcl
Index: rivet2-test.tcl
===================================================================
# test file for plain .tcl files
puts "� � � � � � - El Burro Sabe M�s Que T�!"
1.1 tcl-rivet/tests/runtests.tcl
Index: runtests.tcl
===================================================================
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
source makeconf.tcl
set binname [ getbinname ]
makeconf $binname server.conf
set apachepid [ exec $binname -X -f "[pwd]/server.conf" & ]
set oput [ exec ./rivet.test ]
puts $oput
exec kill $apachepid
1.1 tcl-rivet/tests/template.conf.tcl
Index: template.conf.tcl
===================================================================
# \$Id\$
# Minimal config file for testing
# Parsed by makeconf.tcl
ServerType standalone
ServerRoot "$CWD"
PidFile "$CWD/httpd.pid"
# ScoreBoardFile "$CWD/apache_runtime_status"
ResourceConfig "$CWD/srm.conf"
AccessConfig "$CWD/access.conf"
Timeout 300
MaxRequestsPerChild 100
$LOADMODULES
LoadModule rivet_module $CWD/../mod_rivet[info sharedlibextension]
Port 8080
ServerName localhost
DocumentRoot "$CWD"
<Directory "$CWD">
Options All MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.html
</IfModule>
AccessFileName .htaccess
HostnameLookups Off
ErrorLog $CWD/error_log
LogLevel debug
LogFormat "%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined
CustomLog /home/davidw/install/apache-1.3/logs/access_log combined
<IfModule mod_mime.c>
AddLanguage en .en
AddLanguage it .it
AddLanguage es .es
AddType application/x-httpd-tcl .ttml
AddType application/x-rivet-tcl .tcl
</IfModule>