minitest_reporters_github 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 33bad65ff00059d719888171a5fdad11d4b90f4ce2b8cc8722cbebd37b4a5bd7
4
+ data.tar.gz: 39523ba765a358fcbde5c00182df609f8173abb4a960975fc654d00befff2c1e
5
+ SHA512:
6
+ metadata.gz: 79bee2463e0775101f8fbd69c302f87a4a32374edc129d8f86962c5e90a4f1b43c34dea413394265e1d4bb09733e6bd95330b975b70668bcf128ec7ee96876b3
7
+ data.tar.gz: d9903407d27150a1cdc618b1d2d08b73ae0f9a4e6db8916ca746407345c665bbc11770bd87e404d85238b35debe9af4f29826887fb16e8b517eb5c3774e7992f
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.pattern = "test/{unit,integration}/**/*_test.rb"
5
+ t.verbose = true
6
+ end
7
+
8
+ task default: :test
@@ -0,0 +1,88 @@
1
+ # Taken from https://github.com/minitest-reporters/minitest-reporters/pull/332
2
+ # and adapted to be able to run as a standalone gem
3
+
4
+ require 'pathname'
5
+ require 'minitest/reporters'
6
+
7
+ # Inspired by the rubocop formatter.
8
+ # https://github.com/rubocop/rubocop/blob/2f8239f61bd41fe672a4cd9d6f24e334eba7854a/lib/rubocop/formatter/git_hub_actions_formatter.rb
9
+
10
+ # Simple reporter designed for Github Actions
11
+ class MinitestReportersGithub < Minitest::Reporters::BaseReporter
12
+ ESCAPE_MAP = { '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze
13
+
14
+ def start
15
+ super
16
+
17
+ print_run_options
18
+ end
19
+
20
+ def record(test)
21
+ super
22
+
23
+ print(message_for(test))
24
+ end
25
+
26
+ def message_for(test)
27
+ if test.passed? || test.skipped?
28
+ nil
29
+ elsif test.failure
30
+ to_annotation(test, "Failure")
31
+ elsif test.error?
32
+ to_annotation(test, "Error")
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def to_annotation(test, failure_type)
39
+ message = "#{failure_type}: #{test.name}\n\n#{test.failure.message}"
40
+ line_number = location(test.failure).split(":").last
41
+
42
+ "\n::error file=%<file>s,line=%<line>d::%<message>s\n" % {
43
+ file: get_relative_path(test),
44
+ line: line_number,
45
+ message: github_escape(message.rstrip),
46
+ }
47
+ end
48
+
49
+ def github_escape(string)
50
+ string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
51
+ end
52
+
53
+ def get_source_location(result)
54
+ if result.respond_to? :source_location
55
+ result.source_location
56
+ else
57
+ result.method(result.name).source_location
58
+ end
59
+ end
60
+
61
+ def location(exception)
62
+ last_before_assertion = ''
63
+ exception.backtrace.reverse_each do |s|
64
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
65
+
66
+ last_before_assertion = s
67
+ end
68
+
69
+ last_before_assertion.sub(/:in .*$/, '')
70
+ end
71
+
72
+ def get_relative_path(result)
73
+ file_path = Pathname.new(get_source_location(result).first)
74
+ base_path = Pathname.new(options[:base_path] || Dir.pwd)
75
+
76
+ if file_path.absolute?
77
+ file_path.relative_path_from(base_path)
78
+ else
79
+ file_path
80
+ end
81
+ end
82
+
83
+ def print_run_options
84
+ puts
85
+ puts("# Running tests with run options %s:" % options[:args])
86
+ puts
87
+ end
88
+ end
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/reporters'
4
+ require 'minitest_reporters_github'
5
+
6
+ Minitest::Reporters.use! MinitestReportersGithub.new
7
+
8
+ class TestClass < Minitest::Test
9
+ def test_assertion
10
+ assert true
11
+ end
12
+
13
+ def test_fail
14
+ if true
15
+ assert false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "../test_helper"
2
+
3
+ class MinitestReportersGithubTest < Minitest::Test
4
+ def test_output_format
5
+ fixtures_directory = File.expand_path('../fixtures', __dir__)
6
+ test_filename = File.join(fixtures_directory, 'github_actions_test.rb')
7
+ output = `ruby #{test_filename} 2>&1`
8
+ refute_match 'test_assertion', output
9
+ assert_match '::error file=test/fixtures/github_actions_test.rb,line=15::Failure: test_fail', output
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require "minitest/autorun"
2
+ require "minitest/reporters"
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest_reporters_github
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ewoud Kohl van Wijngaarden
8
+ - Earlopain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest-reporters
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '13.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '13.0'
42
+ description: A separate gem until https://github.com/minitest-reporters/minitest-reporters/pull/332
43
+ is merged
44
+ email:
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Rakefile
50
+ - lib/minitest_reporters_github.rb
51
+ - test/fixtures/github_actions_test.rb
52
+ - test/integration/github_actions_reporter_test.rb
53
+ - test/test_helper.rb
54
+ homepage: https://github.com/ekohl/minitest-reporters
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.7'
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '4'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.4.10
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: The GitHub Actions reporter for minitest-reporters
80
+ test_files: []