Debian Codegraph @

tests/incr-old.test

raw
1 # Commands covered: incr
2 #
3 # This file contains the original set of tests for Tcl's incr command.
4 # Since the incr command is now compiled, a new set of tests covering
5 # the new implementation is in the file "incr.test". Sourcing this file
6 # into Tcl runs the tests and generates output for errors.
7 # No output means no errors were found.
8 #
9 # Copyright (c) 1991-1993 The Regents of the University of California.
10 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
11 # Copyright (c) 1998-1999 by Scriptics Corporation.
12 #
13 # See the file "license.terms" for information on usage and redistribution
14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
16 if {"::tcltest" ni [namespace children]} {
17 package require tcltest 2.5
18 namespace import -force ::tcltest::*
19 }
20
21 catch {unset x}
22
23 test incr-old-1.1 {basic incr operation} {
24 set x 23
25 list [incr x] $x
26 } {24 24}
27 test incr-old-1.2 {basic incr operation} {
28 set x 106
29 list [incr x -5] $x
30 } {101 101}
31 test incr-old-1.3 {basic incr operation} {
32 set x " -106"
33 list [incr x 1] $x
34 } {-105 -105}
35 test incr-old-1.4 {basic incr operation} {
36 set x " +106"
37 list [incr x 1] $x
38 } {107 107}
39
40 test incr-old-2.1 {incr errors} {
41 list [catch incr msg] $msg
42 } {1 {wrong # args: should be "incr varName ?increment?"}}
43 test incr-old-2.2 {incr errors} {
44 list [catch {incr a b c} msg] $msg
45 } {1 {wrong # args: should be "incr varName ?increment?"}}
46 test incr-old-2.3 {incr errors} {
47 catch {unset x}
48 incr x
49 } 1
50 test incr-old-2.4 {incr errors} {
51 set x abc
52 list [catch {incr x} msg] $msg $::errorInfo
53 } {1 {expected integer but got "abc"} {expected integer but got "abc"
54 while executing
55 "incr x"}}
56 test incr-old-2.5 {incr errors} {
57 set x 123
58 list [catch {incr x 1a} msg] $msg $::errorInfo
59 } {1 {expected integer but got "1a"} {expected integer but got "1a"
60 (reading increment)
61 invoked from within
62 "incr x 1a"}}
63 test incr-old-2.6 {incr errors} -body {
64 proc readonly args {error "variable is read-only"}
65 set x 123
66 trace var x w readonly
67 list [catch {incr x 1} msg] $msg $::errorInfo
68 } -match glob -result {1 {can't set "x": variable is read-only} {*variable is read-only
69 while executing
70 *
71 "incr x 1"}}
72 catch {unset x}
73 test incr-old-2.7 {incr errors} {
74 set x -
75 list [catch {incr x 1} msg] $msg
76 } {1 {expected integer but got "-"}}
77 test incr-old-2.8 {incr errors} {
78 set x { - }
79 list [catch {incr x 1} msg] $msg
80 } {1 {expected integer but got " - "}}
81 test incr-old-2.9 {incr errors} {
82 set x +
83 list [catch {incr x 1} msg] $msg
84 } {1 {expected integer but got "+"}}
85 test incr-old-2.10 {incr errors} {
86 set x {20 x}
87 list [catch {incr x 1} msg] $msg
88 } {1 {expected integer but got "20 x"}}
89
90 # cleanup
91 ::tcltest::cleanupTests
92 return