Merge pull request #10100 from issyl0/use-rspec-github-gem

Replace `test/support/github_formatter` with `rspec-github` gem
This commit is contained in:
Issy Long 2020-12-23 18:34:47 +00:00 committed by GitHub
commit e041468375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 59 deletions

View File

@ -9,6 +9,7 @@ gem "nokogiri", require: false
gem "parallel_tests", require: false gem "parallel_tests", require: false
gem "ronn", require: false gem "ronn", require: false
gem "rspec", require: false gem "rspec", require: false
gem "rspec-github", require: false
gem "rspec-its", require: false gem "rspec-its", require: false
gem "rspec-retry", require: false gem "rspec-retry", require: false
gem "rspec-sorbet", require: false gem "rspec-sorbet", require: false

View File

@ -86,6 +86,8 @@ GEM
rspec-expectations (3.10.0) rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0) rspec-support (~> 3.10.0)
rspec-github (2.3.1)
rspec-core (~> 3.0)
rspec-its (1.3.0) rspec-its (1.3.0)
rspec-core (>= 3.0.0) rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0) rspec-expectations (>= 3.0.0)
@ -173,6 +175,7 @@ DEPENDENCIES
plist plist
ronn ronn
rspec rspec
rspec-github
rspec-its rspec-its
rspec-retry rspec-retry
rspec-sorbet rspec-sorbet

View File

@ -24,6 +24,7 @@ if ENV["HOMEBREW_TESTS_COVERAGE"]
end end
require "rspec/its" require "rspec/its"
require "rspec/github"
require "rspec/wait" require "rspec/wait"
require "rspec/retry" require "rspec/retry"
require "rspec/sorbet" require "rspec/sorbet"
@ -38,7 +39,6 @@ $LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/suppo
require_relative "../global" require_relative "../global"
require "test/support/no_seed_progress_formatter" require "test/support/no_seed_progress_formatter"
require "test/support/github_formatter"
require "test/support/helper/cask" require "test/support/helper/cask"
require "test/support/helper/fixtures" require "test/support/helper/fixtures"
require "test/support/helper/formula" require "test/support/helper/formula"

View File

@ -1,58 +0,0 @@
# typed: true
# frozen_string_literal: true
require "rspec/core"
require "rspec/core/formatters/base_formatter"
# TODO: Replace with `rspec-github` when https://github.com/Drieam/rspec-github/pull/4 is merged.
module RSpec
module Github
class Formatter < RSpec::Core::Formatters::BaseFormatter
RSpec::Core::Formatters.register self, :example_failed, :example_pending
def self.escape(string)
# See https://github.community/t/set-output-truncates-multiline-strings/16852/3.
string.gsub("%", "%25")
.gsub("\n", "%0A")
.gsub("\r", "%0D")
end
def self.relative_path(path)
if (workspace = ENV["GITHUB_WORKSPACE"])
workspace = "#{File.realpath(workspace)}#{File::SEPARATOR}"
absolute_path = File.realpath(path)
return absolute_path.delete_prefix(workspace) if absolute_path.start_with?(workspace)
end
path
end
def example_failed(failure)
file, line = failure.example.location.split(":")
file = self.class.relative_path(file)
description = failure.example.full_description
message = failure.message_lines.join("\n")
annotation = "#{description}\n\n#{message}"
output.puts "\n::error file=#{file},line=#{line}::#{self.class.escape(annotation)}"
end
def example_pending(pending)
file, line = pending.example.location.split(":")
file = self.class.relative_path(file)
description = pending.example.full_description
message = if pending.example.skip
"Skipped: #{pending.example.execution_result.pending_message}"
else
"Pending: #{pending.example.execution_result.pending_message}"
end
annotation = "#{description}\n\n#{message}"
output.puts "\n::warning file=#{file},line=#{line}::#{self.class.escape(annotation)}"
end
end
end
end