From 943afda37cdefb3839b32c808ee22119512e4c93 Mon Sep 17 00:00:00 2001 From: nicholas evans Date: Tue, 17 Jan 2023 23:46:25 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Setup=20simplecov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It took me a while to figure out that the simplecov-check-action requires extra permissions, and even then it still needs a GitHub App to work on `pull_request` events. I'm okay with only running it on `push` events. --- .github/workflows/test.yml | 11 +++++++++++ Gemfile | 8 +++++++- test/lib/helper.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17732cac..39d16289 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,9 @@ jobs: build: needs: ruby-versions + permissions: + contents: read + checks: write name: build (${{ matrix.ruby }} / ${{ matrix.os }}) strategy: matrix: @@ -29,3 +32,11 @@ jobs: rubygems: 3.5.14 - name: Run test run: bundle exec rake test + + - uses: joshmfrankel/simplecov-check-action@main + if: matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' + with: + check_job_name: "SimpleCov - ${{ matrix.ruby }}" + minimum_suite_coverage: 90 + minimum_file_coverage: 40 # TODO: increase this after switching to SASL::AuthenticationExchange + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Gemfile b/Gemfile index cdf72462..cbceddc9 100644 --- a/Gemfile +++ b/Gemfile @@ -13,4 +13,10 @@ gem "rdoc" gem "test-unit" gem "test-unit-ruby-core", git: "https://github.com/ruby/test-unit-ruby-core" -gem "benchmark-driver" +gem "benchmark-driver", require: false + +group :test do + gem "simplecov", require: false + gem "simplecov-html", require: false + gem "simplecov-json", require: false +end diff --git a/test/lib/helper.rb b/test/lib/helper.rb index e84854a5..a03dcd8a 100644 --- a/test/lib/helper.rb +++ b/test/lib/helper.rb @@ -1,3 +1,31 @@ +require "simplecov" + +# Cannot use ".simplecov" file: simplecov-json triggers a circular require. +require "simplecov-json" +SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter, +]) + +SimpleCov.start do + command_name "Net::IMAP tests" + enable_coverage :branch + primary_coverage :branch + enable_coverage_for_eval + + add_filter "/test/" + add_filter "/rakelib/" + + add_group "Parser", %w[lib/net/imap/response_parser.rb + lib/net/imap/response_parser] + add_group "Config", %w[lib/net/imap/config.rb + lib/net/imap/config] + add_group "SASL", %w[lib/net/imap/sasl.rb + lib/net/imap/sasl + lib/net/imap/authenticators.rb] + add_group "StringPrep", %w[lib/net/imap/stringprep.rb + lib/net/imap/stringprep] +end require "test/unit" require "core_assertions"