From: Stephen D. <sd...@us...> - 2005-03-26 14:25:35
|
Update of /cvsroot/naviserver/naviserver/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3873/tests Added Files: ns_parseargs.test Log Message: * include/ns.h: * nsd/nsd.h: * nsd/tclobjv.c: * nsd/tclcmds.c: * tests/ns_parseargs.test: Change the signature of Ns_ObjvProc()s to return either TCL_OK, TCL_ERROR or TCL_BREAK. Fixes a bug where options were being double-counted as args. Also simplified the Ns_ObjvProc interface by passing the Ns_ObjvSpec directly. Added a new Tcl command: ns_parseargs specification args. It parses options, args and handles defaults. * nsd/tclobj.c: Added some wrapper procs for handling Tcl obj types. * nsd/tclinit.c: Added Ns_TclPrintfResult() as a convenience for writing ints into a formatted string result. --- NEW FILE: ns_parseargs.test --- # # $Header: /cvsroot/naviserver/naviserver/tests/ns_parseargs.test,v 1.1 2005/03/26 14:25:26 sdeasey Exp $ # load ../nsd/libnsd.so package require tcltest 2.2 namespace import -force ::tcltest::* eval ::tcltest::configure $argv test ns_parseargs-1.1 {basic syntax} -body { ns_parseargs } -returnCodes error -result {wrong # args: should be "ns_parseargs specification args"} test ns_parseargs-1.2 {basic syntax} -body { ns_parseargs {} {} } -result {} test ns_parseargs-2.1 {object type conversion / display} -body { set spec1 {-a -- x {y Y} args} set spec2 $spec1 ns_parseargs $spec1 X ns_parseargs $spec2 X set spec1 $spec2 ns_parseargs $spec1 X ns_parseargs $spec2 X set spec2 "" set spec2 $spec1 ns_parseargs $spec2 X string equal $spec1 $spec2 } -cleanup { unset -nocomplain -- spec1 spec2 x y args } -result 1 test ns_parseargs-2.2 {object type conversion / display} -body { ns_parseargs a a } -cleanup { unset -nocomplain a } -result {} test ns_parseargs-3.1 {Arguments} -body { ns_parseargs {x y args} {1 2 3 4 5} list $x $y $args } -cleanup { unset -nocomplain -- x y args } -result [list 1 2 [list 3 4 5]] test ns_parseargs-4.1 {Options} -body { ns_parseargs {-a -b -c -d -e} {-b B -d D} list [info exists a] $b [info exists c] $d [info exists e] } -cleanup { unset -nocomplain -- a b c d e } -result [list 0 B 0 D 0] test ns_parseargs-5.1 {Defaults} -body { ns_parseargs {{-a A} -- x {y Y} {args {1 2 3}}} {X} list $a $x $y $args } -cleanup { unset -nocomplain -- a x y args } -result [list A X Y [list 1 2 3]] test ns_parseargs-5.2 {Defaults} -body { ns_parseargs {{-a A} -- x {y Y} {args {1 2 3}}} {-a aaa -- xxx yyy 3 2 1} list $a $x $y $args } -cleanup { unset -nocomplain -- a x y args } -result [list aaa xxx yyy [list 3 2 1]] test ns_parseargs-6.1 {-- ends option parsing} -body { ns_parseargs {-a -- x} {-a A -- X} list $a $x } -cleanup { unset -nocomplain -- a x } -result [list A X] test ns_parseargs-6.2 {-- ends option parsing} -body { ns_parseargs {-a -- x} {-a A X} list $a $x } -cleanup { unset -nocomplain -- a x } -result [list A X] test ns_parseargs-6.1 {-- ends option parsing} -body { ns_parseargs {-a x} {-a A X} list $a $x } -cleanup { unset -nocomplain -- a x } -result [list A X] test ns_parseargs-7.1 {Bad Args} -body { ns_parseargs {-a x} {} } -returnCodes error -result {wrong # args: should be "?-a a? x"} test ns_parseargs-7.2 {Bad Args} -body { ns_parseargs {-a x} {x y} } -returnCodes error -result {wrong # args: should be "?-a a? x"} test ns_parseargs-7.3 {Bad Args} -body { ns_parseargs {-a x} {-b x} } -returnCodes error -result {wrong # args: should be "?-a a? x"} test ns_parseargs-7.4 {Bad Args} -body { ns_parseargs {-a x} {-a a -- x} } -returnCodes error -result {wrong # args: should be "?-a a? x"} cleanupTests |