PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/fth/t_tools.fth

https://github.com/cataska/pforth
Forth | 83 lines | 68 code | 15 blank | 0 comment | 4 complexity | c9ec76fb123d9b17bea5cf20458a715e MD5 | raw file
  1. \ @(#) t_tools.fth 97/12/10 1.1
  2. \ Test Tools for pForth
  3. \
  4. \ Based on testing tools from John Hayes
  5. \ (c) 1993 Johns Hopkins University / Applied Physics Laboratory
  6. \
  7. \ Syntax was changed to avoid conflict with { -> and } for local variables.
  8. \ Also added tracking of #successes and #errors.
  9. anew task-t_tools.fth
  10. decimal
  11. variable TEST-DEPTH
  12. variable TEST-PASSED
  13. variable TEST-FAILED
  14. : TEST{
  15. depth test-depth !
  16. 0 test-passed !
  17. 0 test-failed !
  18. ;
  19. : }TEST
  20. test-passed @ 4 .r ." passed, "
  21. test-failed @ 4 .r ." failed." cr
  22. ;
  23. VARIABLE actual-depth \ stack record
  24. CREATE actual-results 20 CELLS ALLOT
  25. : empty-stack \ ( ... -- ) Empty stack.
  26. DEPTH dup 0>
  27. IF 0 DO DROP LOOP
  28. ELSE drop
  29. THEN ;
  30. CREATE the-test 128 CHARS ALLOT
  31. : ERROR \ ( c-addr u -- ) Display an error message followed by
  32. \ the line that had the error.
  33. TYPE the-test COUNT TYPE CR \ display line corresponding to error
  34. empty-stack \ throw away every thing else
  35. ;
  36. : T{
  37. source the-test place
  38. empty-stack
  39. ;
  40. : }T{ \ ( ... -- ) Record depth and content of stack.
  41. DEPTH actual-depth ! \ record depth
  42. DEPTH 0
  43. ?DO
  44. actual-results I CELLS + !
  45. LOOP \ save them
  46. ;
  47. : }T \ ( ... -- ) Compare stack (expected) contents with saved
  48. \ (actual) contents.
  49. DEPTH
  50. actual-depth @ =
  51. IF \ if depths match
  52. 1 test-passed +! \ assume will pass
  53. DEPTH 0
  54. ?DO \ for each stack item
  55. actual-results I CELLS + @ \ compare actual with expected
  56. <>
  57. IF
  58. -1 test-passed +!
  59. 1 test-failed +!
  60. S" INCORRECT RESULT: " error
  61. LEAVE
  62. THEN
  63. LOOP
  64. ELSE \ depth mismatch
  65. 1 test-failed +!
  66. S" WRONG NUMBER OF RESULTS: " error
  67. THEN
  68. ;