Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. ```chapel
  2. /*
  3. Holder for test result information.
  4. Test results are automatically managed by the TestRunner, and do not
  5. need to be explicitly manipulated by writers of tests.
  6. Each instance holds the total number of tests run, and collections of
  7. failures and errors that occurred among those test runs. The collections
  8. contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
  9. formatted traceback of the error that occurred.
  10. */
  11. class TestResult {
  12. type tupType = 2*string;
  13. var failures: [1..0] tupType,
  14. errors: [1..0] tupType,
  15. skipped: [1..0] tupType;
  16. var testsRun = 0;
  17. var shouldStop = false;
  18. var separator1 = "="* 70,
  19. separator2 = "-"* 70;
  20. // called when a test if about to run
  21. proc startTest() {
  22. this.testsRun += 1;
  23. }
  24.  
  25. /*Called when an error has occurred.*/
  26. proc addError(test, errMsg) {
  27. this.errors.push_back((test: string, errMsg: string));
  28. }
  29.  
  30. /*called when error occured */
  31. proc addFailure(test, errMsg) {
  32. this.failures.push_back((test: string, errMsg: string));
  33. }
  34.  
  35. /*Called when a test has completed successfully*/
  36. proc addSuccess(test) { }
  37.  
  38. /*Called when a test is skipped.*/
  39. proc addSkip(test, reason) {
  40. this.skipped.push_back((test: string, reason: string));
  41. }
  42.  
  43. /*Tells whether or not this result was a success.*/
  44. proc wasSuccessful() {
  45. return this.failures.size == 0 && this.errors.size == 0;
  46. }
  47.  
  48. /* Indicates that the tests should be aborted. */
  49. proc stop() {
  50. this.shouldStop = true;
  51. }
  52.  
  53. /*Count of test skipped*/
  54. proc skippedTests() {
  55. return this.skipped.size;
  56. }
  57.  
  58. /*Count of test failed*/
  59. proc failedTests() {
  60. return this.failures.size;
  61. }
  62.  
  63. /*Count of tests giving error*/
  64. proc erroredTests() {
  65. return this.errors.size;
  66. }
  67.  
  68. proc printErrors() {
  69. writeln();
  70. this.printErrorList("ERROR", this.errors);
  71. this.printErrorList("FAIL", this.failures);
  72. this.printErrorList("SKIPPED", this.skipped);
  73. }
  74.  
  75. proc printErrorList(flavour, errors) {
  76. for (test, err) in errors {
  77. writeln(this.separator1);
  78. writeln(flavour," ",test);
  79. writeln(this.separator2);
  80. writeln(err);
  81. }
  82. }
  83.  
  84. /* Function to print the result*/
  85. proc PrintResult() {
  86. var skipped = this.skippedTests();
  87. var run = this.testsRun - skipped;
  88. writeln("Run "+ run +" "+printTest(run));
  89. writeln();
  90. var infos: [1..0](string);
  91. if !this.wasSuccessful() {
  92. write("FAILED");
  93. var failed = this.failedTests(),
  94. errored = this.erroredTests();
  95. if failed then
  96. infos.push_back("failures = "+failed);
  97. if errored then
  98. infos.push_back("errors = "+errored);
  99. }
  100. else
  101. stdout.write("OK");
  102. if skipped then
  103. infos.push_back("skipped = "+skipped);
  104. if infos.size {
  105. stdout.write(" ");
  106. for info in infos do stdout.write(info," ");
  107. }
  108. stdout.write("\n");
  109. // for value in this.failures do stdout.writeln(value);
  110. // for value in this.skipped do stdout.writeln(value);
  111. }
  112.  
  113. proc printTest(count) {
  114. if count > 1 {
  115. return "tests";
  116. }
  117. return "test";
  118. }
  119. }
  120. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement