1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
# Some global definitions.
if ![info exists prompt] then {
set prompt "octave:\[0-9\]*> "
}
if ![info exists nl] then {
set nl "(\[\r\n\])*"
}
if ![info exists d] then {
set d "\[0-9\]*"
}
if ![info exists dp] then {
set dp "\.*"
}
if ![info exists resync] then {
set resync ".*$prompt$"
}
# octave_version -- extract and print the version number of octave
proc octave_version {} {
global OCTAVE
set tmp [exec $OCTAVE -v]
regexp "version.*$" $tmp version
clone_output "[which $OCTAVE] $version\n"
unset tmp
unset version
}
# octave_load -- loads the program
proc octave_load { arg } { }
# octave_exit -- quit and cleanup
proc octave_exit { } { }
# Start Octave for an interactive test.
proc octave_interactive_start { } {
global OCTAVE
global OCTAVE_SCRIPT_PATH
global prompt
global nl
global resync
global spawn_id
global verbose
global timeout
if { $verbose > 1 } {
send_user "starting $OCTAVE\n"
}
# It might take a long time to start Octave, but we shouldn't leave
# the timeout period at a minute for the real tests.
set timeout 60
if [ llength $OCTAVE_SCRIPT_PATH ] {
spawn $OCTAVE -f -q -p $OCTAVE_SCRIPT_PATH
} else {
spawn $OCTAVE -f -q
}
set timeout 5
expect {
-re "No such file.*" { error "Can't start $OCTAVE"; exit 1 }
-re "$resync" { }
timeout { error "Failed to spawn $OCTAVE (timeout)"; exit 1 }
}
# Expectations that are checked before and after those explicitly
# specified in each expect block. Note that `$test' is a purely local
# variable. Leaving one of these empty will screw us.
# expect_before {
# }
expect_after {
-re "usage:.*$prompt$" { fail "$test (usage)" }
-re "warning:.*$prompt$" { fail "$test (warning)" }
-re "parse error:.*$prompt$" { fail "$test (parse error)" }
-re "error:.*$prompt$" { fail "$test (error)" }
timeout { fail "$test (timeout)" }
}
# Always turn off paging!
send "page_screen_output = \"false\";\n"
expect {
-re "$resync" { }
}
}
# Stop an interactive Octave session.
proc octave_interactive_stop { } {
send "quit\n"
expect {
-re ".*$" { }
}
}
# Start Octave for a single non-interactive test.
proc octave_start { src_file } {
global OCTAVE
global OCTAVE_SCRIPT_PATH
global oct_output
set OSPATH $OCTAVE_SCRIPT_PATH
if ![info exists OSPATH] then {
set OSPATH ""
}
# Can't seem to get 2>&1 to work without using /bin/sh -c ""...
send_log "EXEC: $OCTAVE -f -q -p $OSPATH $src_file\n"
catch "exec /bin/sh -c \"$OCTAVE -f -q -p $OSPATH $src_file 2>&1\"" oct_output
}
# do_test -- run a test given by the file $src_code.
proc do_test { src_code } {
global OCTAVE
global OCTAVE_SCRIPT_PATH
global srcdir
global subdir
global spawn_id
global verbose
global timeout
global prog_output
global oct_output
if { $verbose > 1 } {
send_user "starting $OCTAVE\n"
}
# Reset some variables
set oct_output ""
set pass_message $subdir/$src_code
set fail_message $subdir/$src_code
set pass no
# Since we are starting up a fresh Octave for nearly every test, use a
# fairly large timeout value.
set timeout 60
# Run the test
octave_start $srcdir/$subdir/$src_code
# Check for expected output.
if { $verbose > 1 } {
send_user "\nChecking:\n$oct_output\nto see if it matches:\n$prog_output\n"
} else {
send_log "\nOctave Output:\n$oct_output\n"
}
if [regexp $prog_output $oct_output] then {
if { $verbose > 1 } {
send_user "Yes, it matches.\n\n"
}
set pass yes
} else {
if { $verbose > 1 } {
send_user "Nope, it does not match.\n\n"
}
}
if [string match $pass "yes"] then {
pass $pass_message
} else {
fail $fail_message
}
uplevel {
if [info exists errorInfo] then {
unset errorInfo
}
}
}
|