aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2020-04-17 16:23:37 +1000
committerSteve Bennett <steveb@workware.net.au>2020-04-17 17:36:50 +1000
commitb081ba9fe23cb52fbd17a7f4635244c9ce3ff1fa (patch)
tree3f32b3f3d0fac917ef15817e726617f86d1fce6c
parent35b0acdccfe58043717b026fa2d86ecd76711c85 (diff)
downloadjimtcl-b081ba9fe23cb52fbd17a7f4635244c9ce3ff1fa.zip
jimtcl-b081ba9fe23cb52fbd17a7f4635244c9ce3ff1fa.tar.gz
jimtcl-b081ba9fe23cb52fbd17a7f4635244c9ce3ff1fa.tar.bz2
tests: improve code coverage
- clock - array - file tempfile - lreverse - string byterange - aio tty Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--tests/array.test20
-rw-r--r--tests/clock.test42
-rw-r--r--tests/filecopy.test22
-rw-r--r--tests/list.test7
-rw-r--r--tests/string.test40
-rw-r--r--tests/tty.test44
6 files changed, 175 insertions, 0 deletions
diff --git a/tests/array.test b/tests/array.test
index 423276b..38494de 100644
--- a/tests/array.test
+++ b/tests/array.test
@@ -131,4 +131,24 @@ test array-1.23 "array exists non-array" -body {
array exists x
} -result {0}
+test array-2.1 {array -help} -constraints jim -body {
+ array -help
+} -match glob -result {Usage: "array command ... ", where command is one of: *}
+
+test array-2.2 {array -help get} -constraints jim -body {
+ array -help get
+} -result {Usage: array get arrayName ?pattern?}
+
+test array-2.3 {array -help ambiguous} -constraints jim -body {
+ array -help s
+} -match glob -result {Usage: "array command ... ", where command is one of: *}
+
+test array-2.3 {array -help nomatch} -constraints jim -body {
+ array -help unknown
+} -match glob -result {Usage: "array command ... ", where command is one of: *}
+
+test array-2.4 {array ambiguous} -constraints jim -body {
+ array s
+} -returnCodes error -match glob -result {array, ambiguous command "s": should be *}
+
testreport
diff --git a/tests/clock.test b/tests/clock.test
index 4e32df4..f6c0a23 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -30,6 +30,10 @@ test clock-3.6 {clock format tests} -body {
clock format foo
} -returnCodes error -result {expected integer but got "foo"}
+test clock-3.7 {clock format tests} -body {
+ clock format 10000 -format [string repeat x 1000] -gmt true
+} -returnCodes error -result {format string too long or invalid time}
+
test clock-3.8 {clock format tests} -body {
clock format a b c d e g
} -returnCodes error -result {wrong # args: should be "clock format seconds ?-format string? ?-gmt boolean?"}
@@ -47,8 +51,46 @@ test clock-3.11 {clock format tests} {
clock format 123 -format "x"
} x
+test clock-3.12 {clock format tests} -body {
+ clock format 123 -gmt blah
+} -returnCodes error -result {expected boolean but got "blah"}
+
+test clock-3.13 {clock format tests} -body {
+ clock format 123 odd option count
+} -returnCodes error -result {wrong # args: should be "clock format seconds ?-format string? ?-gmt boolean?"}
+
test clock-4.1 {clock scan tests} clockscan {
clock scan {Sun Nov 04 03:02:46 AM 1990} -format {%a %b %d %I:%M:%S %p %Y} -gmt true
} 657687766
+test clock-4.2 {clock scan tests} -constraints clockscan -body {
+ clock scan odd number arg count
+} -returnCodes error -result {wrong # args: should be "clock scan str -format format ?-gmt boolean?"}
+
+test clock-4.3 {clock scan tests} -constraints clockscan -body {
+ clock scan str -bad option
+} -returnCodes error -result {bad option "-bad": must be -format, or -gmt}
+
+test clock-4.4 {clock scan tests} -constraints clockscan -body {
+ clock scan str -gmt true
+} -returnCodes error -result {wrong # args: should be "clock scan str -format format ?-gmt boolean?"}
+
+test clock-4.5 {clock scan tests} -constraints clockscan -body {
+ clock scan str -format "%H" -gmt true
+} -returnCodes error -result {Failed to parse time according to format}
+
+test clock-5.1 {clock seconds} {
+ clock format [clock seconds]
+ list 1
+} {1}
+
+test clock-5.2 {clock millis, micros} {
+ set ms [clock millis]
+ set us [clock micros]
+ set delta [expr {abs($us - $ms * 1000)}]
+ if {$delta > 250000} {
+ error "clock millis and micros differ by too much"
+ }
+} {}
+
testreport
diff --git a/tests/filecopy.test b/tests/filecopy.test
index fea3d33..0c0231e 100644
--- a/tests/filecopy.test
+++ b/tests/filecopy.test
@@ -68,6 +68,28 @@ test filecopy-2.6 "Source and target identical (-force)" {
file size tempfile
} 16
+test file-tempfile-1.1 {file tempfile - simple} {
+ set f [file tempfile]
+ set ret [file exists $f]
+ file delete $f
+ set ret
+} {1}
+
+test file-tempfile-1.2 {file tempfile with pattern} {
+ set f [file tempfile /tmp/file-tempfile.XXXXXX]
+ set ret [file exists $f]
+ file delete $f
+ set ret
+} {1}
+
+test file-tempfile-1.3 {file tempfile with invalid path} -body {
+ set f [file tempfile /doesnotexist/file-tempfile.XXXXXX]
+ puts $f
+ set ret [file exists $f]
+ file delete $f
+ set ret
+} -returnCodes error -match glob -result {/doesnotexist/file-tempfile.*}
+
file delete tempfile
file delete --force tempdir
diff --git a/tests/list.test b/tests/list.test
index d4cecda..c5cbd28 100644
--- a/tests/list.test
+++ b/tests/list.test
@@ -110,4 +110,11 @@ test list-3.1 {SetListFromAny and lrange/concat results} {
slowsort {fred julie alex carol bill annie}
} {alex annie bill carol fred julie}
+test list-4.1 {lreverse} {
+ lreverse {}
+} {}
+test list-4.2 {lreverse} {
+ lreverse {1 2 3}
+} {3 2 1}
+
testreport
diff --git a/tests/string.test b/tests/string.test
index 48451e4..e9d5399 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -977,4 +977,44 @@ test string-23.4 {string cat} {
string cat $abc (def)
} {123(def)}
+test string-24.1 {string byterange} {
+ list [catch {string byterange} msg]
+} {1}
+test string-24.2 {string byterange} {
+ list [catch {string byterange a 1} msg]
+} {1}
+test string-24.3 {string byterange} {
+ list [catch {string byterange a 1 2 3} msg]
+} {1}
+test string-24.4 {string byterange} {
+ string byterange abcdefghijklmnop 2 14
+} {cdefghijklmno}
+test string-24.5 {string byterange, last > length} {
+ string byterange abcdefghijklmnop 7 1000
+} {hijklmnop}
+test string-24.6 {string byterange} {
+ string byterange abcdefghijklmnop 10 end
+} {klmnop}
+test string-24.7 {string byterange, last < first} {
+ string byterange abcdefghijklmnop 10 9
+} {}
+test string-24.8 {string byterange, first < 0} {
+ string byterange abcdefghijklmnop -3 2
+} {abc}
+test string-24.9 {string byterange} {
+ string byterange abcdefghijklmnop -3 -2
+} {}
+test string-24.10 {string byterange, utf8} {
+ string byterange \u00b5\u00b6 0 1
+} \u00b5
+test string-24.11 {string byterange, slice utf8 } {
+ string byterange \u00b5\u00b6 1 2
+} \xb5\xc2
+test string-24.12 {string byterange, full range} {
+ string byterange abcdef 0 end
+} abcdef
+test string-24.13 {string byterange, invalid range} -body {
+ string byterange abcdef foo bar
+} -returnCodes error -result {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?}
+
testreport
diff --git a/tests/tty.test b/tests/tty.test
new file mode 100644
index 0000000..0736947
--- /dev/null
+++ b/tests/tty.test
@@ -0,0 +1,44 @@
+source [file dirname [info script]]/testing.tcl
+
+set havetty 0
+catch {
+ set havetty [expr {"tty" in [stdout -commands]}]
+}
+if {!$havetty} {
+ skiptest " (aio tty)"
+}
+
+test tty-1.1 {tty status} {
+ set dict [stdout tty]
+ dict exists $dict output
+} 1
+
+foreach {id param value} {
+ tty-1.2 output raw
+ tty-1.3 input raw
+ tty-1.4 handshake rtscts
+} {
+ test $id "tty setting $param" -setup {
+ set savetty [stdout tty]
+ } -body "stdout tty $param $value; dict get \[stdout tty\] $param" \
+ -result $value -cleanup {
+ stdout tty $savetty
+ }
+}
+
+test tty-1.4 {tty setting} -body {
+ stdout tty output bad
+} -returnCodes error -result {bad value for output: bad}
+
+test tty-1.4 {tty setting} -body {
+ stdout tty bad value
+} -returnCodes error -result {bad setting "bad": must be baud, data, echo, handshake, input, output, parity, stop, vmin, or vtime}
+
+test tty-1.5 {tty bad fd} -body {
+ set f [open [file tempfile] w]
+ $f tty
+} -returnCodes error -result {Inappropriate ioctl for device} -cleanup {
+ $f close
+}
+
+testreport