summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-05-19 10:38:23 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-05-19 10:38:23 (GMT)
commite2fad6a3fa1a1911c5c3014b6d9206aadcd7bf7e (patch)
treeb036f8e5aab29934ba73f924fc0591df69bb193f
parent4a48fddf76997f4e8db2a639205e385eecf837d1 (diff)
downloadtcl-e2fad6a3fa1a1911c5c3014b6d9206aadcd7bf7e.zip
tcl-e2fad6a3fa1a1911c5c3014b6d9206aadcd7bf7e.tar.gz
tcl-e2fad6a3fa1a1911c5c3014b6d9206aadcd7bf7e.tar.bz2
Fixed get.test so it really tests Tcl_GetInt() and uses constraints properly.
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclTest.c36
-rw-r--r--tests/get.test110
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 <donal.k.fellows@man.ac.uk>
+
+ * 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 <kennykb@acm.org>
* 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<argc ; i++) {
+ if (Tcl_GetInt(interp, argv[i], &val) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ total += val;
+ }
+ TclFormatInt(buf, total);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ return TCL_OK;
+ }
+}
diff --git a/tests/get.test b/tests/get.test
index 4c3f679..a04e131 100644
--- a/tests/get.test
+++ b/tests/get.test
@@ -10,76 +10,58 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: get.test,v 1.8 2002/11/19 02:34:50 hobbs Exp $
+# RCS: @(#) $Id: get.test,v 1.9 2004/05/19 10:38:24 dkf Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import -force ::tcltest::*
}
-test get-1.1 {Tcl_GetInt procedure} {
- set x 44
- incr x { 22}
+testConstraint testgetint [llength [info commands testgetint]]
+testConstraint intsAre64bit [expr {int(0x80000000) > 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
-
-
-
-
-
-
-
-
-
-
-
-