diff --git a/HISTORY.md b/HISTORY.md index bfdf984..5c4d139 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,16 @@ # RELEASE HISTORY +## Unreleased + +Changes: + +* Fix the TAP-Y and TAP-J reporters, which raised NoMethodError + ("undefined method 'file' for nil") for a failed, errored or pending test + whose exception had no backtrace line outside the test framework. Lemon + marks a test pending that way when it doesn't call the method it covers. + The run then ended early with wrong counts. The record now has the + exception's message without a source location. + ## 0.11.0 / 2026-11-17 The Rake task and the HTML reporter are back in Rubytest, so rubytest-rake diff --git a/demo/05_builtin_reporters.md b/demo/05_builtin_reporters.md index 2534679..7e32484 100644 --- a/demo/05_builtin_reporters.md +++ b/demo/05_builtin_reporters.md @@ -104,6 +104,26 @@ YAML documents, TAP-J a line of JSON for each record. records.count { |record| record['type'] == 'case' && !record['status'] }.assert == 2 end +An exception may have no line of backtrace outside the test framework, as +when a framework marks a test pending itself. Its record then has the message +without a source location. + + bare = probe_type.new('bare') do + error = NotImplementedError.new('not tested') + error.set_backtrace([]) + raise error + end + + readers.each do |format, read| + success, output, report = render.call(format, [bare, passing]) + records = read.call(output) + records.last['counts']['total'].assert == 2 + record = records.find { |r| r['label'] == 'bare' } + record['status'].assert == 'todo' + record['exception']['message'].assert == 'not tested' + record['exception'].key?('file').assert == false + end + A TAP-Y stream ends with the YAML end-of-document marker. render.call('tapy')[1].lines.last.chomp.assert == '...' diff --git a/lib/rubytest/format/abstract_hash.rb b/lib/rubytest/format/abstract_hash.rb index c3540f9..0cd7257 100644 --- a/lib/rubytest/format/abstract_hash.rb +++ b/lib/rubytest/format/abstract_hash.rb @@ -275,10 +275,14 @@ def merge_source(hash, test) # Add exception subsection of hash. def merge_exception(hash, test, exception, bt=false) hash['exception'] = {} - hash['exception']['file' ] = code(exception).file - hash['exception']['line' ] = code(exception).line - hash['exception']['source' ] = code(exception).to_str - hash['exception']['snippet' ] = code(exception).to_omap + # There is no snippet when every line of the backtrace belongs to + # the test framework, or the exception has none. + if snippet = code(exception) + hash['exception']['file' ] = snippet.file + hash['exception']['line' ] = snippet.line + hash['exception']['source' ] = snippet.to_str + hash['exception']['snippet' ] = snippet.to_omap + end hash['exception']['message' ] = exception.message hash['exception']['backtrace'] = clean_backtrace(exception) if bt if @current_result && @current_result.exceptions.size > 1