Skip to content

Commit

Permalink
Merge pull request #43 from grosser/grosser/max
Browse files Browse the repository at this point in the history
allow setting SINGLE_COV_MAX_OUTPUT via env
  • Loading branch information
grosser committed Jun 3, 2023
2 parents 53b2e80 + 9ad1dd9 commit 98909ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/single_cov.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module SingleCov
COVERAGES = []
MAX_OUTPUT = 40
MAX_OUTPUT = Integer(ENV["SINGLE_COV_MAX_OUTPUT"] || "40")
RAILS_APP_FOLDERS = ["models", "serializers", "helpers", "controllers", "mailers", "views", "jobs", "channels"]
UNCOVERED_COMMENT_MARKER = /#.*uncovered/
PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
Expand Down Expand Up @@ -50,7 +50,9 @@ def all_covered?(result)

return true if errors.empty?

errors[MAX_OUTPUT..-1] = "... coverage output truncated" if errors.size >= MAX_OUTPUT
if errors.size >= MAX_OUTPUT
errors[MAX_OUTPUT..-1] = "... coverage output truncated (use SINGLE_COV_MAX_OUTPUT=999 to expand)"
end
@error_logger.puts errors

errors.all? { |l| warning?(l) }
Expand Down
20 changes: 19 additions & 1 deletion specs/single_cov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ def add_missing_coverage(&block)
end
end

describe "with many uncovered" do
around { |test| change_file("lib/a.rb", "1", "return 1 if 1 == 1\n#{100.times.map { "puts 1" }.join("\n")}", &test) }

it "truncates when too many lines are uncovered" do
result = sh "ruby test/a_test.rb", fail: true
assert_tests_finished_normally(result)
expect(result).to include "1 current"
expect(result.count("\n")).to equal 50
end

it "can truncate to custom length for in-depth debugging" do
result = sh "SINGLE_COV_MAX_OUTPUT=60 ruby test/a_test.rb", fail: true
assert_tests_finished_normally(result)
expect(result).to include "1 current"
expect(result.count("\n")).to equal 70
end
end

describe "running in non-root" do
it_does_not_complain_when_everything_is_covered in_test: true

Expand Down Expand Up @@ -114,7 +132,7 @@ def add_missing_coverage(&block)
end
end

describe "when something is uncovered" do
describe "when single item is uncovered" do
around { |block| add_missing_coverage(&block) }

it "complains" do
Expand Down

0 comments on commit 98909ab

Please sign in to comment.