blob: c1cae626aea4a3f2ea3f6e7b5c695213e4ac60af [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/base/unittest/constants.html">
<link rel="import" href="/tracing/ui/base/ui.html">
<script>
'use strict';
tr.exportTo('tr.b.unittest', function() {
/**
* @constructor
*/
function TextTestResults() {
this.numTestsThatPassed_ = 0;
this.numTestsThatFailed_ = 0;
this.numFlakyTests_ = 0;
this.currentTestCaseHadErrors_ = false;
this.currentTestIsFlaky_ = false;
}
TextTestResults.prototype = {
get numTestsThatRan() {
return this.numTestsThatPassed_ + this.numTestsThatFailed_ +
this.numFlakyTests_;
},
get numTestsThatFailed() {
return this.numTestsThatFailed_;
},
get numTestsThatPassed() {
return this.numTestsThatPassed_;
},
get numFlakyTests() {
return this.numFlakyTests_;
},
willRunTests: function(testCases) {
},
willRunTest: function(testCase) {
this.write_(testCase.name + ' (' + testCase.suite.name + ') ... ');
this.currentTestCaseHadErrors_ = false;
this.currentTestIsFlaky_ = false;
},
addErrorForCurrentTest: function(error) {
if (!this.currentTestCaseHadErrors_)
this.write_('FAIL\n');
var normalizedException = tr.b.normalizeException(error);
this.write_(normalizedException.stack + '\n');
this.currentTestCaseHadErrors_ = true;
},
addHTMLOutputForCurrentTest: function(element) {
this.curHTMLOutput_.push(element);
},
setCurrentTestFlaky: function() {
if (!this.currentTestIsFlaky_)
this.write_('FLAKY\n');
this.currentTestIsFlaky_ = true;
},
setReturnValueFromCurrentTest: function(returnValue) {
this.write_('[RESULT] ' + JSON.stringify(returnValue) + '\n');
},
didCurrentTestEnd: function() {
if (this.currentTestCaseHadErrors_) {
this.numTestsThatFailed_ += 1;
} else if (this.currentTestIsFlaky_) {
this.numFlakyTests_ += 1;
} else {
this.numTestsThatPassed_ += 1;
this.write_('ok\n');
}
},
didRunTests: function() {
this.write_('\n------------------------------------------------------' +
'----------------\n');
if (this.numTestsThatRan === 1)
this.write_('Ran 1 test\n');
else
this.write_('Ran ' + this.numTestsThatRan + ' tests\n');
if (this.numTestsThatFailed > 0) {
var flakyString = this.numFlakyTests == 0 ? '' :
' flaky=' + this.numFlakyTests;
this.write_('\nFAILED (errors=' + this.numTestsThatFailed +
flakyString + ')');
} else {
var flakyString = this.numFlakyTests == 0 ? '' :
' (flaky=' + this.numFlakyTests + ')';
this.write_('\nOK' + flakyString);
}
},
write_: function(msg) {
if (tr.isVinn)
global.write(msg);
else
console.log(msg);
}
};
return {
TextTestResults: TextTestResults
};
});
</script>