Skip to content
Snippets Groups Projects
Unverified Commit 456e674c authored by Markus Reiter's avatar Markus Reiter Committed by GitHub
Browse files

Merge pull request #8654 from reitermarkus/rspec-github-actions

Improve RSpec annotations.
parents fc27658b 196d7bad
No related branches found
No related tags found
No related merge requests found
......@@ -95,15 +95,15 @@ RSpec.configure do |config|
config.include(Test::Helper::OutputAsTTY)
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
config.before(:each, :needs_linux) do
skip "Not on Linux." unless OS.linux?
skip "Not running on Linux." unless OS.linux?
end
config.before(:each, :needs_macos) do
skip "Not on macOS." unless OS.mac?
skip "Not running on macOS." unless OS.mac?
end
config.before(:each, :needs_java) do
......@@ -113,11 +113,11 @@ RSpec.configure do |config|
else
which("java")
end
skip "Java not installed." unless java_installed
skip "Java is not installed." unless java_installed
end
config.before(:each, :needs_python) do
skip "Python not installed." unless which("python")
skip "Python is not installed." unless which("python")
end
config.before(:each, :needs_network) do
......@@ -125,7 +125,7 @@ RSpec.configure do |config|
end
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"])
if OS.mac?
......@@ -135,7 +135,7 @@ RSpec.configure do |config|
svn = which("svn", 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"])
.append(svn.dirname)
......@@ -143,7 +143,7 @@ RSpec.configure do |config|
end
config.before(:each, :needs_unzip) do
skip "unzip not installed." unless which("unzip")
skip "UnZip is not installed." unless which("unzip")
end
config.around do |example|
......
......@@ -9,6 +9,13 @@ module RSpec
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}"
......@@ -23,13 +30,27 @@ module RSpec
def example_failed(failure)
file, line = failure.example.location.split(":")
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
def example_pending(pending)
file, line = pending.example.location.split(":")
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
......
......@@ -6,10 +6,10 @@ module GitHub
# @api private
module Actions
def self.escape(string)
string.gsub(/\r/, "%0D")
.gsub(/\n/, "%0A")
.gsub(/]/, "%5D")
.gsub(/;/, "%3B")
# See https://github.community/t/set-output-truncates-multiline-strings/16852/3.
string.gsub("%", "%25")
.gsub("\n", "%0A")
.gsub("\r", "%0D")
end
# Helper class for formatting annotations on GitHub Actions.
......
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