home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d009_2 / 1.ddi / SAMPLES / TSTSUITE / DRIVER.MS$ / DRIVER.bin
Encoding:
Text File  |  1992-02-03  |  6.5 KB  |  202 lines

  1. '******************************** DRIVER.MST  *********************************
  2. 'Demonstrates: A sample test suite driver script - uses File list processing,
  3. '              error trapping, and transaction logging.
  4. '
  5. 'Required Files: TESTDRVR.EXE
  6. '
  7. 'Uses: TESTDRVR.EXE
  8. '
  9. 'Complexity Level: INTERMEDIATE
  10. '
  11. 'Notes:  Assumes one or more sub-directories containing test scripts exist.
  12. '        The directory layout for this sample is:
  13. '
  14. '           TSTSUITE            -   DRIVER.MST, TSTSUITE.INC, and log file.
  15. '           TSTSUITE\EDIT       -   EDITMENU.MST, result file.
  16. '           TSTSUITE\FILE       -   FILEMENU.MST, result file.
  17. '           TSTSUITE\SRCH       -   SRCHMENU.MST, result file.
  18. '
  19. '       Writes log data to LOG_FILE.  Individual test scripts run from the
  20. '       driver will write detailed results to a result file in their directory.
  21. '******************************************************************************
  22.  
  23. Declare Function GetSubDirs() As Integer
  24. Declare Sub RunScripts(targetDir$)
  25. Declare Sub BackUpLogFile()
  26. Declare Sub PrintLogHeader()
  27. Declare SUb PrintLogFooter()
  28.  
  29. '******************************************************************************
  30. ' CONSTs
  31. '******************************************************************************
  32.  
  33. '  Directory / File constants
  34. Const MAX_DIRS = 3              'Number of sub directories to use
  35. Const PROG_NAME = "TESTDRVR "   'Name of MSTest executable
  36. Const PARENT_DIR = ".."         'Name of the parent directory
  37. Const PARAMS = " /RUN"
  38. Const LOG_FILE = "TSTSUITE.LOG"
  39. Const BACKUP_FILE = "TSTSUITE.BAK"
  40.  
  41. Global dirNames$(MAX_DIRS)      'Array of sub-directories
  42. Global currentTest$             'Name of currently running script
  43.  
  44.  
  45. '******************************************************************************
  46. ' Main program code
  47. '******************************************************************************
  48.  
  49. On Error Goto ErrorTrap
  50.  
  51. ' Initialize log file
  52. BackUpLogFile
  53. PrintLogHeader
  54.  
  55. '  Run scripts in each sub-directory
  56. numDirs = GetSubDirs
  57. For i = 0 To numDirs - 1
  58.    currentDir$ = DirNames$(i)
  59.    RunScripts currentDir$
  60. Next
  61.  
  62. '  Close log file
  63. PrintLogFooter
  64. Close
  65. End
  66.  
  67. '******************************************************************************
  68. ' TRAPS
  69. '******************************************************************************
  70.  
  71. ErrorTrap:
  72.     If Exists(LOG_FILE) Then
  73.       OPEN LOG_FILE For Append As #1
  74.     Else
  75.       Open PARENT_DIR + "\" + LOG_FILE For Append As #1
  76.     End If
  77.     Print #1, "Driver: A Testdriver run-time error occurred at line "; ERL
  78.     Print #1, "Error #"; ERR; " "; ERROR$
  79.     Close
  80.     End
  81.  
  82. Trap UAETrap From "TESTDRVR.EXE"
  83.     If Exists(LOG_FILE) Then
  84.       OPEN LOG_FILE For Append As #1
  85.     Else
  86.       Open PARENT_DIR + "\" + LOG_FILE For Append As #1
  87.     End If
  88.     Print #1, "*** Driver: Testdriver UAE occurred"
  89.     Print #1, "    testing terminated"
  90.     Close
  91. End Trap
  92.  
  93.  
  94. '******************************************************************************
  95. ' SUBs and FUNCTIONs
  96. '******************************************************************************
  97.  
  98.  
  99. '******************************************************************************
  100. 'SUB BackUpLogFile saves the last log file (if it exists).  If
  101. 'a backup log file already exists, it is deleted and replaced
  102. 'with the new backup.
  103. '******************************************************************************
  104. Sub BackUpLogFile Static
  105.  
  106.   IF Exists(LOG_FILE) THEN
  107.     IF Exists(BACKUP_FILE) THEN
  108.       Kill BACKUP_FILE
  109.     End If
  110.     Name LOG_FILE AS BACKUP_FILE
  111.   END IF
  112.  
  113. End Sub
  114.  
  115.  
  116. '******************************************************************************
  117. 'SUB PrintLogHeader prints a starting banner to the log file
  118. '******************************************************************************
  119. Sub PrintLogHeader () Static
  120.   Open LOG_FILE For Append As #1
  121.  
  122.   Print #1, "*******************************************************************************"
  123.   Print #1, "*                        MSTest Sample log file                               *"
  124.   Print #1, "*                          "; DateTime$; "                                  *"
  125.   Print #1, "*                                                                             *"
  126.   Print #1, "*******************************************************************************"
  127.  
  128.   Close
  129. End Sub
  130.  
  131.  
  132. '******************************************************************************
  133. 'SUB PrintLogFooter prints an ending banner to the log file
  134. '******************************************************************************
  135. Sub PrintLogFooter () Static
  136.   Open LOG_FILE For Append As #1
  137.  
  138.   Print #1, "*******************************************************************************"
  139.   Print #1, "*                         Sample test complete                                *"
  140.   Print #1, "*                           "; DateTime$; "                                 *"
  141.   Print #1, "*******************************************************************************"
  142.  
  143.   Close
  144. End Sub
  145.  
  146.  
  147. '******************************************************************************
  148. ' FUNCTION GetSubDirs reads the names of the sub-directories which contain
  149. ' test scripts to be run from the file "testdirs.dat" into the array
  150. ' dirNames$() and returns an integer value which indicates the number of
  151. ' script sub-directories in the array
  152. '******************************************************************************
  153. Function GetSubDirs() Static As Integer
  154.  
  155.     Dim count as integer
  156.  
  157.     Open "testdirs.dat" For Input As #1
  158.  
  159.     While Not Eof(1) And count < MAX_DIRS
  160.       Line Input #1, a$
  161.       a$ = Ucase$(Ltrim$(Rtrim$(a$)))
  162.       If a$ <> "" Then
  163.         dirNames$(count) = Mid$(a$,1,12)
  164.         count = count + 1
  165.       End If
  166.     Wend
  167.  
  168.     Close #1
  169.  
  170.     GetSubDirs = count
  171.  
  172. End Function
  173.  
  174.  
  175. '******************************************************************************
  176. ' SUB RunScripts executes the test script files (those with a .MST
  177. ' extension) in the sub-directory specified by the currentDir$ parameter.
  178. '******************************************************************************
  179. Sub RunScripts (currentDir$) Static
  180.  
  181.     Chdir CurrentDir$
  182.  
  183.     Clearlist
  184.     Setfile "*.mst", On
  185.  
  186.     For currentTest$ In Filelist
  187.  
  188.       '  Log start of new script
  189.       Open PARENT_DIR + "\" + LOG_FILE For Append As #1
  190.       Print #1, "Running script: "; currentTest$
  191.       Close
  192.  
  193.       Run PROG_NAME + currentTest$ + PARAMS
  194.     NEXT
  195.  
  196.     Chdir PARENT_DIR
  197.  
  198. END SUB
  199.  
  200.  
  201.  
  202.