1# Helper functions common to multiple regressions. 2 3set test_dir [file dirname [file normalize [info script]]] 4set result_dir [file join $test_dir "results"] 5 6proc make_result_file { filename } { 7 variable result_dir 8 if { ![file exists $result_dir] } { 9 file mkdir $result_dir 10 } 11 return [file join $result_dir $filename] 12} 13 14# puts [exec cat $file] without forking. 15proc report_file { file } { 16 set stream [open $file r] 17 18 while { [gets $stream line] >= 0 } { 19 puts $line 20 } 21 close $stream 22} 23 24proc diff_files { file1 file2 } { 25 set stream1 [open $file1 r] 26 set stream2 [open $file2 r] 27 28 set line 1 29 set diff_line 0; 30 while { [gets $stream1 line1] >= 0 && [gets $stream2 line2] >= 0 } { 31 if { $line1 != $line2 } { 32 set diff_line $line 33 break 34 } 35 incr line 36 } 37 close $stream1 38 close $stream2 39 40 if { $diff_line } { 41 puts "Differences found at line $diff_line." 42 puts "$line1" 43 puts "$line2" 44 return 1 45 } else { 46 puts "No differences found." 47 return 0 48 } 49} 50