home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / dejagnu / util-defs.exp < prev    next >
Encoding:
Text File  |  1996-10-12  |  3.0 KB  |  108 lines

  1. #   Copyright (C) 1988, 1990, 1991, 1992 , 1993 Free Software Foundation, Inc.
  2.  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-dejagnu@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19.  
  20. #
  21. # util_test -- run a utility and test the result.
  22. #             Takes four parameters.
  23. #             Parameters:
  24. #                First one is the command line arguments
  25. #                Second one is the file name
  26. #                Third one is the regexp style pattern to match for a PASS,
  27. #             Returns:
  28. #                1 if the test failed,
  29. #                0 if the test passes,
  30. #               -1 if there was an internal error.
  31. #
  32. proc util_test { args } {
  33.     global verbose
  34.     # get the parameters
  35.     set cmd    [lindex $args 0]
  36.     verbose     "Utility to execute is $cmd" 2
  37.     set cmd_arg [lindex $args 1]
  38.     verbose     "Command line arguments are $cmd_arg" 2
  39.     set file    [lindex $args 2]
  40.     verbose     "The file name to use is $file" 2
  41.     set pattern [lindex $args 3]
  42.     verbose    "The pattern to match is \"$pattern\"" 2
  43.  
  44.     verbose "Looking to match \"$pattern\"" 1
  45.  
  46.     if [info exists file] then {
  47.     if ![string match "" $file] then {
  48.         if ![file exists $file] then {
  49.         perror "$file doesn't exist"
  50.         return -1
  51.         }
  52.     }
  53.     }
  54.  
  55. #
  56. # run the utility to be tested and analyze the results
  57. #
  58.     set comp_output [util_start $cmd $cmd_arg $file]
  59.  
  60.      if [regexp "$pattern" $comp_output] then {
  61.     return 0
  62.     }
  63.  
  64.     if [string match "" $comp_output] then {
  65.     return 1
  66.     } else {
  67.     if $verbose>=2 then {
  68.         verbose "$comp_output"
  69.     } else {
  70.         send_log "$comp_output\n"
  71.     }
  72.     }
  73.     return 1
  74. }
  75.  
  76. # util_start -- run the utility.
  77. #               return NULL or the output
  78. #
  79. proc util_start { args } {
  80.     set cmd    [lindex $args 0]
  81.     set cmd_arg [lindex $args 1]
  82.     set file    [lindex $args 2]
  83.  
  84.     if {[which $cmd] == 0} then {
  85.         perror "Can't find $cmd"
  86.     return ""
  87.     }
  88.  
  89.     verbose "Spawning \"$cmd $cmd_arg $file\""
  90.     catch "exec $cmd $cmd_arg $file" comp_output
  91.     if ![string match "" $comp_output] then {    
  92.         send_log "$comp_output\n"
  93.         verbose "$comp_output" 2
  94.     }
  95.     return $comp_output
  96. }
  97.  
  98. #
  99. # add some basic error trapping. These mostly catch programming error's
  100. # within the tests themselves
  101. #
  102. expect_before {
  103.     buffer_full           { error "Internal buffer is full" }
  104.     "can't open 'nmtest'" { error "Can't open test file" }
  105. }
  106.