Artifact
3da397c4688680d27b56fc17f3623cee285469ded895c0cd78eaed63b9d0d445:
Attachment "exercise.tcl" to
ticket [77527e2f99]
added by
erikleunissen
2021-01-13 19:19:41.
(unpublished)
0000: 23 21 20 2f 62 69 6e 2f 73 68 0a 23 20 49 66 20 #! /bin/sh.# If
0010: 65 78 65 63 75 74 65 64 20 61 73 20 61 20 73 68 executed as a sh
0020: 65 6c 6c 20 73 63 72 69 70 74 2c 20 74 68 65 20 ell script, the
0030: 6e 65 78 74 20 6c 69 6e 65 20 72 65 70 6c 61 63 next line replac
0040: 65 73 20 74 68 65 20 73 68 65 6c 6c 20 5c 0a 65 es the shell \.e
0050: 78 65 63 20 74 63 6c 73 68 20 22 24 30 22 20 24 xec tclsh "$0" $
0060: 7b 31 2b 22 24 40 22 7d 0a 0a 73 65 74 20 4d 79 {1+"$@"}..set My
0070: 41 70 70 20 7b 0a 09 69 6e 74 65 72 70 20 63 72 App {..interp cr
0080: 65 61 74 65 20 63 68 69 6c 64 0a 09 70 72 6f 63 eate child..proc
0090: 20 73 6f 6d 65 50 72 6f 63 20 7b 7d 20 7b 0a 09 someProc {} {..
00a0: 09 63 68 69 6c 64 20 65 76 61 6c 20 7b 0a 09 09 .child eval {...
00b0: 09 70 75 74 73 20 22 48 69 20 66 72 6f 6d 20 63 .puts "Hi from c
00c0: 68 69 6c 64 2e 22 0a 09 09 09 70 75 74 73 20 73 hild."....puts s
00d0: 74 64 65 72 72 20 22 45 72 72 6f 72 20 6d 65 73 tderr "Error mes
00e0: 73 61 67 65 20 66 72 6f 6d 20 63 68 69 6c 64 2e sage from child.
00f0: 22 0a 09 09 7d 0a 09 7d 0a 7d 0a 0a 70 61 63 6b "...}..}.}..pack
0100: 61 67 65 20 72 65 71 75 69 72 65 20 74 63 6c 74 age require tclt
0110: 65 73 74 20 32 2e 32 0a 6e 61 6d 65 73 70 61 63 est 2.2.namespac
0120: 65 20 69 6d 70 6f 72 74 20 2d 66 6f 72 63 65 20 e import -force
0130: 3a 3a 74 63 6c 74 65 73 74 3a 3a 2a 0a 74 63 6c ::tcltest::*.tcl
0140: 74 65 73 74 3a 3a 63 6f 6e 66 69 67 75 72 65 20 test::configure
0150: 2d 76 65 72 62 6f 73 65 20 7b 62 6f 64 79 20 70 -verbose {body p
0160: 61 73 73 20 65 72 72 6f 72 7d 0a 0a 74 65 73 74 ass error}..test
0170: 20 73 6f 6d 65 50 72 6f 63 2d 31 2e 31 20 7b 63 someProc-1.1 {c
0180: 61 70 74 75 72 65 20 6f 75 74 70 75 74 20 66 72 apture output fr
0190: 6f 6d 20 63 68 69 6c 64 20 69 6e 74 65 72 70 7d om child interp}
01a0: 20 2d 73 65 74 75 70 20 7b 0a 09 65 76 61 6c 20 -setup {..eval
01b0: 24 4d 79 41 70 70 0a 7d 20 2d 62 6f 64 79 20 7b $MyApp.} -body {
01c0: 0a 09 73 6f 6d 65 50 72 6f 63 0a 7d 20 2d 72 65 ..someProc.} -re
01d0: 73 75 6c 74 20 7b 7d 20 2d 6f 75 74 70 75 74 20 sult {} -output
01e0: 22 48 69 20 66 72 6f 6d 20 63 68 69 6c 64 2e 5c "Hi from child.\
01f0: 6e 22 20 2d 65 72 72 6f 72 4f 75 74 70 75 74 20 n" -errorOutput
0200: 22 45 72 72 6f 72 20 6d 65 73 73 61 67 65 20 66 "Error message f
0210: 72 6f 6d 20 63 68 69 6c 64 2e 5c 6e 22 20 2d 63 rom child.\n" -c
0220: 6c 65 61 6e 75 70 20 7b 0a 09 69 6e 74 65 72 70 leanup {..interp
0230: 20 64 65 6c 65 74 65 20 63 68 69 6c 64 0a 7d 0a delete child.}.
0240: 74 63 6c 74 65 73 74 3a 3a 63 6c 65 61 6e 75 70 tcltest::cleanup
0250: 54 65 73 74 73 0a Tests.