text_test_results.html revision cef7893435aa41160dd1255c43cb8498279738cc
1<!DOCTYPE html>
2<!--
3Copyright (c) 2014 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7<link rel="import" href="/tracing/base/utils.html">
8<link rel="import" href="/tracing/base/unittest/constants.html">
9<link rel="import" href="/tracing/ui/base/ui.html">
10<script>
11'use strict';
12
13tr.exportTo('tr.b.unittest', function() {
14  /**
15   * @constructor
16   */
17  function TextTestResults() {
18    this.numTestsThatPassed_ = 0;
19    this.numTestsThatFailed_ = 0;
20    this.numFlakyTests_ = 0;
21    this.currentTestCaseHadErrors_ = false;
22    this.currentTestIsFlaky_ = false;
23  }
24
25  TextTestResults.prototype = {
26    get numTestsThatRan() {
27      return this.numTestsThatPassed_ + this.numTestsThatFailed_ +
28          this.numFlakyTests_;
29    },
30
31    get numTestsThatFailed() {
32      return this.numTestsThatFailed_;
33    },
34
35    get numTestsThatPassed() {
36      return this.numTestsThatPassed_;
37    },
38
39    get numFlakyTests() {
40      return this.numFlakyTests_;
41    },
42
43    willRunTests: function(testCases) {
44    },
45
46    willRunTest: function(testCase) {
47      this.write_(testCase.name + ' (' + testCase.suite.name + ') ... ');
48      this.currentTestCaseHadErrors_ = false;
49      this.currentTestIsFlaky_ = false;
50    },
51
52    addErrorForCurrentTest: function(error) {
53      if (!this.currentTestCaseHadErrors_)
54        this.write_('FAIL\n');
55      var normalizedException = tr.b.normalizeException(error);
56      this.write_(normalizedException.stack + '\n');
57      this.currentTestCaseHadErrors_ = true;
58    },
59
60    addHTMLOutputForCurrentTest: function(element) {
61      this.curHTMLOutput_.push(element);
62    },
63
64    setCurrentTestFlaky: function() {
65      if (!this.currentTestIsFlaky_)
66        this.write_('FLAKY\n');
67      this.currentTestIsFlaky_ = true;
68    },
69
70    setReturnValueFromCurrentTest: function(returnValue) {
71      this.write_('[RESULT] ' + JSON.stringify(returnValue) + '\n');
72    },
73
74    didCurrentTestEnd: function() {
75      if (this.currentTestCaseHadErrors_) {
76        this.numTestsThatFailed_ += 1;
77      } else if (this.currentTestIsFlaky_) {
78        this.numFlakyTests_ += 1;
79      } else {
80        this.numTestsThatPassed_ += 1;
81        this.write_('ok\n');
82      }
83    },
84
85    didRunTests: function() {
86      this.write_('\n------------------------------------------------------' +
87               '----------------\n');
88      if (this.numTestsThatRan === 1)
89        this.write_('Ran 1 test\n');
90      else
91        this.write_('Ran ' + this.numTestsThatRan + ' tests\n');
92
93      if (this.numTestsThatFailed > 0) {
94        var flakyString = this.numFlakyTests == 0 ? '' :
95            ' flaky=' + this.numFlakyTests;
96        this.write_('\nFAILED (errors=' + this.numTestsThatFailed +
97            flakyString + ')');
98      } else {
99        var flakyString = this.numFlakyTests == 0 ? '' :
100            ' (flaky=' + this.numFlakyTests + ')';
101        this.write_('\nOK' + flakyString);
102      }
103    },
104
105    write_: function(msg) {
106      if (tr.isVinn)
107        global.write(msg);
108      else
109        console.log(msg);
110    }
111  };
112
113  return {
114    TextTestResults: TextTestResults
115  };
116});
117</script>
118