blob: d1d519654e681577ed7b261b2e84fcda43813538 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
|
# This file contains a collection of tests for generic/tclMain.c.
#
# RCS: @(#) $Id: main.test,v 1.4 2002/01/27 11:09:26 das Exp $
if {[catch {package require tcltest 2}]} {
puts stderr "Skipping tests in [info script]. tcltest v2 needed."
return
}
namespace eval ::tcl::main::test {
namespace import ::tcltest::test
namespace import ::tcltest::testConstraint
namespace import ::tcltest::interpreter
namespace import ::tcltest::cleanupTests
namespace import ::tcltest::makeFile
namespace import ::tcltest::removeFile
# Is [exec] defined?
testConstraint exec [llength [info commands exec]]
# Is the Tcltest package loaded?
# - that is, the special C-coded testing commands in tclTest.c
# - tests use testing commands introduced in Tcltest 8.4
testConstraint Tcltest [expr {
[llength [package provide Tcltest]]
&& [package vsatisfies [package provide Tcltest] 8.4]}]
# Procedure to simulate interactive typing of commands, line by line
proc type {chan script} {
foreach line [split $script \n] {
if {[catch {
puts $chan $line
flush $chan
}]} {
return
}
# Grrr... Behavior depends on this value.
after 1000
}
}
# Tests Tcl_Main-1.*: variable initializations
test Tcl_Main-1.1 {
Tcl_Main: startup script - normal
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} script
catch {set f [open "|[interpreter] script" r]}
} -body {
read $f
} -cleanup {
close $f
removeFile script
} -result [list script {} 0]\n
test Tcl_Main-1.2 {
Tcl_Main: startup script - can't begin with '-'
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} -script
catch {set f [open "|[interpreter] -script" w+]}
} -body {
puts $f {puts [list $argv0 $argv $tcl_interactive]; exit}
flush $f
read $f
} -cleanup {
close $f
removeFile -script
} -result [list [interpreter] -script 0]\n
test Tcl_Main-1.3 {
Tcl_Main: encoding of arguments: done by system encoding
Note the shortcoming explained in Tcl Patch 491789
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} script
catch {set f [open "|[interpreter] script \u00c0" r]}
} -body {
read $f
} -cleanup {
close $f
removeFile script
} -result [list script [list [encoding convertfrom [encoding system] \
[encoding convertto [encoding system] \u00c0]]] 0]\n
test Tcl_Main-1.4 {
Tcl_Main: encoding of arguments: done by system encoding
Note the shortcoming explained in Tcl Patch 491789
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} script
catch {set f [open "|[interpreter] script \u20ac" r]}
} -body {
read $f
} -cleanup {
close $f
removeFile script
} -result [list script [list [encoding convertfrom [encoding system] \
[encoding convertto [encoding system] \u20ac]]] 0]\n
test Tcl_Main-1.5 {
Tcl_Main: encoding of script name: system encoding loss
Note the shortcoming explained in Tcl Patch 491789
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} \u00c0
catch {set f [open "|[interpreter] \u00c0" r]}
} -body {
read $f
} -cleanup {
close $f
removeFile \u00c0
} -result [list [list [encoding convertfrom [encoding system] \
[encoding convertto [encoding system] \u00c0]]] {} 0]\n
test Tcl_Main-1.6 {
Tcl_Main: encoding of script name: system encoding loss
Note the shortcoming explained in Tcl Patch 491789
} -constraints [list exec] -setup {
makeFile {puts [list $argv0 $argv $tcl_interactive]} \u20ac
catch {set f [open "|[interpreter] \u20ac" r]}
} -body {
read $f
} -cleanup {
close $f
removeFile \u20ac
} -result [list [list [encoding convertfrom [encoding system] \
[encoding convertto [encoding system] \u20ac]]] {} 0]\n
# Tests Tcl_Main-2.*: application-initialization procedure
test Tcl_Main-2.1 {
Tcl_Main: appInitProc returns error
} -constraints [list exec Tcltest] -setup {
makeFile {puts "In script"} script
} -body {
exec [interpreter] script -appinitprocerror >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "application-specific initialization failed: \nIn script\n"
test Tcl_Main-2.2 {
Tcl_Main: appInitProc returns error
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {puts "In script"} -appinitprocerror >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "application-specific initialization failed: \nIn script\n"
test Tcl_Main-2.3 {
Tcl_Main: appInitProc deletes interp
} -constraints [list exec Tcltest] -setup {
makeFile {puts "In script"} script
} -body {
exec [interpreter] script -appinitprocdeleteinterp >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "application-specific initialization failed: \n"
test Tcl_Main-2.4 {
Tcl_Main: appInitProc deletes interp
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {puts "In script"} \
-appinitprocdeleteinterp >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "application-specific initialization failed: \n"
test Tcl_Main-2.5 {
Tcl_Main: appInitProc closes stderr
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {puts "In script"} \
-appinitprocclosestderr >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "In script\n"
# Tests Tcl_Main-3.*: startup script evaluation
test Tcl_Main-3.1 {
Tcl_Main: startup script does not exist
} -constraints [list exec] -setup {
catch {removeFile no-such-file}
} -body {
set code [catch {exec [interpreter] no-such-file >& result} result]
set f [open result]
list $code $result [read $f]
} -cleanup {
close $f
file delete result
} -match glob -result [list 1 {child process exited abnormally} \
{couldn't read file "no-such-file":*}]
test Tcl_Main-3.2 {
Tcl_Main: startup script raises error
} -constraints [list exec] -setup {
makeFile {error ERROR} script
} -body {
set code [catch {exec [interpreter] script >& result} result]
set f [open result]
list $code $result [read $f]
} -cleanup {
close $f
file delete result
removeFile script
} -match glob -result [list 1 {child process exited abnormally} \
"ERROR\n while executing*"]
test Tcl_Main-3.3 {
Tcl_Main: startup script closes stderr
} -constraints [list exec] -setup {
makeFile {close stderr; error ERROR} script
} -body {
set code [catch {exec [interpreter] script >& result} result]
set f [open result]
list $code $result [read $f]
} -cleanup {
close $f
file delete result
removeFile script
} -result [list 1 {child process exited abnormally} {}]
test Tcl_Main-3.4 {
Tcl_Main: startup script holds incomplete script
} -constraints [list exec] -setup {
makeFile "if 1 \{" script
} -body {
set code [catch {exec [interpreter] script >& result} result]
set f [open result]
list $code $result [read $f]
} -cleanup {
close $f
file delete result
removeFile script
} -match glob -result [list 1 {child process exited abnormally}\
"missing close-brace\n while executing*"]
test Tcl_Main-3.5 {
Tcl_Main: startup script sets main loop
} -constraints [list exec Tcltest] -setup {
makeFile {
rename exit _exit
proc exit {code} {
puts "In exit"
_exit $code
}
after 0 {
puts event
testexitmainloop
}
testexithandler create 0
testsetmainloop
} script
} -body {
exec [interpreter] script >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "event\nExit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-3.6 {
Tcl_Main: startup script sets main loop and closes stdin
} -constraints [list exec Tcltest] -setup {
makeFile {
close stdin
testsetmainloop
rename exit _exit
proc exit {code} {
puts "In exit"
_exit $code
}
after 0 {
puts event
testexitmainloop
}
testexithandler create 0
} script
} -body {
exec [interpreter] script >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "event\nExit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-3.7 {
Tcl_Main: startup script deletes interp
} -constraints [list exec Tcltest] -setup {
makeFile {
rename exit _exit
proc exit {code} {
puts "In exit"
_exit $code
}
testexithandler create 0
testinterpdelete {}
} script
} -body {
exec [interpreter] script >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "even 0\n"
test Tcl_Main-3.8 {
Tcl_Main: startup script deletes interp and sets mainloop
} -constraints [list exec Tcltest] -setup {
makeFile {
testsetmainloop
rename exit _exit
proc exit {code} {
puts "In exit"
_exit $code
}
testexitmainloop
testexithandler create 0
testinterpdelete {}
} script
} -body {
exec [interpreter] script >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result "Exit MainLoop\neven 0\n"
test Tcl_Main-3.9 {
Tcl_Main: startup script can set tcl_interactive without limit
} -constraints [list exec] -setup {
makeFile {set tcl_interactive foo} script
} -body {
exec [interpreter] script >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile script
} -result {}
# Tests Tcl_Main-4.*: rc file evaluation
test Tcl_Main-4.1 {
Tcl_Main: rcFile evaluation deletes interp
} -constraints [list exec Tcltest] -setup {
set rc [makeFile {testinterpdelete {}} rc]
} -body {
exec [interpreter] << {puts "In script"} \
-appinitprocsetrcfile $rc >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile rc
} -result "application-specific initialization failed: \n"
test Tcl_Main-4.2 {
Tcl_Main: rcFile evaluation closes stdin
} -constraints [list exec Tcltest] -setup {
set rc [makeFile {close stdin} rc]
} -body {
exec [interpreter] << {puts "In script"} \
-appinitprocsetrcfile $rc >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile rc
} -result "application-specific initialization failed: \n"
test Tcl_Main-4.3 {
Tcl_Main: rcFile evaluation closes stdin and sets main loop
} -constraints [list exec Tcltest] -setup {
set rc [makeFile {
close stdin
testsetmainloop
after 0 testexitmainloop
testexithandler create 0
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
} rc]
} -body {
exec [interpreter] << {puts "In script"} \
-appinitprocsetrcfile $rc >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile rc
} -result "application-specific initialization failed:\
\nExit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-4.4 {
Tcl_Main: rcFile evaluation sets main loop
} -constraints [list exec Tcltest] -setup {
set rc [makeFile {
testsetmainloop
after 0 testexitmainloop
testexithandler create 0
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
} rc]
} -body {
exec [interpreter] << {puts "In script"} \
-appinitprocsetrcfile $rc >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
removeFile rc
} -result "application-specific initialization failed:\
\nIn script\nExit MainLoop\nIn exit\neven 0\n"
# Tests Tcl_Main-5.*: interactive operations
test Tcl_Main-5.1 {
Tcl_Main: tcl_interactive must be boolean
} -constraints [list exec] -body {
exec [interpreter] << {set tcl_interactive foo} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "can't set \"tcl_interactive\":\
variable must have boolean value\n"
test Tcl_Main-5.2 {
Tcl_Main able to handle non-blocking stdin
} -constraints [list exec] -setup {
catch {set f [open "|[interpreter]" w+]}
} -body {
type $f {
fconfigure stdin -blocking 0
puts SUCCESS
}
list [catch {gets $f} line] $line
} -cleanup {
close $f
} -result [list 0 SUCCESS]
test Tcl_Main-5.3 {
Tcl_Main handles stdin EOF in mid-command
} -constraints [list exec] -setup {
catch {set f [open "|[interpreter]" w+]}
catch {fconfigure $f -blocking 0}
} -body {
type $f "fconfigure stdin -eofchar \\032
if 1 \{\n\032"
variable wait
fileevent $f readable \
[list set [namespace which -variable wait] "child exit"]
after 2000 [list set [namespace which -variable wait] timeout]
vwait [namespace which -variable wait]
set wait
} -cleanup {
if {[string equal timeout $wait]
&& [string equal unix $::tcl_platform(platform)]} {
exec kill [pid $f]
}
close $f
} -result {child exit}
test Tcl_Main-5.4 {
Tcl_Main handles stdin EOF in mid-command
} -constraints [list exec] -setup {
set cmd {makeFile "if 1 \{" script}
catch {set f [open "|[interpreter] < [eval $cmd]" r]}
catch {fconfigure $f -blocking 0}
} -body {
variable wait
fileevent $f readable \
[list set [namespace which -variable wait] "child exit"]
after 2000 [list set [namespace which -variable wait] timeout]
vwait [namespace which -variable wait]
set wait
} -cleanup {
if {[string equal timeout $wait]
&& [string equal unix $::tcl_platform(platform)]} {
exec kill [pid $f]
}
close $f
removeFile script
} -result {child exit}
test Tcl_Main-5.5 {
Tcl_Main: error raised in interactive mode
} -constraints [list exec] -body {
exec [interpreter] << {error foo} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "foo\n"
test Tcl_Main-5.6 {
Tcl_Main: interactive mode: errors don't stop command loop
} -constraints [list exec] -body {
exec [interpreter] << {
error foo
puts bar
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "foo\nbar\n"
test Tcl_Main-5.7 {
Tcl_Main: interactive mode: closed stderr
} -constraints [list exec] -body {
exec [interpreter] << {
close stderr
error foo
puts bar
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "bar\n"
test Tcl_Main-5.8 {
Tcl_Main: interactive mode: close stdin
-> main loop & [exit] & exit handlers
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
testsetmainloop
testexitmainloop
testexithandler create 0
close stdin
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-5.9 {
Tcl_Main: interactive mode: delete interp
-> main loop & exit handlers, but no [exit]
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
testsetmainloop
testexitmainloop
testexithandler create 0
testinterpdelete {}
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\neven 0\n"
test Tcl_Main-5.10 {
Tcl_Main: exit main loop in mid-interactive command
} -constraints [list exec Tcltest] -setup {
catch {set f [open "|[interpreter]" w+]}
catch {fconfigure $f -blocking 0}
} -body {
type $f "testsetmainloop
after 2000 testexitmainloop
puts \{1 2"
after 4000
type $f "3 4\}"
set code1 [catch {gets $f} line1]
set code2 [catch {gets $f} line2]
set code3 [catch {gets $f} line3]
list $code1 $line1 $code2 $line2 $code3 $line3
} -cleanup {
close $f
} -result [list 0 {Exit MainLoop} 0 {1 2} 0 {3 4}]
test Tcl_Main-5.11 {
Tcl_Main: EOF in interactive main loop
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
testexithandler create 0
after 0 testexitmainloop
testsetmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-5.12 {
Tcl_Main: close stdin in interactive main loop
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
testexithandler create 0
after 100 testexitmainloop
testsetmainloop
close stdin
puts "don't reach this"
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\nIn exit\neven 0\n"
# Tests Tcl_Main-6.*: interactive operations with prompts
test Tcl_Main-6.1 {
Tcl_Main: enable prompts with tcl_interactive
} -constraints [list exec] -body {
exec [interpreter] << {set tcl_interactive 1} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% "
test Tcl_Main-6.2 {
Tcl_Main: prompt deletes interp
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
set tcl_prompt1 {testinterpdelete {}}
set tcl_interactive 1
puts "not reached"
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n"
test Tcl_Main-6.3 {
Tcl_Main: prompt closes stdin
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_prompt1 {close stdin}
set tcl_interactive 1
puts "not reached"
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n"
test Tcl_Main-6.4 {
Tcl_Main: interactive output, closed stdout
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_interactive 1
close stdout
set a NO
puts stderr YES
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% YES\n"
test Tcl_Main-6.5 {
Tcl_Main: interactive entry to main loop
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
set tcl_interactive 1
testsetmainloop
testexitmainloop} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% % % Exit MainLoop\n"
test Tcl_Main-6.6 {
Tcl_Main: number of prompts during stdin close exit
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_interactive 1
close stdin} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% "
# Tests Tcl_Main-7.*: exiting
test Tcl_Main-7.1 {
Tcl_Main: [exit] defined as no-op -> still have exithandlers
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
proc exit args {}
testexithandler create 0
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "even 0\n"
test Tcl_Main-7.2 {
Tcl_Main: [exit] defined as no-op -> still have exithandlers
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
proc exit args {}
testexithandler create 0
after 0 testexitmainloop
testsetmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\neven 0\n"
# Tests Tcl_Main-8.*: StdinProc operations
test Tcl_Main-8.1 {
StdinProc: handles non-blocking stdin
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
fconfigure stdin -blocking 0
testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\n"
test Tcl_Main-8.2 {
StdinProc: handles stdin EOF
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
testexithandler create 0
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
after 100 testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\nIn exit\neven 0\n"
test Tcl_Main-8.3 {
StdinProc: handles interactive stdin EOF
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
testexithandler create 0
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
set tcl_interactive 1} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% even 0\n"
test Tcl_Main-8.4 {
StdinProc: handles stdin close
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
after 100 testexitmainloop
after 0 puts 1
close stdin
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\nExit MainLoop\nIn exit\n"
test Tcl_Main-8.5 {
StdinProc: handles interactive stdin close
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
set tcl_interactive 1
rename exit _exit
proc exit code {
puts "In exit"
_exit $code
}
after 100 testexitmainloop
after 0 puts 1
close stdin
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% % % after#0\n% after#1\n% 1\nExit MainLoop\nIn exit\n"
test Tcl_Main-8.6 {
StdinProc: handles event loop re-entry
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
after 100 {puts 1; set delay 1}
vwait delay
puts 2
testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n2\nExit MainLoop\n"
test Tcl_Main-8.7 {
StdinProc: handling of errors
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
error foo
testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "foo\nExit MainLoop\n"
test Tcl_Main-8.8 {
StdinProc: handling of errors, closed stderr
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
close stderr
error foo
testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "Exit MainLoop\n"
test Tcl_Main-8.9 {
StdinProc: interactive output
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
set tcl_interactive 1
testexitmainloop} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% % Exit MainLoop\n"
test Tcl_Main-8.10 {
StdinProc: interactive output, closed stdout
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
close stdout
set tcl_interactive 1
testexitmainloop
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result {}
test Tcl_Main-8.11 {
StdinProc: prompt deletes interp
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
set tcl_prompt1 {testinterpdelete {}}
set tcl_interactive 1} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n"
test Tcl_Main-8.12 {
StdinProc: prompt closes stdin
} -constraints [list exec Tcltest] -body {
exec [interpreter] << {
testsetmainloop
set tcl_prompt1 {close stdin}
after 100 testexitmainloop
set tcl_interactive 1
puts "not reached"
} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\nExit MainLoop\n"
# Tests Tcl_Main-9.*: Prompt operations
test Tcl_Main-9.1 {
Prompt: custom prompt variables
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_prompt1 {puts -nonewline stdout "one "}
set tcl_prompt2 {puts -nonewline stdout "two "}
set tcl_interactive 1
puts {This is
a test}} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\none two This is\n\t\ta test\none "
test Tcl_Main-9.2 {
Prompt: error in custom prompt variables
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_prompt1 {error foo}
set tcl_interactive 1
set errorInfo} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\nfoo\n% foo\n while executing\n\"error foo\"\n (script\
that generates prompt)\nfoo\n% "
test Tcl_Main-9.3 {
Prompt: error in custom prompt variables, closed stderr
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_prompt1 {close stderr; error foo}
set tcl_interactive 1} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\n% "
test Tcl_Main-9.4 {
Prompt: error in custom prompt variables, closed stdout
} -constraints [list exec] -body {
exec [interpreter] << {
set tcl_prompt1 {close stdout; error foo}
set tcl_interactive 1} >& result
set f [open result]
read $f
} -cleanup {
close $f
file delete result
} -result "1\nfoo\n"
cleanupTests
}
namespace delete ::tcl::main::test
|