home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / test / config / unix-octave.exp
Text File  |  1995-01-19  |  4KB  |  193 lines

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