Improve RSpec annotations.
This commit is contained in:
parent
6d1de3a72b
commit
196d7badfa
@ -95,15 +95,15 @@ RSpec.configure do |config|
|
|||||||
config.include(Test::Helper::OutputAsTTY)
|
config.include(Test::Helper::OutputAsTTY)
|
||||||
|
|
||||||
config.before(:each, :needs_compat) do
|
config.before(:each, :needs_compat) do
|
||||||
skip "Requires compatibility layer." if ENV["HOMEBREW_NO_COMPAT"]
|
skip "Requires the compatibility layer." if ENV["HOMEBREW_NO_COMPAT"]
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_linux) do
|
config.before(:each, :needs_linux) do
|
||||||
skip "Not on Linux." unless OS.linux?
|
skip "Not running on Linux." unless OS.linux?
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_macos) do
|
config.before(:each, :needs_macos) do
|
||||||
skip "Not on macOS." unless OS.mac?
|
skip "Not running on macOS." unless OS.mac?
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_java) do
|
config.before(:each, :needs_java) do
|
||||||
@ -113,11 +113,11 @@ RSpec.configure do |config|
|
|||||||
else
|
else
|
||||||
which("java")
|
which("java")
|
||||||
end
|
end
|
||||||
skip "Java not installed." unless java_installed
|
skip "Java is not installed." unless java_installed
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_python) do
|
config.before(:each, :needs_python) do
|
||||||
skip "Python not installed." unless which("python")
|
skip "Python is not installed." unless which("python")
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_network) do
|
config.before(:each, :needs_network) do
|
||||||
@ -125,7 +125,7 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_svn) do
|
config.before(:each, :needs_svn) do
|
||||||
skip "subversion not installed." unless quiet_system "#{HOMEBREW_SHIMS_PATH}/scm/svn", "--version"
|
skip "Subversion is not installed." unless quiet_system "#{HOMEBREW_SHIMS_PATH}/scm/svn", "--version"
|
||||||
|
|
||||||
svn_paths = PATH.new(ENV["PATH"])
|
svn_paths = PATH.new(ENV["PATH"])
|
||||||
if OS.mac?
|
if OS.mac?
|
||||||
@ -135,7 +135,7 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
svn = which("svn", svn_paths)
|
svn = which("svn", svn_paths)
|
||||||
svnadmin = which("svnadmin", svn_paths)
|
svnadmin = which("svnadmin", svn_paths)
|
||||||
skip "subversion not installed." if !svn || !svnadmin
|
skip "Subversion is not installed." if !svn || !svnadmin
|
||||||
|
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"])
|
ENV["PATH"] = PATH.new(ENV["PATH"])
|
||||||
.append(svn.dirname)
|
.append(svn.dirname)
|
||||||
@ -143,7 +143,7 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_unzip) do
|
config.before(:each, :needs_unzip) do
|
||||||
skip "unzip not installed." unless which("unzip")
|
skip "UnZip is not installed." unless which("unzip")
|
||||||
end
|
end
|
||||||
|
|
||||||
config.around do |example|
|
config.around do |example|
|
||||||
|
|||||||
@ -9,6 +9,13 @@ module RSpec
|
|||||||
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
||||||
RSpec::Core::Formatters.register self, :example_failed, :example_pending
|
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)
|
def self.relative_path(path)
|
||||||
if (workspace = ENV["GITHUB_WORKSPACE"])
|
if (workspace = ENV["GITHUB_WORKSPACE"])
|
||||||
workspace = "#{File.realpath(workspace)}#{File::SEPARATOR}"
|
workspace = "#{File.realpath(workspace)}#{File::SEPARATOR}"
|
||||||
@ -23,13 +30,27 @@ module RSpec
|
|||||||
def example_failed(failure)
|
def example_failed(failure)
|
||||||
file, line = failure.example.location.split(":")
|
file, line = failure.example.location.split(":")
|
||||||
file = self.class.relative_path(file)
|
file = self.class.relative_path(file)
|
||||||
output.puts "\n::error file=#{file},line=#{line}::#{failure.message_lines.join("%0A")}"
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def example_pending(pending)
|
def example_pending(pending)
|
||||||
file, line = pending.example.location.split(":")
|
file, line = pending.example.location.split(":")
|
||||||
file = self.class.relative_path(file)
|
file = self.class.relative_path(file)
|
||||||
output.puts "\n::warning file=#{file},line=#{line}::#{pending.example.full_description}"
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,10 +6,10 @@ module GitHub
|
|||||||
# @api private
|
# @api private
|
||||||
module Actions
|
module Actions
|
||||||
def self.escape(string)
|
def self.escape(string)
|
||||||
string.gsub(/\r/, "%0D")
|
# See https://github.community/t/set-output-truncates-multiline-strings/16852/3.
|
||||||
.gsub(/\n/, "%0A")
|
string.gsub("%", "%25")
|
||||||
.gsub(/]/, "%5D")
|
.gsub("\n", "%0A")
|
||||||
.gsub(/;/, "%3B")
|
.gsub("\r", "%0D")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper class for formatting annotations on GitHub Actions.
|
# Helper class for formatting annotations on GitHub Actions.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user