diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f8e9401..1f8f0d2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,6 @@ on: - main - release-* - schedule: - - cron: "0 6 * * *" - workflow_dispatch: inputs: full-matrix: @@ -252,6 +249,7 @@ jobs: run: bundle exec rake test env: SKIP_TLS_TESTS: ${{ matrix.host.OS == 'macos' && 'true' || '' }} + COVERAGE: "1" # Coverage is cheap so we compute it every run # Must run in its own process: the fork guard's precondition is that no # command has been issued yet, which is false inside the shared suite. diff --git a/.simplecov b/.simplecov new file mode 100644 index 00000000..7aea1b75 --- /dev/null +++ b/.simplecov @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# SimpleCov configuration +SimpleCov.configure do + suite = ENV["COV_GROUP"] || "all" + + enable_coverage :branch + primary_coverage :line + command_name "test-#{suite}" + merging true + merge_timeout 3600 + + skip %r{^/test/} + skip %r{^/valkey-glide/} # vendored upstream submodule, not our code + cover "lib/**/*.rb" # includes unloaded lib files and restricts the report to them + + # tracked in https://github.com/valkey-io/valkey-glide-ruby/issues/307 + # reference_config = RUBY_PLATFORM.start_with?("x86_64-linux") && + # RUBY_VERSION.start_with?("3.4") && + # ENV["ENGINE_VERSION"] == "9.0" + + # cluster runs last, so its report is the merge of all three suites. + project_total = suite == "cluster" + + if reference_config && project_total + minimum_coverage line: 80, branch: 70 + end +end diff --git a/DEVELOPER.md b/DEVELOPER.md index 6bfe90dd..3a272d9a 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -77,6 +77,21 @@ bundle exec rake test:standalone python3 valkey-glide/utils/cluster_manager.py --tls stop --prefix tls-standalone ``` +## Test Coverage + +We measure both **line coverage** and **branch coverage** with [SimpleCov](https://github.com/simplecov-ruby/simplecov). Coverage is opt-in via the `COVERAGE` environment variable; when set, the test suite writes an HTML report to `coverage/index.html` and a machine-readable summary to `coverage/.last_run.json`. The `coverage/` directory is gitignored. + +```bash +# Standalone only +COVERAGE=1 bundle exec rake test:standalone + +# Full suite (standalone + cluster) +COVERAGE=1 bundle exec rake test + +# Coverage report (MacOS) +open coverage/index.html +``` + ## RuboCop ```bash diff --git a/Gemfile b/Gemfile index 5791dea2..3bda9639 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,10 @@ gem "irb" if RUBY_VERSION >= "4.0" gem "rake", "~> 13.0" -gem "minitest", "~> 5.16" - -gem "minitest-reporters", "~> 1.4" - gem "rubocop", "~> 1.21" + +group :test do + gem "minitest", "~> 5.16" + gem "minitest-reporters", "~> 1.4" + gem "simplecov", "~> 1.1" if RUBY_VERSION >= "3.2" +end diff --git a/README.md b/README.md index f411c4b1..b7b64f1f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Valkey GLIDE for Ruby +[![CI](https://github.com/valkey-io/valkey-glide-ruby/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/valkey-io/valkey-glide-ruby/actions/workflows/ci.yml?query=branch%3Amain) +[![Gem Version](https://img.shields.io/gem/v/valkey-glide-rb.svg)](https://rubygems.org/gems/valkey-glide-rb) +[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/valkey-io/valkey-glide-ruby/blob/main/LICENSE) + Valkey General Language Independent Driver for the Enterprise (GLIDE) is the official open-source Valkey client library, part of the [Valkey](https://valkey.io) organization. The Ruby gem (`valkey-glide-rb`) wraps [Valkey GLIDE Core](https://github.com/valkey-io/valkey-glide), giving Ruby applications the performance and reliability of the GLIDE core. ## Features diff --git a/Rakefile b/Rakefile index 2fec2c6e..54ad432b 100644 --- a/Rakefile +++ b/Rakefile @@ -117,6 +117,12 @@ namespace :test do cluster: "integration/cluster" } groups.each do |group, dir| + # Set the COV_GROUP environment variable for the test group task, so that + # SimpleCov can use it to determine the coverage group. + task "cov_group_#{group}" do + ENV["COV_GROUP"] = group.to_s + end + Rake::TestTask.new(group) do |t| t.libs << "test" # Only add local lib to load path when not testing installed gem @@ -124,6 +130,8 @@ namespace :test do t.test_files = FileList["test/#{dir}/**/*_test.rb"] t.options = '-v' if ENV['CI'] || ENV['VERBOSE'] end + + Rake::Task["test:#{group}"].enhance(["test:cov_group_#{group}"]) end # Exclude module directories (integration/valkey/, lint/) from lost_tests check diff --git a/test/test_helper.rb b/test/test_helper.rb index c97fec68..4af16d3e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,13 @@ # This is useful for CD testing to verify the published gem works correctly $LOAD_PATH.unshift File.expand_path("../lib", __dir__) unless ENV["TEST_INSTALLED_GEM"] +# We use SimpleCov expected_coverage option, which requires SimpleCov 1.0 which needs +# Ruby 3.2. Enable for Ruby 3.0 and 3.1 once coverage reaches 80%. +if ENV["COVERAGE"] && RUBY_VERSION >= "3.2" + require "simplecov" + SimpleCov.start +end + require "valkey" require_relative "support/test_cluster"