Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always round numbers down, never up #146

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.rvmrc
.bundle
/tmp

## MAC OS
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ AllCops:
DisplayCopNames: true
NewCops: enable
TargetRubyVersion: 2.5
Exclude:
- "test/fixtures/*"
- "tmp/**/*"
- "vendor/**/*"
- ".git/**/*"

Bundler/DuplicatedGem:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group :test do
end

group :development do
gem "nokogiri"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-performance"
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ GEM
json (2.7.2-java)
language_server-protocol (3.17.0.3)
logger (1.6.1)
mini_portile2 (2.8.8)
minitest (5.25.1)
nokogiri (1.18.1)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -73,13 +77,13 @@ GEM
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-22
ruby
universal-java-1.8

DEPENDENCIES
logger
minitest
nokogiri
rake (>= 11)
rubocop
rubocop-minitest
Expand Down
5 changes: 3 additions & 2 deletions lib/simplecov-html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def line_status?(source_file, line)

def output_message(result)
output = "Coverage report generated for #{result.command_name} to #{output_path}."
output += "\nLine Coverage: #{result.covered_percent.round(2)}% (#{result.covered_lines} / #{result.total_lines})"
output += "\nBranch Coverage: #{result.coverage_statistics[:branch].percent.round(2)}% (#{result.covered_branches} / #{result.total_branches})" if branchable_result?
output += "\nLine Coverage: #{result.covered_percent.floor(2)}% (#{result.covered_lines} / #{result.total_lines})"

output += "\nBranch Coverage: #{result.coverage_statistics[:branch].percent.floor(2)}% (#{result.covered_branches} / #{result.total_branches})" if branchable_result?
output
end

Expand Down
50 changes: 50 additions & 0 deletions test/fixtures/branch_tester_script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Adapted from https://github.com/simplecov-ruby/simplecov/pull/694#issuecomment-562097006
# rubocop:disable all
x = 1
x.eql?(4) ? "4" : x

puts x unless x.eql?(5)

unless x == 5
puts "Ola.."
end

unless x != 5
puts "Ola.."
end

unless x != 5
puts "Ola.."
else
puts "text"
end

puts x if x.eql?(5)
if x != 5
puts "Ola.."
end

if x == 5
puts "Ola.."
end

if x != 5
puts "Ola.."
else
puts "text"
end
x = 4
if x == 1
puts "wow 1"
puts "such excite!"
elsif x == 4
4.times { puts "4!!!!"}
elsif x == 14
puts "magic"

puts "very"
else
puts x
end

# rubocop:enable all
13 changes: 13 additions & 0 deletions test/fixtures/branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Branches
def call(arg)
return if arg < 0

_val = (arg == 42 ? :yes : :no)

if arg.odd?
:yes
else
:no
end
end
end
14 changes: 14 additions & 0 deletions test/fixtures/case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Case
def self.call(arg)
case arg
when 0...23
:foo
when 40..50
:bar
when Integer
:baz
else
:nope
end
end
end
12 changes: 12 additions & 0 deletions test/fixtures/case_without_else.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Case
def self.call(arg)
case arg
when 0...23
:foo
when 40..50
:bar
when Integer
:baz
end
end
end
13 changes: 13 additions & 0 deletions test/fixtures/elsif.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Elsif
def self.call(arg)
if arg.odd?
:odd
elsif arg == 30
:mop
elsif arg == 42
:yay
else
:nay
end
end
end
13 changes: 13 additions & 0 deletions test/fixtures/inline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Inline
def call(arg)
String(arg == 42 ? :yes : :no)

String(
if arg.odd?
:yes
else
:no
end
)
end
end
15 changes: 15 additions & 0 deletions test/fixtures/nested_branches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yes rubocop you are right but I want to test nesting!
# rubocop:disable Metrics/BlockNesting
module NestedBranches
def self.call(arg)
if arg.even?
if arg == 42
arg -= 1 while arg > 40
:ok
end
else
:nope
end
end
end
# rubocop:enable Metrics/BlockNesting
2 changes: 2 additions & 0 deletions test/fixtures/never.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This class is purely some
# comments
27 changes: 27 additions & 0 deletions test/fixtures/nocov_complex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# So much skippping
# rubocop:disable Metrics/MethodLength
module NoCovComplex
def self.call(arg)
# :nocov:
if arg == 42
0
# :nocov:
else
puts "yolo"
end

arg += 1 if arg.odd?

# :nocov:
arg -= 1 while arg > 40

case arg
when 1..20
:nope
# :nocov:
when 30..40
:yas
end
end
end
# rubocop:enable Metrics/MethodLength
16 changes: 16 additions & 0 deletions test/fixtures/sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Foo class
class Foo
def initialize
@foo = "baz"
end

def bar
@foo
end

# :nocov:
def skipped
@foo * 2
end
# :nocov:
end
14 changes: 14 additions & 0 deletions test/fixtures/single_nocov.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# :nocov:
module SingleNocov
def self.call(arg)
if arg.odd?
:odd
elsif arg == 30
:mop
elsif arg == 42
:yay
else
:nay
end
end
end
16 changes: 16 additions & 0 deletions test/fixtures/uneven_nocovs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module UnevenNocov
def self.call(arg)
# :nocov:
if arg.odd?
:odd
elsif arg == 30
:mop
# :nocov:
elsif arg == 42
:yay
# :nocov:
else
:nay
end
end
end
3 changes: 3 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
require "simplecov"
require "simplecov-html"
require "minitest/autorun"

require "pathname"
require "nokogiri"
Loading
Loading