|
| 1 | +proc normalize_output {output} { |
| 2 | + # Remove leading newline for cleaner multiline string formatting |
| 3 | + regsub {^\n} $output "" result |
| 4 | + # Convert Unix line endings to Windows-style line endings for expect matching |
| 5 | + regsub -all {\n} $result "\r\n" result |
| 6 | + return $result |
| 7 | +} |
| 8 | + |
| 9 | +proc show_diff {expected actual} { |
| 10 | + puts stderr "\n=== DIFF OUTPUT ===" |
| 11 | + puts stderr "Expected:" |
| 12 | + puts stderr [repr_string $expected] |
| 13 | + puts stderr "\nActual:" |
| 14 | + puts stderr [repr_string $actual] |
| 15 | + |
| 16 | + # Line-by-line comparison |
| 17 | + set exp_lines [split $expected "\r\n"] |
| 18 | + set act_lines [split $actual "\r\n"] |
| 19 | + set max_lines [expr {max([llength $exp_lines], [llength $act_lines])}] |
| 20 | + |
| 21 | + puts stderr "\nLine-by-line comparison:" |
| 22 | + for {set i 0} {$i < $max_lines} {incr i} { |
| 23 | + set exp_line [lindex $exp_lines $i] |
| 24 | + set act_line [lindex $act_lines $i] |
| 25 | + |
| 26 | + if {$exp_line ne $act_line} { |
| 27 | + puts stderr "Line [expr {$i + 1}] differs:" |
| 28 | + puts stderr " Expected: [repr_string $exp_line]" |
| 29 | + puts stderr " Actual: [repr_string $act_line]" |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +proc repr_string {str} { |
| 35 | + # Show invisible characters |
| 36 | + regsub -all {\r} $str "\\r" result |
| 37 | + regsub -all {\n} $result "\\n" result |
| 38 | + regsub -all {\t} $result "\\t" result |
| 39 | + return "\"$result\"" |
| 40 | +} |
| 41 | + |
| 42 | +proc expect_with_diff {expected_output} { |
| 43 | + expect { |
| 44 | + $expected_output { |
| 45 | + expect eof { |
| 46 | + check_exit_and_segfault |
| 47 | + } |
| 48 | + } |
| 49 | + eof { |
| 50 | + show_diff $expected_output $expect_out(buffer) |
| 51 | + puts stderr "\nExpect script failed: output was different from expected value." |
| 52 | + exit 1 |
| 53 | + } |
| 54 | + timeout { |
| 55 | + puts stderr "\nExpect script failed: timeout waiting for expected output." |
| 56 | + puts stderr "Partial output received:" |
| 57 | + puts stderr [repr_string $expect_out(buffer)] |
| 58 | + exit 1 |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
1 | 63 | proc check_exit_and_segfault {} { |
2 | 64 | set status [wait] |
3 | 65 | set exit_code [lindex $status 2] |
|
0 commit comments