Annotation For example/main.tcl

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

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