Artifact
17625961d86a952e35c986fbacef5306dbc140350ca51809f636c6eb1ff127b8:
0000: 23 0a 23 20 4e 61 6d 65 3a 09 09 4d 61 6b 65 20 #.# Name:..Make
0010: 54 65 73 74 20 46 69 6c 65 73 20 46 72 6f 6d 20 Test Files From
0020: 43 53 56 20 46 69 6c 65 73 0a 23 20 56 65 72 73 CSV Files.# Vers
0030: 69 6f 6e 3a 09 30 2e 33 0a 23 20 44 61 74 65 3a ion:.0.3.# Date:
0040: 09 09 4d 61 72 63 68 20 39 2c 20 32 30 32 34 0a ..March 9, 2024.
0050: 23 20 41 75 74 68 6f 72 3a 09 42 72 69 61 6e 20 # Author:.Brian
0060: 4f 27 48 61 67 61 6e 0a 23 20 45 6d 61 69 6c 3a O'Hagan.# Email:
0070: 09 62 72 69 61 6e 31 39 39 40 63 6f 6d 63 61 73 .brian199@comcas
0080: 74 2e 6e 65 74 0a 23 20 4c 65 67 61 6c 20 4e 6f t.net.# Legal No
0090: 74 69 63 65 3a 09 28 63 29 20 43 6f 70 79 72 69 tice:.(c) Copyri
00a0: 67 68 74 20 32 30 32 30 20 62 79 20 42 72 69 61 ght 2020 by Bria
00b0: 6e 20 4f 27 48 61 67 61 6e 0a 23 09 09 52 65 6c n O'Hagan.#..Rel
00c0: 65 61 73 65 64 20 75 6e 64 65 72 20 74 68 65 20 eased under the
00d0: 41 70 61 63 68 65 20 76 32 2e 30 20 6c 69 63 65 Apache v2.0 lice
00e0: 6e 73 65 2e 20 49 20 77 6f 75 6c 64 20 61 70 70 nse. I would app
00f0: 72 65 63 69 61 74 65 20 61 20 63 6f 70 79 20 6f reciate a copy o
0100: 66 20 61 6e 79 20 6d 6f 64 69 66 69 63 61 74 69 f any modificati
0110: 6f 6e 73 0a 23 09 09 6d 61 64 65 20 74 6f 20 74 ons.#..made to t
0120: 68 69 73 20 70 61 63 6b 61 67 65 20 66 6f 72 20 his package for
0130: 70 6f 73 73 69 62 6c 65 20 69 6e 63 6f 72 70 6f possible incorpo
0140: 72 61 74 69 6f 6e 20 69 6e 20 61 20 66 75 74 75 ration in a futu
0150: 72 65 20 72 65 6c 65 61 73 65 2e 0a 23 0a 0a 23 re release..#..#
0160: 0a 23 20 50 61 72 73 65 20 43 53 56 20 6c 69 6e .# Parse CSV lin
0170: 65 0a 23 0a 70 72 6f 63 20 70 61 72 73 65 5f 63 e.#.proc parse_c
0180: 73 76 20 7b 63 68 20 64 61 74 61 7d 20 7b 0a 20 sv {ch data} {.
0190: 20 20 20 73 65 74 20 62 75 66 66 65 72 20 22 22 set buffer ""
01a0: 0a 20 20 20 20 73 65 74 20 72 65 73 75 6c 74 20 . set result
01b0: 5b 6c 69 73 74 5d 0a 20 20 20 20 73 65 74 20 73 [list]. set s
01c0: 74 61 72 74 20 30 0a 20 20 20 20 73 65 74 20 65 tart 0. set e
01d0: 6e 64 20 5b 73 74 72 69 6e 67 20 6c 65 6e 67 74 nd [string lengt
01e0: 68 20 24 64 61 74 61 5d 0a 0a 20 20 20 20 77 68 h $data].. wh
01f0: 69 6c 65 20 7b 24 73 74 61 72 74 20 3c 20 24 65 ile {$start < $e
0200: 6e 64 7d 20 7b 0a 09 69 66 20 7b 5b 73 74 72 69 nd} {..if {[stri
0210: 6e 67 20 69 6e 64 65 78 20 24 64 61 74 61 20 24 ng index $data $
0220: 73 74 61 72 74 5d 20 65 71 20 22 5c 22 22 7d 20 start] eq "\""}
0230: 7b 0a 09 20 20 20 20 23 20 51 75 6f 74 65 64 0a {.. # Quoted.
0240: 09 20 20 20 20 69 66 20 7b 5b 73 65 74 20 69 6e . if {[set in
0250: 64 65 78 20 5b 73 74 72 69 6e 67 20 66 69 72 73 dex [string firs
0260: 74 20 22 5c 22 22 20 24 64 61 74 61 20 5b 69 6e t "\"" $data [in
0270: 63 72 20 73 74 61 72 74 5d 5d 5d 20 3e 20 2d 31 cr start]]] > -1
0280: 7d 20 7b 0a 09 09 73 65 74 20 6e 65 78 74 20 5b } {...set next [
0290: 73 74 72 69 6e 67 20 69 6e 64 65 78 20 24 64 61 string index $da
02a0: 74 61 20 5b 65 78 70 72 20 7b 24 69 6e 64 65 78 ta [expr {$index
02b0: 20 2b 20 31 7d 5d 5d 0a 09 09 69 66 20 7b 24 6e + 1}]]...if {$n
02c0: 65 78 74 20 65 71 20 22 5c 22 22 7d 20 7b 0a 09 ext eq "\""} {..
02d0: 09 20 20 20 20 23 20 51 75 6f 74 65 0a 09 09 20 . # Quote...
02e0: 20 20 20 61 70 70 65 6e 64 20 62 75 66 66 65 72 append buffer
02f0: 20 5b 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 [string range $
0300: 64 61 74 61 20 24 73 74 61 72 74 20 24 69 6e 64 data $start $ind
0310: 65 78 5d 0a 09 09 20 20 20 20 73 65 74 20 73 74 ex]... set st
0320: 61 72 74 20 5b 69 6e 63 72 20 69 6e 64 65 78 5d art [incr index]
0330: 0a 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 20 ....} else {...
0340: 20 20 20 23 20 45 6e 64 20 6f 66 20 71 75 6f 74 # End of quot
0350: 65 64 20 64 61 74 61 0a 09 09 20 20 20 20 61 70 ed data... ap
0360: 70 65 6e 64 20 62 75 66 66 65 72 20 5b 73 74 72 pend buffer [str
0370: 69 6e 67 20 72 61 6e 67 65 20 24 64 61 74 61 20 ing range $data
0380: 24 73 74 61 72 74 20 5b 69 6e 63 72 20 69 6e 64 $start [incr ind
0390: 65 78 20 2d 31 5d 5d 0a 09 09 20 20 20 20 73 65 ex -1]]... se
03a0: 74 20 73 74 61 72 74 20 5b 69 6e 63 72 20 69 6e t start [incr in
03b0: 64 65 78 20 33 5d 0a 09 09 20 20 20 20 6c 61 70 dex 3]... lap
03c0: 70 65 6e 64 20 72 65 73 75 6c 74 20 24 62 75 66 pend result $buf
03d0: 66 65 72 0a 09 09 20 20 20 20 73 65 74 20 62 75 fer... set bu
03e0: 66 66 65 72 20 22 22 0a 09 09 7d 0a 0a 09 20 20 ffer ""...}...
03f0: 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 23 20 4d } else {...# M
0400: 75 6c 74 69 2d 6c 69 6e 65 0a 09 09 61 70 70 65 ulti-line...appe
0410: 6e 64 20 62 75 66 66 65 72 20 5b 73 74 72 69 6e nd buffer [strin
0420: 67 20 72 61 6e 67 65 20 24 64 61 74 61 20 24 73 g range $data $s
0430: 74 61 72 74 20 65 6e 64 5d 20 22 5c 6e 22 0a 09 tart end] "\n"..
0440: 09 67 65 74 73 20 24 63 68 20 6e 65 77 0a 09 09 .gets $ch new...
0450: 73 65 74 20 64 61 74 61 20 22 5c 22 22 0a 09 09 set data "\""...
0460: 61 70 70 65 6e 64 20 64 61 74 61 20 24 6e 65 77 append data $new
0470: 0a 09 09 73 65 74 20 73 74 61 72 74 20 30 0a 09 ...set start 0..
0480: 09 73 65 74 20 65 6e 64 20 5b 73 74 72 69 6e 67 .set end [string
0490: 20 6c 65 6e 67 74 68 20 24 64 61 74 61 5d 0a 09 length $data]..
04a0: 20 20 20 20 7d 0a 0a 09 7d 20 65 6c 73 65 20 7b }...} else {
04b0: 0a 09 20 20 20 20 23 20 4e 6f 74 20 71 75 6f 74 .. # Not quot
04c0: 65 64 2c 20 73 6f 20 6e 6f 20 65 6d 62 65 64 64 ed, so no embedd
04d0: 65 64 20 4e 4c 2c 20 71 75 6f 74 65 73 2c 20 6f ed NL, quotes, o
04e0: 72 20 63 6f 6d 6d 61 73 0a 09 20 20 20 20 73 65 r commas.. se
04f0: 74 20 69 6e 64 65 78 20 5b 73 74 72 69 6e 67 20 t index [string
0500: 66 69 72 73 74 20 22 2c 22 20 24 64 61 74 61 20 first "," $data
0510: 24 73 74 61 72 74 5d 0a 09 20 20 20 20 69 66 20 $start].. if
0520: 7b 24 69 6e 64 65 78 20 3e 20 2d 31 7d 20 7b 0a {$index > -1} {.
0530: 09 09 6c 61 70 70 65 6e 64 20 72 65 73 75 6c 74 ..lappend result
0540: 20 5b 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 [string range $
0550: 64 61 74 61 20 24 73 74 61 72 74 20 5b 69 6e 63 data $start [inc
0560: 72 20 69 6e 64 65 78 20 2d 31 5d 5d 0a 09 09 73 r index -1]]...s
0570: 65 74 20 73 74 61 72 74 20 5b 69 6e 63 72 20 69 et start [incr i
0580: 6e 64 65 78 20 32 5d 0a 09 20 20 20 20 7d 20 65 ndex 2].. } e
0590: 6c 73 65 20 7b 0a 09 09 6c 61 70 70 65 6e 64 20 lse {...lappend
05a0: 72 65 73 75 6c 74 20 5b 73 74 72 69 6e 67 20 72 result [string r
05b0: 61 6e 67 65 20 24 64 61 74 61 20 24 73 74 61 72 ange $data $star
05c0: 74 20 65 6e 64 5d 0a 09 09 73 65 74 20 73 74 61 t end]...set sta
05d0: 72 74 20 5b 73 74 72 69 6e 67 20 6c 65 6e 67 74 rt [string lengt
05e0: 68 20 24 64 61 74 61 5d 0a 09 20 20 20 20 7d 0a h $data].. }.
05f0: 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 .}. }. ret
0600: 75 72 6e 20 24 72 65 73 75 6c 74 0a 7d 0a 0a 23 urn $result.}..#
0610: 0a 23 20 43 6f 6e 76 65 72 74 20 74 65 73 74 20 .# Convert test
0620: 63 61 73 65 20 66 69 6c 65 20 69 6e 74 6f 20 74 case file into t
0630: 65 73 74 20 66 69 6c 65 73 0a 23 0a 70 72 6f 63 est files.#.proc
0640: 20 70 72 6f 63 65 73 73 5f 63 6f 6e 66 69 67 5f process_config_
0650: 66 69 6c 65 20 7b 66 69 6c 65 6e 61 6d 65 7d 20 file {filename}
0660: 7b 0a 20 20 20 20 73 65 74 20 70 72 65 76 20 22 {. set prev "
0670: 22 0a 20 20 20 20 73 65 74 20 74 65 73 74 20 30 ". set test 0
0680: 0a 0a 20 20 20 20 23 20 4f 70 65 6e 20 66 69 6c .. # Open fil
0690: 65 20 77 69 74 68 20 74 65 73 74 20 63 61 73 65 e with test case
06a0: 20 69 6e 64 6f 0a 20 20 20 20 73 65 74 20 69 6e indo. set in
06b0: 20 5b 6f 70 65 6e 20 24 66 69 6c 65 6e 61 6d 65 [open $filename
06c0: 20 72 5d 0a 20 20 20 20 61 72 72 61 79 20 73 65 r]. array se
06d0: 74 20 63 61 73 65 73 20 5b 6c 69 73 74 5d 0a 0a t cases [list]..
06e0: 20 20 20 20 23 20 4f 70 65 6e 20 6f 75 74 70 75 # Open outpu
06f0: 74 20 74 65 73 74 20 66 69 6c 65 0a 20 20 20 20 t test file.
0700: 73 65 74 20 6f 75 74 20 5b 6f 70 65 6e 20 5b 66 set out [open [f
0710: 6f 72 6d 61 74 20 25 73 2e 74 65 73 74 20 5b 66 ormat %s.test [f
0720: 69 6c 65 20 72 6f 6f 74 6e 61 6d 65 20 24 66 69 ile rootname $fi
0730: 6c 65 6e 61 6d 65 5d 5d 20 77 5d 0a 20 20 20 20 lename]] w].
0740: 66 63 6f 6e 66 69 67 75 72 65 20 24 6f 75 74 20 fconfigure $out
0750: 2d 65 6e 63 6f 64 69 6e 67 20 75 74 66 2d 38 20 -encoding utf-8
0760: 2d 74 72 61 6e 73 6c 61 74 69 6f 6e 20 7b 61 75 -translation {au
0770: 74 6f 20 6c 66 7d 0a 20 20 20 20 61 72 72 61 79 to lf}. array
0780: 20 73 65 74 20 63 61 73 65 73 20 5b 6c 69 73 74 set cases [list
0790: 5d 0a 0a 20 20 20 20 23 20 41 64 64 20 73 65 74 ].. # Add set
07a0: 75 70 20 63 6f 6d 6d 61 6e 64 73 20 74 6f 20 74 up commands to t
07b0: 65 73 74 20 66 69 6c 65 0a 20 20 20 20 70 75 74 est file. put
07c0: 73 20 24 6f 75 74 20 5b 66 6f 72 6d 61 74 20 22 s $out [format "
07d0: 23 20 41 75 74 6f 20 67 65 6e 65 72 61 74 65 64 # Auto generated
07e0: 20 74 65 73 74 20 63 61 73 65 73 20 66 6f 72 20 test cases for
07f0: 25 73 22 20 5b 66 69 6c 65 20 74 61 69 6c 20 24 %s" [file tail $
0800: 66 69 6c 65 6e 61 6d 65 5d 5d 0a 20 20 20 20 23 filename]]. #
0810: 70 75 74 73 20 24 6f 75 74 20 5b 66 6f 72 6d 61 puts $out [forma
0820: 74 20 22 23 20 41 75 74 6f 20 67 65 6e 65 72 61 t "# Auto genera
0830: 74 65 64 20 74 65 73 74 20 63 61 73 65 73 20 66 ted test cases f
0840: 6f 72 20 25 73 20 63 72 65 61 74 65 64 20 6f 6e or %s created on
0850: 20 25 73 22 20 5b 66 69 6c 65 20 74 61 69 6c 20 %s" [file tail
0860: 24 66 69 6c 65 6e 61 6d 65 5d 20 5b 63 6c 6f 63 $filename] [cloc
0870: 6b 20 66 6f 72 6d 61 74 20 5b 63 6c 6f 63 6b 20 k format [clock
0880: 73 65 63 6f 6e 64 73 5d 5d 5d 0a 0a 20 20 20 20 seconds]]]..
0890: 23 20 50 61 63 6b 61 67 65 20 72 65 71 75 69 72 # Package requir
08a0: 65 73 0a 20 20 20 20 70 75 74 73 20 24 6f 75 74 es. puts $out
08b0: 20 22 5c 6e 23 20 4c 6f 61 64 20 54 63 6c 20 54 "\n# Load Tcl T
08c0: 65 73 74 20 70 61 63 6b 61 67 65 22 0a 20 20 20 est package".
08d0: 20 70 75 74 73 20 24 6f 75 74 20 5b 73 75 62 73 puts $out [subs
08e0: 74 20 2d 6e 6f 63 6f 6d 6d 61 6e 64 73 20 7b 69 t -nocommands {i
08f0: 66 20 7b 5b 6c 73 65 61 72 63 68 20 5b 6e 61 6d f {[lsearch [nam
0900: 65 73 70 61 63 65 20 63 68 69 6c 64 72 65 6e 5d espace children]
0910: 20 3a 3a 74 63 6c 74 65 73 74 5d 20 3d 3d 20 2d ::tcltest] == -
0920: 31 7d 20 7b 5c 6e 5c 74 70 61 63 6b 61 67 65 20 1} {\n\tpackage
0930: 72 65 71 75 69 72 65 20 74 63 6c 74 65 73 74 5c require tcltest\
0940: 6e 5c 74 6e 61 6d 65 73 70 61 63 65 20 69 6d 70 n\tnamespace imp
0950: 6f 72 74 20 3a 3a 74 63 6c 74 65 73 74 3a 3a 2a ort ::tcltest::*
0960: 5c 6e 7d 5c 6e 7d 5d 0a 20 20 20 20 70 75 74 73 \n}\n}]. puts
0970: 20 24 6f 75 74 20 7b 73 65 74 20 61 75 74 6f 5f $out {set auto_
0980: 70 61 74 68 20 5b 63 6f 6e 63 61 74 20 5b 6c 69 path [concat [li
0990: 73 74 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 st [file dirname
09a0: 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 5b [file dirname [
09b0: 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d 5d 5d 20 info script]]]]
09c0: 24 61 75 74 6f 5f 70 61 74 68 5d 7d 0a 20 20 20 $auto_path]}.
09d0: 20 70 75 74 73 20 24 6f 75 74 20 22 22 0a 0a 20 puts $out ""..
09e0: 20 20 20 23 20 47 65 6e 65 72 61 74 65 20 74 65 # Generate te
09f0: 73 74 20 63 61 73 65 73 20 61 6e 64 20 61 64 64 st cases and add
0a00: 20 74 6f 20 74 65 73 74 20 66 69 6c 65 0a 20 20 to test file.
0a10: 20 20 77 68 69 6c 65 20 7b 5b 67 65 74 73 20 24 while {[gets $
0a20: 69 6e 20 64 61 74 61 5d 20 3e 20 2d 31 7d 20 7b in data] > -1} {
0a30: 0a 09 23 20 53 6b 69 70 20 63 6f 6d 6d 65 6e 74 ..# Skip comment
0a40: 73 0a 09 73 65 74 20 64 61 74 61 20 5b 73 74 72 s..set data [str
0a50: 69 6e 67 20 74 72 69 6d 20 24 64 61 74 61 5d 0a ing trim $data].
0a60: 09 69 66 20 7b 5b 73 74 72 69 6e 67 20 6d 61 74 .if {[string mat
0a70: 63 68 20 22 23 2a 22 20 24 64 61 74 61 5d 7d 20 ch "#*" $data]}
0a80: 63 6f 6e 74 69 6e 75 65 0a 09 23 20 53 70 6c 69 continue..# Spli
0a90: 74 20 63 6f 6d 6d 61 20 73 65 70 61 72 61 74 65 t comma separate
0aa0: 64 20 66 69 65 6c 64 73 20 77 69 74 68 20 71 75 d fields with qu
0ab0: 6f 74 65 73 0a 09 73 65 74 20 6c 69 73 74 20 5b otes..set list [
0ac0: 70 61 72 73 65 5f 63 73 76 20 24 69 6e 20 24 64 parse_csv $in $d
0ad0: 61 74 61 5d 0a 0a 09 23 20 47 65 74 20 63 6f 6d ata]...# Get com
0ae0: 6d 61 6e 64 20 6f 72 20 74 65 73 74 20 63 61 73 mand or test cas
0af0: 65 0a 09 66 6f 72 65 61 63 68 20 7b 67 72 6f 75 e..foreach {grou
0b00: 70 20 6e 61 6d 65 20 63 6f 6e 73 74 72 61 69 6e p name constrain
0b10: 74 73 20 73 65 74 75 70 20 62 6f 64 79 20 63 6c ts setup body cl
0b20: 65 61 6e 75 70 20 6d 61 74 63 68 20 72 65 73 75 eanup match resu
0b30: 6c 74 20 6f 75 74 70 75 74 20 65 72 72 6f 72 4f lt output errorO
0b40: 75 74 70 75 74 20 72 65 74 75 72 6e 43 6f 64 65 utput returnCode
0b50: 73 7d 20 24 6c 69 73 74 20 7b 0a 09 20 20 20 20 s} $list {..
0b60: 69 66 20 7b 24 67 72 6f 75 70 20 65 71 20 22 63 if {$group eq "c
0b70: 6f 6d 6d 61 6e 64 22 7d 20 7b 0a 09 09 70 75 74 ommand"} {...put
0b80: 73 20 24 6f 75 74 20 24 6e 61 6d 65 0a 0a 09 20 s $out $name...
0b90: 20 20 20 7d 20 65 6c 73 65 69 66 20 7b 24 67 72 } elseif {$gr
0ba0: 6f 75 70 20 6e 65 20 22 22 20 26 26 20 24 62 6f oup ne "" && $bo
0bb0: 64 79 20 6e 65 20 22 22 7d 20 7b 0a 09 09 73 65 dy ne ""} {...se
0bc0: 74 20 67 72 6f 75 70 20 5b 73 74 72 69 6e 67 20 t group [string
0bd0: 6d 61 70 20 5b 6c 69 73 74 20 22 20 22 20 22 5f map [list " " "_
0be0: 22 5d 20 24 67 72 6f 75 70 5d 0a 09 09 69 66 20 "] $group]...if
0bf0: 7b 24 67 72 6f 75 70 20 6e 65 20 24 70 72 65 76 {$group ne $prev
0c00: 7d 20 7b 0a 09 09 20 20 20 20 69 6e 63 72 20 74 } {... incr t
0c10: 65 73 74 0a 09 09 20 20 20 20 73 65 74 20 70 72 est... set pr
0c20: 65 76 20 24 67 72 6f 75 70 0a 09 09 20 20 20 20 ev $group...
0c30: 70 75 74 73 20 24 6f 75 74 20 22 22 0a 09 09 7d puts $out ""...}
0c40: 0a 0a 09 09 23 20 54 65 73 74 20 63 61 73 65 0a ....# Test case.
0c50: 09 09 69 66 20 7b 5b 73 74 72 69 6e 67 20 69 6e ..if {[string in
0c60: 64 65 78 20 24 6e 61 6d 65 20 30 5d 20 6e 65 20 dex $name 0] ne
0c70: 7b 24 7d 7d 20 7b 0a 09 09 20 20 20 20 73 65 74 {$}} {... set
0c80: 20 62 75 66 66 65 72 20 5b 66 6f 72 6d 61 74 20 buffer [format
0c90: 22 5c 6e 74 65 73 74 20 25 73 2d 25 64 2e 25 64 "\ntest %s-%d.%d
0ca0: 20 7b 25 73 7d 22 20 24 67 72 6f 75 70 20 24 74 {%s}" $group $t
0cb0: 65 73 74 20 5b 69 6e 63 72 20 63 61 73 65 73 28 est [incr cases(
0cc0: 24 67 72 6f 75 70 29 5d 20 24 6e 61 6d 65 5d 0a $group)] $name].
0cd0: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 20 20 20 ..} else {...
0ce0: 20 73 65 74 20 62 75 66 66 65 72 20 5b 66 6f 72 set buffer [for
0cf0: 6d 61 74 20 22 5c 6e 74 65 73 74 20 25 73 2d 25 mat "\ntest %s-%
0d00: 64 2e 25 64 20 25 73 22 20 24 67 72 6f 75 70 20 d.%d %s" $group
0d10: 24 74 65 73 74 20 5b 69 6e 63 72 20 63 61 73 65 $test [incr case
0d20: 73 28 24 67 72 6f 75 70 29 5d 20 24 6e 61 6d 65 s($group)] $name
0d30: 5d 0a 09 09 7d 0a 0a 09 09 66 6f 72 65 61 63 68 ]...}....foreach
0d40: 20 6f 70 74 20 5b 6c 69 73 74 20 2d 63 6f 6e 73 opt [list -cons
0d50: 74 72 61 69 6e 74 73 20 2d 73 65 74 75 70 20 2d traints -setup -
0d60: 62 6f 64 79 20 2d 63 6c 65 61 6e 75 70 20 2d 6d body -cleanup -m
0d70: 61 74 63 68 20 2d 72 65 73 75 6c 74 20 2d 6f 75 atch -result -ou
0d80: 74 70 75 74 20 2d 65 72 72 6f 72 4f 75 74 70 75 tput -errorOutpu
0d90: 74 20 2d 72 65 74 75 72 6e 43 6f 64 65 73 5d 20 t -returnCodes]
0da0: 7b 0a 09 09 20 20 20 20 73 65 74 20 63 6d 64 20 {... set cmd
0db0: 5b 73 74 72 69 6e 67 20 74 72 69 6d 20 5b 73 65 [string trim [se
0dc0: 74 20 5b 73 74 72 69 6e 67 20 74 72 69 6d 6c 65 t [string trimle
0dd0: 66 74 20 24 6f 70 74 20 22 2d 22 5d 5d 5d 0a 09 ft $opt "-"]]]..
0de0: 09 20 20 20 20 69 66 20 7b 24 63 6d 64 20 6e 65 . if {$cmd ne
0df0: 20 22 22 7d 20 7b 0a 09 09 09 69 66 20 7b 24 6f ""} {....if {$o
0e00: 70 74 20 69 6e 20 5b 6c 69 73 74 20 2d 73 65 74 pt in [list -set
0e10: 75 70 20 2d 62 6f 64 79 20 2d 63 6c 65 61 6e 75 up -body -cleanu
0e20: 70 5d 7d 20 7b 0a 09 09 09 20 20 20 20 61 70 70 p]} {.... app
0e30: 65 6e 64 20 62 75 66 66 65 72 20 22 20 22 20 24 end buffer " " $
0e40: 6f 70 74 20 22 20 5c 7b 5c 6e 22 0a 09 09 09 20 opt " \{\n"....
0e50: 20 20 20 66 6f 72 65 61 63 68 20 6c 69 6e 65 20 foreach line
0e60: 5b 73 70 6c 69 74 20 24 63 6d 64 20 22 3b 22 5d [split $cmd ";"]
0e70: 20 7b 0a 09 09 09 09 61 70 70 65 6e 64 20 62 75 {.....append bu
0e80: 66 66 65 72 20 5c 74 20 5b 73 74 72 69 6e 67 20 ffer \t [string
0e90: 74 72 69 6d 20 24 6c 69 6e 65 5d 20 5c 6e 0a 09 trim $line] \n..
0ea0: 09 09 20 20 20 20 7d 0a 09 09 09 20 20 20 20 61 .. }.... a
0eb0: 70 70 65 6e 64 20 62 75 66 66 65 72 20 22 20 20 ppend buffer "
0ec0: 20 20 5c 7d 22 0a 09 09 09 7d 20 65 6c 73 65 69 \}"....} elsei
0ed0: 66 20 7b 24 6f 70 74 20 69 6e 20 5b 6c 69 73 74 f {$opt in [list
0ee0: 20 2d 6f 75 74 70 75 74 20 2d 65 72 72 6f 72 4f -output -errorO
0ef0: 75 74 70 75 74 5d 7d 20 7b 0a 09 09 09 20 20 20 utput]} {....
0f00: 20 61 70 70 65 6e 64 20 62 75 66 66 65 72 20 22 append buffer "
0f10: 20 22 20 24 6f 70 74 20 22 20 7b 22 20 24 63 6d " $opt " {" $cm
0f20: 64 20 5c 6e 20 22 7d 22 0a 09 09 09 7d 20 65 6c d \n "}"....} el
0f30: 73 65 69 66 20 7b 24 6f 70 74 20 69 6e 20 5b 6c seif {$opt in [l
0f40: 69 73 74 20 2d 72 65 73 75 6c 74 5d 7d 20 7b 0a ist -result]} {.
0f50: 09 09 09 20 20 20 20 69 66 20 7b 5b 73 74 72 69 ... if {[stri
0f60: 6e 67 20 69 6e 64 65 78 20 24 63 6d 64 20 30 5d ng index $cmd 0]
0f70: 20 69 6e 20 5b 6c 69 73 74 20 5c 5b 20 5c 22 20 in [list \[ \"
0f80: 5c 7b 20 5c 24 5d 7d 20 7b 0a 09 09 09 09 61 70 \{ \$]} {.....ap
0f90: 70 65 6e 64 20 62 75 66 66 65 72 20 22 20 22 20 pend buffer " "
0fa0: 24 6f 70 74 20 22 20 22 20 24 63 6d 64 0a 09 09 $opt " " $cmd...
0fb0: 09 20 20 20 20 7d 20 65 6c 73 65 69 66 20 7b 5b . } elseif {[
0fc0: 73 74 72 69 6e 67 20 6d 61 74 63 68 20 7b 2a 5b string match {*[
0fd0: 5c 5c 24 5d 2a 7d 20 24 63 6d 64 5d 7d 20 7b 0a \\$]*} $cmd]} {.
0fe0: 09 09 09 09 61 70 70 65 6e 64 20 62 75 66 66 65 ....append buffe
0ff0: 72 20 22 20 22 20 24 6f 70 74 20 22 20 5c 22 22 r " " $opt " \""
1000: 20 5b 73 74 72 69 6e 67 20 6d 61 70 20 5b 6c 69 [string map [li
1010: 73 74 20 5c 5c 5c 5c 5c 22 20 5c 5c 5c 22 5d 20 st \\\\\" \\\"]
1020: 5b 73 74 72 69 6e 67 20 6d 61 70 20 5b 6c 69 73 [string map [lis
1030: 74 20 5c 22 20 5c 5c 5c 22 20 5d 20 24 63 6d 64 t \" \\\" ] $cmd
1040: 5d 5d 20 22 5c 22 22 0a 09 09 09 20 20 20 20 7d ]] "\"".... }
1050: 20 65 6c 73 65 20 7b 0a 09 09 09 09 61 70 70 65 else {.....appe
1060: 6e 64 20 62 75 66 66 65 72 20 22 20 22 20 24 6f nd buffer " " $o
1070: 70 74 20 22 20 7b 22 20 24 63 6d 64 20 22 7d 22 pt " {" $cmd "}"
1080: 0a 09 09 09 20 20 20 20 7d 0a 09 09 09 7d 20 65 .... }....} e
1090: 6c 73 65 20 7b 0a 09 09 09 20 20 20 20 61 70 70 lse {.... app
10a0: 65 6e 64 20 62 75 66 66 65 72 20 22 20 22 20 24 end buffer " " $
10b0: 6f 70 74 20 22 20 7b 22 20 24 63 6d 64 20 22 7d opt " {" $cmd "}
10c0: 22 0a 09 09 09 7d 0a 09 09 20 20 20 20 7d 0a 09 "....}... }..
10d0: 09 7d 0a 09 09 70 75 74 73 20 24 6f 75 74 20 24 .}...puts $out $
10e0: 62 75 66 66 65 72 0a 0a 09 20 20 20 20 7d 20 65 buffer... } e
10f0: 6c 73 65 20 7b 0a 09 09 23 20 45 6d 70 74 79 20 lse {...# Empty
1100: 6c 69 6e 65 0a 09 09 70 75 74 73 20 24 6f 75 74 line...puts $out
1110: 20 22 22 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 "".. }..
1120: 62 72 65 61 6b 0a 09 7d 0a 20 20 20 20 7d 0a 0a break..}. }..
1130: 20 20 20 20 23 20 4f 75 74 70 75 74 20 63 6c 65 # Output cle
1140: 61 6e 2d 75 70 20 63 6f 6d 6d 61 6e 64 73 0a 20 an-up commands.
1150: 20 20 20 70 75 74 73 20 24 6f 75 74 20 22 5c 6e puts $out "\n
1160: 23 20 43 6c 65 61 6e 75 70 5c 6e 3a 3a 74 63 6c # Cleanup\n::tcl
1170: 74 65 73 74 3a 3a 63 6c 65 61 6e 75 70 54 65 73 test::cleanupTes
1180: 74 73 5c 6e 72 65 74 75 72 6e 22 0a 20 20 20 20 ts\nreturn".
1190: 63 6c 6f 73 65 20 24 6f 75 74 0a 20 20 20 20 63 close $out. c
11a0: 6c 6f 73 65 20 24 69 6e 0a 7d 0a 0a 23 0a 23 20 lose $in.}..#.#
11b0: 43 61 6c 6c 20 73 63 72 69 70 74 0a 23 0a 66 6f Call script.#.fo
11c0: 72 65 61 63 68 20 66 69 6c 65 20 5b 67 6c 6f 62 reach file [glob
11d0: 20 2a 2e 63 73 76 5d 20 7b 0a 70 75 74 73 20 24 *.csv] {.puts $
11e0: 66 69 6c 65 0a 20 20 20 20 70 72 6f 63 65 73 73 file. process
11f0: 5f 63 6f 6e 66 69 67 5f 66 69 6c 65 20 24 66 69 _config_file $fi
1200: 6c 65 0a 7d 0a 65 78 69 74 0a le.}.exit.