Annotation For example/main.tcl

Origin for each line in example/main.tcl from check-in fa71466879:

5583d77f1c 2019-09-14    1: set dir  "//xvfs:/example"
5583d77f1c 2019-09-14    2: set dirNative  [file join [pwd] example]
fa71466879 2019-09-14    3: #set dir $dirNative
5583d77f1c 2019-09-14    4: set file "${dir}/foo"
7d74392642 2019-09-13    5: 
7d74392642 2019-09-13    6: set fd [open $file]
38bed7cee0 2019-09-13    7: seek $fd 0 end
38bed7cee0 2019-09-13    8: seek $fd -1 current
38bed7cee0 2019-09-13    9: set check [read $fd 1]
38bed7cee0 2019-09-13   10: if {$check != "\n"} {
38bed7cee0 2019-09-13   11: 	error "EXPECTED: (new line); GOT: [binary encode hex $check]"
7d74392642 2019-09-13   12: }
7d74392642 2019-09-13   13: close $fd
7d74392642 2019-09-13   14: 
7d74392642 2019-09-13   15: set fd1 [open $file]
7d74392642 2019-09-13   16: set fd2 [open $file]
7d74392642 2019-09-13   17: set data1 [read $fd1]
7d74392642 2019-09-13   18: close $fd1
7d74392642 2019-09-13   19: set data2 [read $fd2]
7d74392642 2019-09-13   20: close $fd2
7d74392642 2019-09-13   21: if {$data1 != $data2} {
7d74392642 2019-09-13   22: 	error "EXPECTED match, differs"
7d74392642 2019-09-13   23: }
7d74392642 2019-09-13   24: 
7d74392642 2019-09-13   25: set fd [open $file]
7d74392642 2019-09-13   26: seek $fd 0 end
7d74392642 2019-09-13   27: set size [tell $fd]
7d74392642 2019-09-13   28: close $fd
7d74392642 2019-09-13   29: set fd [open $file]
7d74392642 2019-09-13   30: set done false
7d74392642 2019-09-13   31: set calls 0
7d74392642 2019-09-13   32: set output ""
7d74392642 2019-09-13   33: fileevent $fd readable [list apply {{fd} {
7d74392642 2019-09-13   34: 	set pos [tell $fd]
7d74392642 2019-09-13   35: 	set x [read $fd 1]
7d74392642 2019-09-13   36: 	if {[string length $x] == 0} {
7d74392642 2019-09-13   37: 		set ::done true
7d74392642 2019-09-13   38: 		fileevent $fd readable ""
7d74392642 2019-09-13   39: 	}
7d74392642 2019-09-13   40: 
7d74392642 2019-09-13   41: 	lappend ::output $pos
7d74392642 2019-09-13   42: 	incr ::calls
7d74392642 2019-09-13   43: }} $fd]
7d74392642 2019-09-13   44: vwait done
7d74392642 2019-09-13   45: if {$calls != ($size + 1)} {
7d74392642 2019-09-13   46: 	error "EXPECTED [expr {$size + 1}], got $calls"
7d74392642 2019-09-13   47: }
7d74392642 2019-09-13   48: if {[lsort -integer $output] != $output} {
7d74392642 2019-09-13   49: 	error "EXPECTED [lsort -integer $output], GOT $output"
aa08a4a749 2019-09-14   50: }
aa08a4a749 2019-09-14   51: close $fd
aa08a4a749 2019-09-14   52: update idle
5583d77f1c 2019-09-14   53: 
5583d77f1c 2019-09-14   54: 
5583d77f1c 2019-09-14   55: proc glob_verify {args} {
5583d77f1c 2019-09-14   56: 	set rv [glob -nocomplain -directory $::dir {*}$args]
5583d77f1c 2019-09-14   57: 	set verify [glob -nocomplain -directory $::dirNative {*}$args]
5583d77f1c 2019-09-14   58: 
5583d77f1c 2019-09-14   59: 	if {[llength $rv] != [llength $verify]} {
5583d77f1c 2019-09-14   60: 		error "VERIFY FAILED: glob ... $args ($rv versus $verify)"
5583d77f1c 2019-09-14   61: 	}
5583d77f1c 2019-09-14   62: 
5583d77f1c 2019-09-14   63: 	return $rv
5583d77f1c 2019-09-14   64: }
5583d77f1c 2019-09-14   65: 
5583d77f1c 2019-09-14   66: set check [glob_verify *]
5583d77f1c 2019-09-14   67: if {[llength $check] < 2} {
5583d77f1c 2019-09-14   68: 	error "EXPECTED >=2, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   69: }
5583d77f1c 2019-09-14   70: 
5583d77f1c 2019-09-14   71: set check [glob_verify f*]
5583d77f1c 2019-09-14   72: if {[llength $check] != 1} {
5583d77f1c 2019-09-14   73: 	error "EXPECTED 1, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   74: }
5583d77f1c 2019-09-14   75: 
5583d77f1c 2019-09-14   76: set check [glob_verify ./f*]
5583d77f1c 2019-09-14   77: if {[llength $check] != 1} {
5583d77f1c 2019-09-14   78: 	error "EXPECTED 1, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   79: }
5583d77f1c 2019-09-14   80: 
5583d77f1c 2019-09-14   81: set check [glob_verify -type f ./f*]
5583d77f1c 2019-09-14   82: if {[llength $check] != 1} {
5583d77f1c 2019-09-14   83: 	error "EXPECTED 1, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   84: }
5583d77f1c 2019-09-14   85: 
5583d77f1c 2019-09-14   86: set check [glob_verify -type d ./f*]
5583d77f1c 2019-09-14   87: if {[llength $check] != 0} {
5583d77f1c 2019-09-14   88: 	error "EXPECTED 0, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   89: }
5583d77f1c 2019-09-14   90: 
5583d77f1c 2019-09-14   91: set check [glob_verify x*]
5583d77f1c 2019-09-14   92: if {[llength $check] != 0} {
5583d77f1c 2019-09-14   93: 	error "EXPECTED 0, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   94: }
5583d77f1c 2019-09-14   95: 
5583d77f1c 2019-09-14   96: set check [glob_verify lib/*]
5583d77f1c 2019-09-14   97: if {[llength $check] != 1} {
5583d77f1c 2019-09-14   98: 	error "EXPECTED 1, GOT [llength $check] ($check)"
5583d77f1c 2019-09-14   99: }
5583d77f1c 2019-09-14  100: 
5583d77f1c 2019-09-14  101: set check [lindex $check 0]
5583d77f1c 2019-09-14  102: if {![string match $dir/* $check]} {
5583d77f1c 2019-09-14  103: 	error "EXPECTED \"$dir/*\", GOT $check"
5583d77f1c 2019-09-14  104: }
5583d77f1c 2019-09-14  105: 
5583d77f1c 2019-09-14  106: set check [glob_verify -type d *]
5583d77f1c 2019-09-14  107: if {[llength $check] != 1} {
5583d77f1c 2019-09-14  108: 	error "EXPECTED 1, GOT [llength $check] ($check)"
12ff77016f 2019-09-14  109: }
12ff77016f 2019-09-14  110: 
12ff77016f 2019-09-14  111: set check [glob_verify -type d lib/*]
12ff77016f 2019-09-14  112: if {[llength $check] != 1} {
12ff77016f 2019-09-14  113: 	error "EXPECTED 1, GOT [llength $check] ($check)"
12ff77016f 2019-09-14  114: }
12ff77016f 2019-09-14  115: 
12ff77016f 2019-09-14  116: cd $dir
12ff77016f 2019-09-14  117: cd lib
12ff77016f 2019-09-14  118: glob *
12ff77016f 2019-09-14  119: 
12ff77016f 2019-09-14  120: 
fa71466879 2019-09-14  121: # XXX:TODO:CURRENTLY BROKEN
fa71466879 2019-09-14  122: if {0} {
12ff77016f 2019-09-14  123: lappend auto_path ${dir}/lib
12ff77016f 2019-09-14  124: package require hello
fa71466879 2019-09-14  125: }
38bed7cee0 2019-09-13  126: 
38bed7cee0 2019-09-13  127: puts "ALL TESTS PASSED"