test(aio,socket,tty): match musl error messages
[jimtcl.git] / tests / aio.test
blob4b04dbd2fd9279f8df891e52c7e220fa3e2ff1ec
1 source [file dirname [info script]]/testing.tcl
3 needs constraint jim
4 testCmdConstraints socket
6 # Create and open in binary mode for compatibility between Windows and Unix
7 set f [open testdata.in wb]
8 $f puts test-data
9 $f close
10 set f [open testdata.in rb]
12 defer {
13         $f close
16 test aio-1.1 {seek usage} -body {
17         $f seek
18 } -returnCodes error -match glob -result {wrong # args: should be "* seek offset ?start|current|end"}
20 test aio-1.2 {seek start} -body {
21         $f seek 2
22         $f tell
23 } -result {2}
25 test aio-1.3 {seek start} -body {
26         $f seek 4 start
27         $f tell
28 } -result {4}
30 test aio-1.4 {read after seek} -body {
31         set c [$f read 1]
32         list $c [$f tell]
33 } -result {- 5}
35 test aio-1.5 {seek backwards} -body {
36         $f seek -2 current
37         set c [$f read 1]
38         list $c [$f tell]
39 } -result {t 4}
41 test aio-1.6 {seek from end} -body {
42         $f seek -2 end
43         set c [$f read 2]
44         list $c [$f tell]
45 } -result [list "a\n" 10]
47 test aio-1.7 {seek usage} -body {
48         $f seek 4 bad
49 } -returnCodes error -match glob -result {wrong # args: should be "* seek offset ?start|current|end"}
51 test aio-1.8 {seek usage} -body {
52         $f seek badint
53 } -returnCodes error -match glob -result {expected integer but got "badint"}
55 test aio-1.9 {seek bad pos} -body {
56         $f seek -20
57 } -returnCodes error -match glob -result {testdata.in: Invalid argument}
59 test aio-2.1 {read usage} -body {
60         $f read -nonoption
61 } -returnCodes error -result {bad option "-nonoption": must be -nonewline, or -pending}
63 test aio-2.2 {read usage} -body {
64         $f read badint
65 } -returnCodes error -result {expected integer but got "badint"}
67 test aio-2.3 {read -ve len} -body {
68         $f read " -20"
69 } -returnCodes error -result {invalid parameter: negative len}
71 test aio-2.4 {read too many args} -body {
72         $f read 20 extra
73 } -returnCodes error -match glob -result {wrong # args: should be "* read ?-nonewline|-pending|len?"}
75 test aio-2.5 {read -pending on non-ssl} -body {
76         $f read -pending
77 } -returnCodes error -result {-pending not supported on this connection type}
79 test aio-3.1 {copy to invalid fh} -body {
80         $f copy lambda
81 } -returnCodes error -result {Not a filehandle: "lambda"}
83 test aio-3.2 {copy bad length} -body {
84         $f copy stdout invalid
85 } -returnCodes error -result {expected integer but got "invalid"}
87 set badvar a
89 test aio-4.1 {gets invalid var} -body {
90         $f gets badvar(abc)
91 } -returnCodes error -result {can't set "badvar(abc)": variable isn't array}
93 test aio-5.1 {puts usage} -body {
94         stdout puts -badopt abc
95 } -returnCodes error -result {wrong # args: should be "stdout puts ?-nonewline? str"}
97 test aio-6.1 {eof} {
98         $f seek 0
99         $f eof
100 } {0}
102 test aio-6.2 {eof} {
103         # eof won't trigger until we try to read
104         $f seek 0 end
105         $f eof
106 } {0}
108 test aio-6.3 {eof} {
109         $f read 1
110         $f eof
111 } {1}
113 test aio-7.1 {close args} -constraints socket -body {
114         $f close badopt
115 } -returnCodes error -result {bad option "badopt": must be -nodelete, r, or w}
117 test aio-7.2 {close w on non-socket} -constraints socket -body {
118         $f close w
119 } -returnCodes error -match regexp -result {^(Socket operation on non-socket|Not a socket)$}
121 test aio-7.3 {close -nodelete on non-socket} -constraints socket -body {
122         $f close -nodelete
123 } -returnCodes error -result {not supported}
125 test aio-8.1 {filename} {
126         $f filename
127 } testdata.in
129 testreport