From e2fad6a3fa1a1911c5c3014b6d9206aadcd7bf7e Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 19 May 2004 10:38:23 +0000 Subject: Fixed get.test so it really tests Tcl_GetInt() and uses constraints properly. --- ChangeLog | 6 +++ generic/tclTest.c | 36 +++++++++++++++++- tests/get.test | 110 ++++++++++++++++++++---------------------------------- 3 files changed, 81 insertions(+), 71 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5173925..9c28462 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-05-19 Donal K. Fellows + + * generic/tclTest.c (TestgetintCmd): Made the tests in get.test check + * tests/get.test: Tcl_GetInt() since the core now + avoids that function. + 2004-05-18 Kevin B. Kenny * compat/strftime.c (_fmt, ISO8601Week): diff --git a/generic/tclTest.c b/generic/tclTest.c index 4867e1c..fc0356f 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclTest.c,v 1.81 2004/04/06 22:25:55 dgp Exp $ + * RCS: @(#) $Id: tclTest.c,v 1.82 2004/05/19 10:38:24 dkf Exp $ */ #define TCL_TEST @@ -257,6 +257,8 @@ static int TestfeventCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, CONST char **argv)); static int TestgetassocdataCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, CONST char **argv)); +static int TestgetintCmd _ANSI_ARGS_((ClientData dummy, + Tcl_Interp *interp, int argc, CONST char **argv)); static int TestgetplatformCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int argc, CONST char **argv)); static int TestgetvarfullnameCmd _ANSI_ARGS_(( @@ -634,6 +636,8 @@ Tcltest_Init(interp) (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testgetassocdata", TestgetassocdataCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); + Tcl_CreateCommand(interp, "testgetint", TestgetintCmd, + (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp, "testgetplatform", TestgetplatformCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "testgetvarfullname", @@ -6604,3 +6608,33 @@ TestHashSystemHashCmd(clientData, interp, objc, objv) Tcl_AppendResult(interp, "OK", NULL); return TCL_OK; } + +/* + * Used for testing Tcl_GetInt which is no longer used directly by the + * core very much. + */ +static int +TestgetintCmd(dummy, interp, argc, argv) + ClientData dummy; + Tcl_Interp *interp; + int argc; + CONST char **argv; +{ + if (argc < 2) { + Tcl_SetResult(interp, "wrong # args", TCL_STATIC); + return TCL_ERROR; + } else { + int val,i,total=0; + char buf[TCL_INTEGER_SPACE]; + + for (i=1 ; i 0}] + +test get-1.1 {Tcl_GetInt procedure} testgetint { + testgetint 44 { 22} } {66} -test get-1.2 {Tcl_GetInt procedure} { - set x 44 - incr x -3 +test get-1.2 {Tcl_GetInt procedure} testgetint { + testgetint 44 -3 } {41} -test get-1.3 {Tcl_GetInt procedure} { - set x 44 - incr x +8 +test get-1.3 {Tcl_GetInt procedure} testgetint { + testgetint 44 +8 } {52} -test get-1.4 {Tcl_GetInt procedure} { - set x 44 - list [catch {incr x foo} msg] $msg +test get-1.4 {Tcl_GetInt procedure} testgetint { + list [catch {testgetint 44 foo} msg] $msg } {1 {expected integer but got "foo"}} -test get-1.5 {Tcl_GetInt procedure} { - set x 44 - list [catch {incr x {16 }} msg] $msg +test get-1.5 {Tcl_GetInt procedure} testgetint { + list [catch {testgetint 44 {16 }} msg] $msg } {0 60} -test get-1.6 {Tcl_GetInt procedure} { - set x 44 - list [catch {incr x {16 x}} msg] $msg +test get-1.6 {Tcl_GetInt procedure} testgetint { + list [catch {testgetint 44 {16 x}} msg] $msg } {1 {expected integer but got "16 x"}} - -# The following tests are non-portable because they depend on -# word size. - -if {wide(0x80000000) > wide(0)} { - test get-1.7 {Tcl_GetInt procedure} { - set x 44 - list [catch {eval incr x 18446744073709551616} msg] $msg $errorCode - } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} - test get-1.8 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x 18446744073709551614} msg] $msg - } {0 -2} - test get-1.9 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x +18446744073709551614} msg] $msg - } {0 -2} - test get-1.10 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x -18446744073709551614} msg] $msg - } {0 2} -} else { - test get-1.11 {Tcl_GetInt procedure} { - set x 44 - list [catch {incr x 4294967296} msg] $msg $errorCode - } {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} - test get-1.12 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x 4294967294} msg] $msg - } {0 -2} - test get-1.13 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x +4294967294} msg] $msg - } {0 -2} - test get-1.14 {Tcl_GetInt procedure} { - set x 0 - list [catch {incr x -4294967294} msg] $msg - } {0 2} -} +test get-1.7 {Tcl_GetInt procedure} {testgetint intsAre64bit} { + list [catch {testgetint 44 18446744073709551616} msg] $msg $errorCode +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} +test get-1.8 {Tcl_GetInt procedure} {testgetint intsAre64bit} { + list [catch {testgetint 18446744073709551614} msg] $msg +} {0 -2} +test get-1.9 {Tcl_GetInt procedure} {testgetint intsAre64bit} { + list [catch {testgetint +18446744073709551614} msg] $msg +} {0 -2} +test get-1.10 {Tcl_GetInt procedure} {testgetint intsAre64bit} { + list [catch {testgetint -18446744073709551614} msg] $msg +} {0 2} +test get-1.11 {Tcl_GetInt procedure} {testgetint && !intsAre64bit} { + list [catch {testgetint 44 4294967296} msg] $msg $errorCode +} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}} +test get-1.12 {Tcl_GetInt procedure} {testgetint && !intsAre64bit} { + list [catch {testgetint 4294967294} msg] $msg +} {0 -2} +test get-1.13 {Tcl_GetInt procedure} {testgetint && !intsAre64bit} { + list [catch {testgetint +4294967294} msg] $msg +} {0 -2} +test get-1.14 {Tcl_GetInt procedure} {testgetint && !intsAre64bit} { + list [catch {testgetint -4294967294} msg] $msg +} {0 2} test get-2.1 {Tcl_GetInt procedure} { format %g 1.23 @@ -115,15 +97,3 @@ test get-3.2 {Tcl_GetDouble(FromObj), bad numbers} { # cleanup ::tcltest::cleanupTests return - - - - - - - - - - - - -- cgit v0.12