Skip to content
Snippets Groups Projects
Unverified Commit 6f06114b authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Improve output of failed tests

Test group and test names are now displayed separately, an additional
line is added to show the location on which the test is defined, and all
output is now left aligned with the corresponding labels. This makes it
easier to read the output whenever there are test failures.
parent a106a003
No related branches found
No related tags found
No related merge requests found
#! Built-in formatters for test suites.
import std::ansi::(self, BOLD, CYAN, GREEN, RED)
import std::conversion::ToString
import std::debug::CallFrame
import std::stdio::stdout
import std::string_buffer::StringBuffer
import std::test::error::TestFailure
Loading
Loading
@@ -33,15 +34,8 @@ object ProgressFormatter {
@colors = colors
}
 
## Returns the title to use for a failed test.
def failure_title(test: Test) -> String {
StringBuffer.new(test.group_name, ' ', test.name).to_string
}
## Returns the location of a test failure.
def failure_location(failure: TestFailure) -> String {
let location = failure.location
def format_location(location: CallFrame) -> String {
StringBuffer
.new(location.path.to_string, ':', location.line.to_string)
.to_string
Loading
Loading
@@ -128,18 +122,24 @@ impl Formatter for ProgressFormatter {
def failures(tests: Array!(Test)) {
stdout.write_string("\n\nFailures:")
 
tests.each do (test) {
tests.each_with_index do (test, index) {
let failure = test.failure!
 
let buffer = StringBuffer.new(
"\n\n",
' Test: ',
bold(failure_title(test)),
' Group: ',
test.group_name,
"\n",
' Location: ',
cyan(failure_location(failure)),
"\n\n",
' ',
' Test: ',
bold(test.name),
"\n",
' Test location: ',
cyan(format_location(test.location)),
"\n",
' Failure location: ',
cyan(format_location(failure.location)),
"\n",
' Failure: ',
red(failure.message),
)
 
Loading
Loading
Loading
Loading
@@ -19,21 +19,12 @@ def example_test -> Test {
)
}
 
test.group('std::test::formatters::ProgressFormatter.failure_title') do (g) {
g.test('Generating the title for a failed test') {
let fmt = ProgressFormatter.new
assert.equal(fmt.failure_title(example_test), 'group name test name')
}
}
test.group('std::test::formatters::ProgressFormatter.failure_location') do (g) {
test.group('std::test::formatters::ProgressFormatter.format_location') do (g) {
g.test('Generating the failure location description for a failed test') {
let fmt = ProgressFormatter.new
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
let failure = TestFailure.new(message: 'oops', location: frame)
 
assert.equal(fmt.failure_location(failure), 'test.inko:1')
assert.equal(fmt.format_location(frame), 'test.inko:1')
}
}
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment