diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 8025ffda3e..db91f4fc8b 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -118,6 +118,8 @@ module Homebrew --out #{HOMEBREW_CACHE}/tests/parallel_runtime_rspec.log ] + bundle_args << "--format" << "RSpec::Github::Formatter" if ENV["GITHUB_ACTIONS"] + unless OS.mac? bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask" files = files.reject { |p| p =~ %r{^test/(os/mac|cask)(/.*|_spec\.rb)$} } diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb index 998198de44..f3b323eaf0 100644 --- a/Library/Homebrew/test/sandbox_spec.rb +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -2,7 +2,7 @@ require "sandbox" -describe Sandbox do +describe Sandbox, :needs_macos do define_negated_matcher :not_matching, :matching let(:dir) { mktmpdir } diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 7d878b0989..17d5c8e2ba 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -36,6 +36,7 @@ $LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/suppo require_relative "../global" require "test/support/no_seed_progress_formatter" +require "test/support/github_formatter" require "test/support/helper/cask" require "test/support/helper/fixtures" require "test/support/helper/formula" diff --git a/Library/Homebrew/test/support/github_formatter.rb b/Library/Homebrew/test/support/github_formatter.rb new file mode 100644 index 0000000000..94b57dcece --- /dev/null +++ b/Library/Homebrew/test/support/github_formatter.rb @@ -0,0 +1,36 @@ +# 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.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) + output.puts "\n::error file=#{file},line=#{line}::#{failure.message_lines.join("%0A")}" + 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}" + end + end + end +end