- Timestamp:
- 06/18/07 22:47:37 (5 years ago)
- Files:
-
- 1 modified
-
trunk/mgunit/mguttestsuite__define.pro (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/mgunit/mguttestsuite__define.pro
r9 r12 12 12 return 13 13 endif 14 15 resolve_routine, testName + '__define'14 15 resolve_routine, classname + '__define' 16 16 end 17 17 … … 20 20 ; Create a new test case or test suite, but check for errors while creating 21 21 ; it. 22 ; 22 ; 23 23 ; @returns obj 24 24 ; @param testName {in}{required}{type=string} … … 31 31 function mguttestsuite::_makeTestCase, testName, error=error, _extra=e 32 32 compile_opt strictarr 33 33 34 34 error = 0L 35 35 catch, error … … 38 38 return, obj_new() 39 39 endif 40 40 41 41 self->_recompile, testName 42 42 43 43 return, obj_new(testName, test_runner=self.testRunner, _strict_extra=e) 44 44 end 45 45 46 46 47 ; 47 ; 48 48 ;+ 49 49 ; Run the contained test suites or test cases. … … 62 62 otestcase = self.testcases->get(position=t) 63 63 otestcase->run 64 64 65 65 ; accumulate results 66 66 otestcase->getProperty, npass=npass, nfail=nfail … … 79 79 ; 80 80 ; @param tests {in}{required}{type=strarr} classnames of test suites or test 81 ; cases 82 ; @keyword all {in}{optional}{type=boolean} set to add all the files in the 83 ; current directory that end in "_ut__define.pro" (the current 84 ; directory is defined to be the directory where the method that 81 ; cases 82 ; @keyword all {in}{optional}{type=boolean} set to add all the files in the 83 ; current directory that end in "_ut__define.pro" (the current 84 ; directory is defined to be the directory where the method that 85 85 ; calls this method is located) 86 86 ;- 87 87 pro mguttestsuite::add, tests, all=all 88 88 compile_opt strictarr 89 89 90 90 if (keyword_set(all)) then begin 91 91 ; first, add all the unit tests in the current directory 92 92 93 93 ; find matching files 94 94 testFiles = file_search(self.home + '*_ut__define.pro', $ 95 95 /fold_case, count=nTestFiles) 96 96 97 97 ; extract just classname from each file 98 98 myTests = file_basename(testFiles) … … 102 102 self->add, myTests[t] 103 103 endfor 104 104 105 105 ; second, for each directory in the current directory, either: 106 106 ; 1) add the *_uts__define.pro found there, or … … 118 118 suiteName = strmid(suiteName, 0, strlen(suiteName) - 12L) 119 119 if (suiteName ne self.name) then self->add, suiteName 120 120 121 121 continue ; finished with this directory 122 122 endif 123 124 ; if there isn't a *_uts__define.pro, but there are unit tests here 123 124 ; if there isn't a *_uts__define.pro, but there are unit tests here 125 125 ; then create a new test suite 126 126 uts = file_search(testDirs[d] + '*_ut__define.pro', $ 127 127 count=nTestCases) 128 128 if (nTestCases eq 0) then continue ; finished with this directory 129 129 130 130 otestsuite = obj_new('MGutTestSuite', home=testDirs[d], $ 131 131 name=file_basename(testDirs[d]), $ … … 138 138 ; don't add yourself to yourself 139 139 if (tests[t] eq self.name) then continue 140 141 ; see if test is valid 140 141 ; see if test is valid 142 142 otestcase = self->_makeTestCase(tests[t], error=error) 143 143 if (error ne 0L) then begin … … 145 145 continue 146 146 endif 147 147 148 148 ; test case is OK so now set it up 149 149 otestcase->setLevel, self.level + 1L … … 156 156 ;+ 157 157 ; Get properties of the object. 158 ; 158 ; 159 159 ; @keyword name {out}{optional}{type=string} name of the object 160 ; @keyword npass {out}{optional}{type=integer} number of passing tests 160 ; @keyword npass {out}{optional}{type=integer} number of passing tests 161 161 ; contained in the hierarchy below this object 162 ; @keyword nfail {out}{optional}{type=integer} number of failing tests 162 ; @keyword nfail {out}{optional}{type=integer} number of failing tests 163 163 ; contained in the hierarchy below this object 164 ; @keyword ntestcases {out}{optional}{type=integer} number of directly 164 ; @keyword ntestcases {out}{optional}{type=integer} number of directly 165 165 ; contained test suites or test cases 166 ; @keyword ntests {out}{optional}{type=integer} number of tests contained in 166 ; @keyword ntests {out}{optional}{type=integer} number of tests contained in 167 167 ; the hierarchy below this object 168 168 ;- … … 219 219 ; 220 220 ; @returns 1 for success, 0 for failure 221 ; @keyword name {in}{optional}{type=string}{default=classname} 221 ; @keyword name {in}{optional}{type=string}{default=classname} 222 222 ; name of the test suite 223 ; @keyword home {in}{optional}{type=string}{default=''} 223 ; @keyword home {in}{optional}{type=string}{default=''} 224 224 ; location of the root of the test suite 225 ; @keyword test_runner {in}{required}{type=object} 225 ; @keyword test_runner {in}{required}{type=object} 226 226 ; subclass of MGtestRunner 227 227 ;- … … 230 230 231 231 self.name = n_elements(name) eq 0 ? strlowcase(obj_class(self)) : name 232 232 233 233 if (n_elements(home) eq 0) then begin 234 234 ; get directory of caller's source code (subtract 2L to *caller* dir) 235 235 traceback = scope_traceback(/structure) 236 callingFrame = traceback[n_elements(traceback) - 2L > 0] 236 callingFrame = traceback[n_elements(traceback) - 2L > 0] 237 237 self.home = file_dirname(callingFrame.filename, /mark_directory) 238 238 endif else begin … … 241 241 : home + path_sep() 242 242 endelse 243 244 self.level = 0L 243 244 self.level = 0L 245 245 246 246 self.testRunner = testRunner 247 247 248 248 self.testcases = obj_new('IDL_Container') 249 249 250 250 self.npass = 0L 251 251 self.nfail = 0L … … 257 257 ;+ 258 258 ; Define member variables. 259 ; 259 ; 260 260 ; @file_comments Test suites are containers for test cases. Either subclass 261 ; MGutTestSuite and add test suites/test cases in its init 262 ; method or create a MGutTestSuite and use the add method to 261 ; MGutTestSuite and add test suites/test cases in its init 262 ; method or create a MGutTestSuite and use the add method to 263 263 ; add test suites/cases. 264 ; 264 ; 265 265 ; @field name name of the object 266 266 ; @field level number of layers below the top-most containing test suite 267 267 ; @field testcases IDL_Container holding test suites or test cases 268 268 ; @field testRunner subclass of MGutTestRunner 269 ; @field npass number of passing tests contained in the hierarchy below this 269 ; @field npass number of passing tests contained in the hierarchy below this 270 270 ; test suite 271 271 ; @field nfail number of failing tests contained in the hierarchy below this
