Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ jobs:
# Git Bash rewrites `//spec:add` into `/spec:add` on Windows.
MSYS_NO_PATHCONV: 1
run: |
bazel coverage //spec:add
# //spec:plain has no bundle and must still pass under coverage.
bazel coverage //spec:add //spec:plain
COVERAGE_FILE=bazel-testlogs/spec/add/coverage.dat
if ! grep -q "SF:.*lib/gem/add.rb" "$COVERAGE_FILE"; then
echo "Error: Coverage report does not contain expected file coverage"
Expand Down
8 changes: 8 additions & 0 deletions examples/gem/spec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ rb_test(
deps = [":spec_helper"],
)

rb_test(
name = "plain",
size = "small",
timeout = "moderate", # JRuby startup can be slow
srcs = ["plain_test.rb"],
main = "plain_test.rb",
)

rb_library(
name = "env_spec",
srcs = ["env_spec.rb"],
Expand Down
4 changes: 4 additions & 0 deletions examples/gem/spec/plain_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

# Has no Bundler dependency, so `bazel coverage` runs it without BUNDLE_GEMFILE.
puts 'ok'
12 changes: 11 additions & 1 deletion ruby/private/coverage/rules_ruby_coverage.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# frozen_string_literal: true

if ENV['COVERAGE'] == '1'
# Targets without a bundle have no BUNDLE_GEMFILE. Bundler would then look
# for a Gemfile above the working directory and raise an error that
# `rescue LoadError` does not catch.
if ENV['BUNDLE_GEMFILE']
begin
require 'bundler/setup'
rescue StandardError, LoadError => e
warn "Coverage enabled but Bundler setup failed: #{e.message}"
end
end

begin
require 'bundler/setup'
require 'simplecov'
require 'simplecov-lcov'

Expand Down
Loading