Mercurial > octave-nkf
comparison scripts/testfun/test.m @ 10549:95c3e38098bf
Untabify .m scripts
author | Rik <code@nomad.inbox5.com> |
---|---|
date | Fri, 23 Apr 2010 11:28:50 -0700 |
parents | f7cf1a53e1c5 |
children | 08050f37ba49 |
comparison
equal
deleted
inserted
replaced
10548:479536c5bb10 | 10549:95c3e38098bf |
---|---|
103 __close_fid = 0; | 103 __close_fid = 0; |
104 if (__batch) | 104 if (__batch) |
105 if (ischar (__fid)) | 105 if (ischar (__fid)) |
106 __fid = fopen (__fid, "wt"); | 106 __fid = fopen (__fid, "wt"); |
107 if (__fid < 0) | 107 if (__fid < 0) |
108 error ("could not open log file"); | 108 error ("could not open log file"); |
109 endif | 109 endif |
110 __close_fid = 1; | 110 __close_fid = 1; |
111 endif | 111 endif |
112 fprintf (__fid, "%sprocessing %s\n", __signal_file, __name); | 112 fprintf (__fid, "%sprocessing %s\n", __signal_file, __name); |
113 fflush (__fid); | 113 fflush (__fid); |
174 __ret2 = []; | 174 __ret2 = []; |
175 else | 175 else |
176 fprintf (__fid, "%s%s does not exist in path\n", __signal_empty, __name); | 176 fprintf (__fid, "%s%s does not exist in path\n", __signal_empty, __name); |
177 fflush (__fid); | 177 fflush (__fid); |
178 if (nargout > 0) | 178 if (nargout > 0) |
179 __ret1 = __ret2 = 0; | 179 __ret1 = __ret2 = 0; |
180 endif | 180 endif |
181 endif | 181 endif |
182 if (__close_fid) | 182 if (__close_fid) |
183 fclose(__fid); | 183 fclose(__fid); |
184 endif | 184 endif |
194 __ret2 = []; | 194 __ret2 = []; |
195 else | 195 else |
196 fprintf (__fid, "%s%s has no tests available\n", __signal_empty, __file); | 196 fprintf (__fid, "%s%s has no tests available\n", __signal_empty, __file); |
197 fflush (__fid); | 197 fflush (__fid); |
198 if (nargout > 0) | 198 if (nargout > 0) |
199 __ret1 = __ret2 = 0; | 199 __ret1 = __ret2 = 0; |
200 endif | 200 endif |
201 endif | 201 endif |
202 if (__close_fid) | 202 if (__close_fid) |
203 fclose(__fid); | 203 fclose(__fid); |
204 endif | 204 endif |
264 __isdemo = strcmp (__type, "demo"); | 264 __isdemo = strcmp (__type, "demo"); |
265 if (__grabdemo || __isdemo) | 265 if (__grabdemo || __isdemo) |
266 __istest = 0; | 266 __istest = 0; |
267 | 267 |
268 if (__grabdemo && __isdemo) | 268 if (__grabdemo && __isdemo) |
269 if (isempty(__demo_code)) | 269 if (isempty(__demo_code)) |
270 __demo_code = __code; | 270 __demo_code = __code; |
271 __demo_idx = [1, length(__demo_code)+1]; | 271 __demo_idx = [1, length(__demo_code)+1]; |
272 else | 272 else |
273 __demo_code = cstrcat(__demo_code, __code); | 273 __demo_code = cstrcat(__demo_code, __code); |
274 __demo_idx = [__demo_idx, length(__demo_code)+1]; | 274 __demo_idx = [__demo_idx, length(__demo_code)+1]; |
275 endif | 275 endif |
276 | 276 |
277 elseif (__rundemo && __isdemo) | 277 elseif (__rundemo && __isdemo) |
278 try | 278 try |
279 ## process the code in an environment without variables | 279 ## process the code in an environment without variables |
280 eval (sprintf ("function __test__()\n%s\nendfunction", __code)); | 280 eval (sprintf ("function __test__()\n%s\nendfunction", __code)); |
281 __test__; | 281 __test__; |
282 input ("Press <enter> to continue: ", "s"); | 282 input ("Press <enter> to continue: ", "s"); |
283 catch | 283 catch |
284 __success = 0; | 284 __success = 0; |
285 __msg = sprintf ("%sdemo failed\n%s", __signal_fail, __error_text__); | 285 __msg = sprintf ("%sdemo failed\n%s", __signal_fail, __error_text__); |
286 end_try_catch | 286 end_try_catch |
287 clear __test__; | 287 clear __test__; |
288 | 288 |
289 endif | 289 endif |
290 ## Code already processed. | 290 ## Code already processed. |
291 __code = ""; | 291 __code = ""; |
292 | 292 |
296 __istest = 0; | 296 __istest = 0; |
297 | 297 |
298 ## Separate initialization code from variables. | 298 ## Separate initialization code from variables. |
299 __idx = find (__code == "\n"); | 299 __idx = find (__code == "\n"); |
300 if (isempty (__idx)) | 300 if (isempty (__idx)) |
301 __vars = __code; | 301 __vars = __code; |
302 __code = ""; | 302 __code = ""; |
303 else | 303 else |
304 __vars = __code (1:__idx(1)-1); | 304 __vars = __code (1:__idx(1)-1); |
305 __code = __code (__idx(1):length(__code)); | 305 __code = __code (__idx(1):length(__code)); |
306 endif | 306 endif |
307 | 307 |
308 ## Strip comments off the variables. | 308 ## Strip comments off the variables. |
309 __idx = find (__vars == "%" | __vars == "#"); | 309 __idx = find (__vars == "%" | __vars == "#"); |
310 if (! isempty (__idx)) | 310 if (! isempty (__idx)) |
311 __vars = __vars(1:__idx(1)-1); | 311 __vars = __vars(1:__idx(1)-1); |
312 endif | 312 endif |
313 | 313 |
314 ## Assign default values to variables. | 314 ## Assign default values to variables. |
315 try | 315 try |
316 __vars = deblank (__vars); | 316 __vars = deblank (__vars); |
317 if (! isempty (__vars)) | 317 if (! isempty (__vars)) |
318 eval (cstrcat (strrep (__vars, ",", "=[];"), "=[];")); | 318 eval (cstrcat (strrep (__vars, ",", "=[];"), "=[];")); |
319 __shared = __vars; | 319 __shared = __vars; |
320 __shared_r = cstrcat ("[ ", __vars, "] = "); | 320 __shared_r = cstrcat ("[ ", __vars, "] = "); |
321 else | 321 else |
322 __shared = " "; | 322 __shared = " "; |
323 __shared_r = " "; | 323 __shared_r = " "; |
324 endif | 324 endif |
325 catch | 325 catch |
326 ## Couldn't declare, so don't initialize. | 326 ## Couldn't declare, so don't initialize. |
327 __code = ""; | 327 __code = ""; |
328 __success = 0; | 328 __success = 0; |
329 __msg = sprintf ("%sshared variable initialization failed\n", | 329 __msg = sprintf ("%sshared variable initialization failed\n", |
330 __signal_fail); | 330 __signal_fail); |
331 end_try_catch | 331 end_try_catch |
332 | 332 |
333 ## Clear shared function definitions. | 333 ## Clear shared function definitions. |
334 eval (__clear, ""); | 334 eval (__clear, ""); |
335 __clear = ""; | 335 __clear = ""; |
343 persistent __fn = 0; | 343 persistent __fn = 0; |
344 __name_position = function_name (__block); | 344 __name_position = function_name (__block); |
345 if (isempty (__name_position)) | 345 if (isempty (__name_position)) |
346 __success = 0; | 346 __success = 0; |
347 __msg = sprintf ("%stest failed: missing function name\n", | 347 __msg = sprintf ("%stest failed: missing function name\n", |
348 __signal_fail); | 348 __signal_fail); |
349 else | 349 else |
350 __name = __block(__name_position(1):__name_position(2)); | 350 __name = __block(__name_position(1):__name_position(2)); |
351 __code = __block; | 351 __code = __block; |
352 try | 352 try |
353 eval(__code); ## Define the function | 353 eval(__code); ## Define the function |
354 __clear = sprintf ("%sclear %s;\n", __clear, __name); | 354 __clear = sprintf ("%sclear %s;\n", __clear, __name); |
355 catch | 355 catch |
356 __success = 0; | 356 __success = 0; |
357 __msg = sprintf ("%stest failed: syntax error\n%s", | 357 __msg = sprintf ("%stest failed: syntax error\n%s", |
358 __signal_fail, __error_text__); | 358 __signal_fail, __error_text__); |
359 end_try_catch | 359 end_try_catch |
360 endif | 360 endif |
361 __code = ""; | 361 __code = ""; |
362 | 362 |
363 ### ASSERT/FAIL | 363 ### ASSERT/FAIL |
378 __patstr = ["id=",__id]; | 378 __patstr = ["id=",__id]; |
379 else | 379 else |
380 __patstr = ["<",__pattern,">"]; | 380 __patstr = ["<",__pattern,">"]; |
381 endif | 381 endif |
382 try | 382 try |
383 eval (sprintf ("function __test__(%s)\n%s\nendfunction", | 383 eval (sprintf ("function __test__(%s)\n%s\nendfunction", |
384 __shared, __code)); | 384 __shared, __code)); |
385 catch | 385 catch |
386 __success = 0; | 386 __success = 0; |
387 __msg = sprintf ("%stest failed: syntax error\n%s", | 387 __msg = sprintf ("%stest failed: syntax error\n%s", |
388 __signal_fail, __error_text__); | 388 __signal_fail, __error_text__); |
389 end_try_catch | 389 end_try_catch |
390 | 390 |
391 if (__success) | 391 if (__success) |
392 __success = 0; | 392 __success = 0; |
393 __warnstate = warning ("query", "quiet"); | 393 __warnstate = warning ("query", "quiet"); |
394 warning ("on", "quiet"); | 394 warning ("on", "quiet"); |
395 try | 395 try |
396 eval (sprintf ("__test__(%s);", __shared)); | 396 eval (sprintf ("__test__(%s);", __shared)); |
397 if (! __warning) | 397 if (! __warning) |
398 __msg = sprintf ("%sexpected %s but got no error\n", | 398 __msg = sprintf ("%sexpected %s but got no error\n", |
399 __signal_fail, __patstr); | 399 __signal_fail, __patstr); |
400 else | 400 else |
401 if (! isempty (__id)) | 401 if (! isempty (__id)) |
402 [~, __err] = lastwarn; | 402 [~, __err] = lastwarn; |
403 __mismatch = ! strcmp (__err, __id); | 403 __mismatch = ! strcmp (__err, __id); |
404 else | 404 else |
405 __err = trimerr (lastwarn, "warning"); | 405 __err = trimerr (lastwarn, "warning"); |
406 __mismatch = isempty (regexp (__err, __pattern, "once")); | 406 __mismatch = isempty (regexp (__err, __pattern, "once")); |
407 endif | 407 endif |
408 warning (__warnstate.state, "quiet"); | 408 warning (__warnstate.state, "quiet"); |
409 if (isempty (__err)) | 409 if (isempty (__err)) |
410 __msg = sprintf ("%sexpected %s but got no warning\n", | 410 __msg = sprintf ("%sexpected %s but got no warning\n", |
411 __signal_fail, __patstr); | 411 __signal_fail, __patstr); |
412 elseif (__mismatch) | 412 elseif (__mismatch) |
413 __msg = sprintf ("%sexpected %s but got %s\n", | 413 __msg = sprintf ("%sexpected %s but got %s\n", |
414 __signal_fail, __patstr, __err); | 414 __signal_fail, __patstr, __err); |
415 else | 415 else |
416 __success = 1; | 416 __success = 1; |
417 endif | 417 endif |
418 endif | 418 endif |
419 | 419 |
420 catch | 420 catch |
421 if (! isempty (__id)) | 421 if (! isempty (__id)) |
422 [~, __err] = lasterr; | 422 [~, __err] = lasterr; |
423 __mismatch = ! strcmp (__err, __id); | 423 __mismatch = ! strcmp (__err, __id); |
424 else | 424 else |
425 __err = trimerr (lasterr, "error"); | 425 __err = trimerr (lasterr, "error"); |
426 __mismatch = isempty (regexp (__err, __pattern, "once")); | 426 __mismatch = isempty (regexp (__err, __pattern, "once")); |
427 endif | 427 endif |
428 warning (__warnstate.state, "quiet"); | 428 warning (__warnstate.state, "quiet"); |
429 if (__warning) | 429 if (__warning) |
430 __msg = sprintf ("%sexpected warning %s but got error %s\n", | 430 __msg = sprintf ("%sexpected warning %s but got error %s\n", |
431 __signal_fail, __patstr, __err); | 431 __signal_fail, __patstr, __err); |
432 elseif (__mismatch) | 432 elseif (__mismatch) |
433 __msg = sprintf ("%sexpected %s but got %s\n", | 433 __msg = sprintf ("%sexpected %s but got %s\n", |
434 __signal_fail, __patstr, __err); | 434 __signal_fail, __patstr, __err); |
435 else | 435 else |
436 __success = 1; | 436 __success = 1; |
437 endif | 437 endif |
438 end_try_catch | 438 end_try_catch |
439 clear __test__; | 439 clear __test__; |
440 endif | 440 endif |
441 ## Code already processed. | 441 ## Code already processed. |
442 __code = ""; | 442 __code = ""; |
443 | 443 |
444 ### TESTIF | 444 ### TESTIF |
445 | 445 |
446 elseif (strcmp (__type, "testif")) | 446 elseif (strcmp (__type, "testif")) |
447 [__e, __feat] = regexp (__code, '^\s*([^\s]+)', 'end', 'tokens'); | 447 [__e, __feat] = regexp (__code, '^\s*([^\s]+)', 'end', 'tokens'); |
448 if (isempty (findstr (octave_config_info ("DEFS"), __feat{1}{1}))) | 448 if (isempty (findstr (octave_config_info ("DEFS"), __feat{1}{1}))) |
449 __xskip++; | 449 __xskip++; |
450 __success = 0; | 450 __success = 0; |
451 __istest = 0; | 451 __istest = 0; |
452 ## Skip the code. | 452 ## Skip the code. |
453 __code = ""; | 453 __code = ""; |
454 __msg = sprintf ("%sskipped test\n", __signal_skip); | 454 __msg = sprintf ("%sskipped test\n", __signal_skip); |
455 else | 455 else |
456 __istest = 1; | 456 __istest = 1; |
457 __code = __code(__e + 1 : end); | 457 __code = __code(__e + 1 : end); |
458 endif | 458 endif |
459 | 459 |
460 ### TEST | 460 ### TEST |
461 | 461 |
462 elseif (strcmp (__type, "test") || strcmp (__type, "xtest")) | 462 elseif (strcmp (__type, "test") || strcmp (__type, "xtest")) |
479 endif | 479 endif |
480 | 480 |
481 ## evaluate code for test, shared, and assert. | 481 ## evaluate code for test, shared, and assert. |
482 if (! isempty(__code)) | 482 if (! isempty(__code)) |
483 try | 483 try |
484 eval (sprintf ("function %s__test__(%s)\n%s\nendfunction", | 484 eval (sprintf ("function %s__test__(%s)\n%s\nendfunction", |
485 __shared_r,__shared, __code)); | 485 __shared_r,__shared, __code)); |
486 eval (sprintf ("%s__test__(%s);", __shared_r, __shared)); | 486 eval (sprintf ("%s__test__(%s);", __shared_r, __shared)); |
487 catch | 487 catch |
488 if (strcmp (__type, "xtest")) | 488 if (strcmp (__type, "xtest")) |
489 __msg = sprintf ("%sknown failure\n%s", __signal_fail, __error_text__); | 489 __msg = sprintf ("%sknown failure\n%s", __signal_fail, __error_text__); |
490 __xfail++; | 490 __xfail++; |
491 else | 491 else |
492 __msg = sprintf ("%stest failed\n%s", __signal_fail, __error_text__); | 492 __msg = sprintf ("%stest failed\n%s", __signal_fail, __error_text__); |
493 __success = 0; | 493 __success = 0; |
494 endif | 494 endif |
495 if (isempty (__error_text__)) | 495 if (isempty (__error_text__)) |
496 error ("empty error text, probably Ctrl-C --- aborting"); | 496 error ("empty error text, probably Ctrl-C --- aborting"); |
497 endif | 497 endif |
498 end_try_catch | 498 end_try_catch |
499 clear __test__; | 499 clear __test__; |
500 endif | 500 endif |
501 | 501 |
502 ## All done. Remember if we were successful and print any messages. | 502 ## All done. Remember if we were successful and print any messages. |
503 if (! isempty (__msg)) | 503 if (! isempty (__msg)) |
504 ## Make sure the user knows what caused the error. | 504 ## Make sure the user knows what caused the error. |
505 if (! __verbose) | 505 if (! __verbose) |
506 fprintf (__fid, "%s%s\n", __signal_block, __block); | 506 fprintf (__fid, "%s%s\n", __signal_block, __block); |
507 fflush (__fid); | 507 fflush (__fid); |
508 endif | 508 endif |
509 fputs (__fid, __msg); | 509 fputs (__fid, __msg); |
510 fputs (__fid, "\n"); | 510 fputs (__fid, "\n"); |
511 fflush (__fid); | 511 fflush (__fid); |
512 ## Show the variable context. | 512 ## Show the variable context. |
513 if (! strcmp (__type, "error") && ! strcmp (__type, "testif") | 513 if (! strcmp (__type, "error") && ! strcmp (__type, "testif") |
514 && ! all (__shared == " ")) | 514 && ! all (__shared == " ")) |
515 fputs (__fid, "shared variables "); | 515 fputs (__fid, "shared variables "); |
516 eval (sprintf ("fdisp(__fid,bundle(%s));", __shared)); | 516 eval (sprintf ("fdisp(__fid,bundle(%s));", __shared)); |
517 fflush (__fid); | 517 fflush (__fid); |
518 endif | 518 endif |
519 endif | 519 endif |
520 if (__success == 0) | 520 if (__success == 0) |
521 __all_success = 0; | 521 __all_success = 0; |
522 ## Stop after one error if not in batch mode. | 522 ## Stop after one error if not in batch mode. |
523 if (! __batch) | 523 if (! __batch) |
524 if (nargout > 0) | 524 if (nargout > 0) |
525 __ret1 = __ret2 = 0; | 525 __ret1 = __ret2 = 0; |
526 endif | 526 endif |
527 if (__close_fid) | 527 if (__close_fid) |
528 fclose(__fid); | 528 fclose(__fid); |
529 endif | 529 endif |
530 return; | 530 return; |
531 endif | 531 endif |
532 endif | 532 endif |
533 __tests += __istest; | 533 __tests += __istest; |
534 __successes += __success * __istest; | 534 __successes += __success * __istest; |
535 endfor | 535 endfor |
536 eval (__clear, ""); | 536 eval (__clear, ""); |
537 | 537 |
538 if (nargout == 0) | 538 if (nargout == 0) |
539 if (__tests || __xfail || __xskip) | 539 if (__tests || __xfail || __xskip) |
540 if (__xfail) | 540 if (__xfail) |
541 printf ("PASSES %d out of %d tests (%d expected failures)\n", | 541 printf ("PASSES %d out of %d tests (%d expected failures)\n", |
542 __successes, __tests, __xfail); | 542 __successes, __tests, __xfail); |
543 else | 543 else |
544 printf ("PASSES %d out of %d tests\n", __successes, __tests); | 544 printf ("PASSES %d out of %d tests\n", __successes, __tests); |
545 endif | 545 endif |
546 if (__xskip) | 546 if (__xskip) |
547 printf ("Skipped %d tests due to missing features\n", __xskip); | 547 printf ("Skipped %d tests due to missing features\n", __xskip); |
548 endif | 548 endif |
549 else | 549 else |
550 printf ("%s%s has no tests available\n", __signal_empty, __file); | 550 printf ("%s%s has no tests available\n", __signal_empty, __file); |
551 endif | 551 endif |
552 elseif (__grabdemo) | 552 elseif (__grabdemo) |
580 endif | 580 endif |
581 right = find (def(1:right-1) != " ", 1, "last"); | 581 right = find (def(1:right-1) != " ", 1, "last"); |
582 | 582 |
583 ## Find the beginning of the name. | 583 ## Find the beginning of the name. |
584 left = max ([find(def(1:right)==" ", 1, "last"), ... | 584 left = max ([find(def(1:right)==" ", 1, "last"), ... |
585 find(def(1:right)=="=", 1, "last")]); | 585 find(def(1:right)=="=", 1, "last")]); |
586 if (isempty (left)) | 586 if (isempty (left)) |
587 return; | 587 return; |
588 endif | 588 endif |
589 left++; | 589 left++; |
590 | 590 |