-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses part of #3176 Note: The `omission` feature in test-unit is not currently supported.
- Loading branch information
Showing
14 changed files
with
5,777 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
$stdout.binmode | ||
$stdout.sync = true | ||
$stderr.binmode | ||
$stderr.sync = true | ||
|
||
module RubyLsp | ||
module TestReporter | ||
class << self | ||
#: (id: String, uri: URI::Generic) -> void | ||
def start_test(id:, uri:) | ||
params = { | ||
id: id, | ||
uri: uri.to_s, | ||
} | ||
send_message("start", params) | ||
end | ||
|
||
#: (id: String, uri: URI::Generic) -> void | ||
def record_pass(id:, uri:) | ||
params = { | ||
id: id, | ||
uri: uri.to_s, | ||
} | ||
send_message("pass", params) | ||
end | ||
|
||
#: (id: String, message: String, uri: URI::Generic) -> void | ||
def record_fail(id:, message:, uri:) | ||
params = { | ||
id: id, | ||
message: message, | ||
uri: uri.to_s, | ||
} | ||
send_message("fail", params) | ||
end | ||
|
||
#: (id: String, message: String?, uri: URI::Generic) -> void | ||
def record_skip(id:, message:, uri:) | ||
params = { | ||
id: id, | ||
message: message, | ||
uri: uri.to_s, | ||
} | ||
send_message("skip", params) | ||
end | ||
|
||
#: (id: String, message: String?, uri: String) -> void | ||
def record_error(id:, message:, uri:) | ||
params = { | ||
id: id, | ||
message: message, | ||
uri: uri.to_s, | ||
} | ||
send_message("error", params) | ||
end | ||
|
||
private | ||
|
||
#: (method_name: String?, params: Hash[String, untyped]) -> void | ||
def send_message(method_name, params) | ||
json_message = { method: method_name, params: params }.to_json | ||
$stdout.write("Content-Length: #{json_message.bytesize}\r\n\r\n#{json_message}") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "test/unit" | ||
require "test/unit/ui/testrunner" | ||
require "ruby_lsp/test_reporter" | ||
require "ruby_indexer/lib/ruby_indexer/uri" | ||
|
||
module RubyLsp | ||
class TestRunner < ::Test::Unit::UI::TestRunner | ||
private | ||
|
||
#: (::Test::Unit::TestCase test) -> void | ||
def test_started(test) | ||
current_test = test | ||
@current_uri = uri_for_test(current_test) | ||
return unless @current_uri | ||
|
||
@current_test_id = "#{current_test.class.name}##{current_test.method_name}" | ||
TestReporter.start_test( | ||
id: @current_test_id, | ||
uri: @current_uri, | ||
) | ||
end | ||
|
||
#: (::Test::Unit::TestCase test) -> void | ||
def test_finished(test) | ||
if test.passed? | ||
TestReporter.record_pass( | ||
id: @current_test_id, | ||
uri: @current_uri, | ||
) | ||
end | ||
end | ||
|
||
#: (::Test::Unit::Failure | ::Test::Unit::Error | ::Test::Unit::Pending result) -> void | ||
def result_fault(result) | ||
case result | ||
when ::Test::Unit::Failure | ||
record_failure(result) | ||
when ::Test::Unit::Error | ||
record_error(result) | ||
when ::Test::Unit::Pending | ||
record_skip(result) | ||
end | ||
end | ||
|
||
#: (::Test::Unit::Failure failure) -> void | ||
def record_failure(failure) | ||
TestReporter.record_fail( | ||
id: @current_test_id, | ||
message: failure.message, | ||
uri: @current_uri, | ||
) | ||
end | ||
|
||
#: (::Test::Unit::Error error) -> void | ||
def record_error(error) | ||
TestReporter.record_error( | ||
id: @current_test_id, | ||
message: error.message, | ||
uri: @current_uri, | ||
) | ||
end | ||
|
||
#: (::Test::Unit::Pending pending) -> void | ||
def record_skip(pending) | ||
TestReporter.record_skip( | ||
id: @current_test_id, | ||
message: pending.message, | ||
uri: @current_uri, | ||
) | ||
end | ||
|
||
#: (::Test::Unit::TestCase test) -> URI::Generic? | ||
def uri_for_test(test) | ||
location = test.method(test.method_name).source_location | ||
return unless location # TODO: when might this be nil? | ||
|
||
file, _line = location | ||
return if file.start_with?("(eval at ") # test is dynamically defined (TODO: better way to check?) | ||
|
||
absolute_path = File.expand_path(file, Dir.pwd) | ||
URI::Generic.from_path(path: absolute_path) | ||
end | ||
|
||
#: -> void | ||
def attach_to_mediator | ||
@mediator.add_listener(Test::Unit::TestResult::FAULT, &method(:result_fault)) | ||
@mediator.add_listener(Test::Unit::TestCase::STARTED_OBJECT, &method(:test_started)) | ||
@mediator.add_listener(Test::Unit::TestCase::FINISHED_OBJECT, &method(:test_finished)) | ||
end | ||
end | ||
end | ||
|
||
Test::Unit::AutoRunner.register_runner(:ruby_lsp) { |_auto_runner| RubyLsp::TestRunner } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.