Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Conditionally permit the console display of file covered >= threshold #36

Merged
merged 3 commits into from

2 participants

@TiteiKo

Why ?

Two reasons :

  • First time I used coco, I thought that the issue #35 was real
  • For some people (me included), seing only the wrong is kind of depressing...
  • It's easier to evaluate the overall coverage when what's greatly covered is displayed

So I added a small option to display in green files whose coverage is greater or equal to the threshold

lib/coco/formatter/console_formatter.rb
@@ -33,6 +33,8 @@ def initialize(covered, uncovered)
text = ColoredString.new "#{percentage}% #{filename}"
if percentage <= 50
text.red
+ elsif percentage == 100
@TiteiKo
TiteiKo added a note

this should be threashold, fix comming up

@lkdjiin Owner
lkdjiin added a note

I'll document the threshold argument…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lkdjiin
Owner

Great! I will review this PR ASAP ;)
Thank you.

@lkdjiin lkdjiin commented on the diff
lib/coco.rb
@@ -26,7 +26,7 @@ module Coco
sources = Coco::SourceLister.new(config).list
uncovered = Coco::UncoveredLister.new(sources, result.all_from_domain).list
- cf = Coco::ConsoleFormatter.new(covered, uncovered)
+ cf = Coco::ConsoleFormatter.new(covered, uncovered, config[:threshold])
@lkdjiin Owner
lkdjiin added a note

ok, mea culpa, I would say console_formatter, or maybe console, not cf! WTF, why did I named this variable cf? Sorry ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lkdjiin lkdjiin commented on the diff
lib/coco/cover/coverage_result.rb
@@ -13,9 +13,9 @@ class CoverageResult
# Returns a Hash coverage for sources that are not sufficiently
# covered. More technically, the sources that live in the root
# project folder and for which the coverage percentage is under the
- # threshold.
@lkdjiin Owner
lkdjiin added a note

Thank you to remove all those spaces ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lkdjiin lkdjiin commented on the diff
spec/formatters_spec.rb
((37 lines not shown))
result = formatter.format
result.should == "\e[31m0% a\e[0m\n" +
"\e[31m0% b\e[0m\n" +
"\e[33m80% the/filename/80\e[0m\n" +
"\e[33m90% the/filename/90\e[0m\n" +
- "\e[33m100% the/filename/100\e[0m"
+ "\e[32m100% the/filename/100\e[0m"
+ end
+
+ it "should put in green when >= threshold" do
+ formatter = ConsoleFormatter.new(COVERAGE_100_90_80, ['a', 'b'], 90)
@lkdjiin Owner
lkdjiin added a note

Yes! I'm happy to see a test with your new feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lkdjiin
Owner

:+1:
I really like it, thanks again!
I think I'll merge it this week-end, and may be it's the time for a new release…
Do you want to update the readme with your new feature? Else I'll do it ;)

@lkdjiin lkdjiin merged commit ab5ec3f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/coco.rb
@@ -26,7 +26,7 @@ module Coco
sources = Coco::SourceLister.new(config).list
uncovered = Coco::UncoveredLister.new(sources, result.all_from_domain).list
- cf = Coco::ConsoleFormatter.new(covered, uncovered)
+ cf = Coco::ConsoleFormatter.new(covered, uncovered, config[:threshold])
@lkdjiin Owner
lkdjiin added a note

ok, mea culpa, I would say console_formatter, or maybe console, not cf! WTF, why did I named this variable cf? Sorry ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
puts cf.format(config[:single_line_report])
puts cf.link if config[:show_link_in_terminal]
View
1  lib/coco/configuration.rb
@@ -30,6 +30,7 @@ def initialize
self[:single_line_report] = false
self[:always_run] = true
self[:show_link_in_terminal] = false
+ self[:exclude_above_threshold] = true
if File.exist?('.coco.yml')
self.merge!(YAML.load_file('.coco.yml'))
# Deprecated: Support of '.coco' file will be removed in v1.0.
View
26 lib/coco/cover/coverage_result.rb
@@ -13,9 +13,9 @@ class CoverageResult
# Returns a Hash coverage for sources that are not sufficiently
# covered. More technically, the sources that live in the root
# project folder and for which the coverage percentage is under the
- # threshold.
@lkdjiin Owner
lkdjiin added a note

Thank you to remove all those spaces ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # threshold.
attr_reader :covered_from_domain
-
+
# Public: Initialize a CoverageResult.
#
# config - Hash
@@ -27,29 +27,33 @@ def initialize(config, raw_results)
@result = raw_results
exclude_external_sources
exclude_files_user_dont_want
- exclude_sources_above_threshold
+ if config[:exclude_above_threshold]
+ @covered_from_domain = exclude_sources_above_threshold
+ else
+ @covered_from_domain = @all_from_domain
+ end
end
-
+
private
-
+
def exclude_external_sources
here = Dir.pwd
@all_from_domain = @result.select {|key, value| key.start_with?(here) }
end
-
+
def exclude_files_user_dont_want
return if @exclude_files.nil?
@exclude_files.each do |filename|
@all_from_domain.delete(File.expand_path(filename))
end
end
-
- def exclude_sources_above_threshold
- @covered_from_domain = @all_from_domain.select do |key, value|
+
+ def exclude_sources_above_threshold
+ @all_from_domain.select do |key, value|
CoverageStat.coverage_percent(value) < @threshold
end
end
-
+
end
-
+
end
View
4 lib/coco/formatter/colored_string.rb
@@ -27,6 +27,10 @@ def yellow
colorize "\033[33m"
end
+ def green
+ colorize "\033[32m"
+ end
+
private
def colorize(color_code)
View
6 lib/coco/formatter/console_formatter.rb
@@ -23,8 +23,8 @@ def link
# covered - Hash
# uncovered - Array
- def initialize(covered, uncovered)
@lkdjiin Owner
lkdjiin added a note

I'll document the threshold argument…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- super
+ def initialize(covered, uncovered, threshold)
+ super(covered, uncovered)
@formatted_output = []
compute_percentage
add_percentage_to_uncovered
@@ -33,6 +33,8 @@ def initialize(covered, uncovered)
text = ColoredString.new "#{percentage}% #{filename}"
if percentage <= 50
text.red
+ elsif percentage >= threshold
+ text.green
else
text.yellow
end
View
10 spec/configuration_spec.rb
@@ -46,6 +46,10 @@
@config[:show_link_in_terminal].should be_false
end
+ it "give true for 'exclude_above_threshold'" do
+ @config[:exclude_above_threshold].should be_true
+ end
+
end
@@ -162,6 +166,12 @@ def always_run_as(bool)
config = Configuration.new
config[:single_line_report].should == true
end
+
+ it "should read 'exclude_above_threshold' value from .coco file" do
+ create_config exclude_above_threshold: false
+ config = Configuration.new
+ config[:exclude_above_threshold].should be_false
+ end
end
end
View
21 spec/coverage_result_spec.rb
@@ -21,11 +21,11 @@
it "must refuse negative threshold" do
lambda {CoverageResult.new({:threshold => -1}, RAW_RESULT)}.should raise_error(ArgumentError)
end
-
+
it "must accept threshold above 100%" do
lambda {CoverageResult.new({:threshold => 101}, RAW_RESULT)}.should_not raise_error
end
-
+
it "must exclude external sources" do
result = CoverageResult.new({:threshold => 90}, RAW_RESULT)
good_hash = result.all_from_domain
@@ -33,7 +33,7 @@
good_hash.should == {"#{File.join(Dir.pwd, 'internal/one')}" => [0, 1],
"#{File.join(Dir.pwd, 'internal/two')}" => [0, 1]}
end
-
+
it "must exclude files user don't need" do
config = {:threshold => 90, :excludes => ['internal/two']}
result = CoverageResult.new(config, RAW_RESULT)
@@ -41,12 +41,19 @@
good_hash.size.should == 1
good_hash.should == {"#{File.join(Dir.pwd, 'internal/one')}" => [0, 1]}
end
-
- it "must exclude sources above threshold" do
- result = CoverageResult.new({:threshold => 90}, RAW_RESULT_2)
+
+ it 'can exclude sources above threshold' do
+ result = CoverageResult.new({:threshold => 90, :exclude_above_threshold => true}, RAW_RESULT_2)
good_hash = result.covered_from_domain
good_hash.size.should == 1
good_hash[File.join(Dir.pwd, 'internal/one')].should == [0, 1]
end
-
+
+ it 'can include sources above threshold' do
+ result = CoverageResult.new({:threshold => 90, :exclude_above_threshold => false}, RAW_RESULT_2)
+ good_hash = result.covered_from_domain
+ good_hash.size.should == 2
+ good_hash[File.join(Dir.pwd, 'internal/one')].should == [0, 1]
+ end
+
end
View
28 spec/formatters_spec.rb
@@ -4,52 +4,62 @@
describe ConsoleFormatter do
it "should respond to format" do
- formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'])
+ formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'], 100)
formatter.respond_to?(:format).should == true
end
it "should return percents and filename" do
- formatter = ConsoleFormatter.new(COVERAGE_80, [])
+ formatter = ConsoleFormatter.new(COVERAGE_80, [], 100)
result = formatter.format
result.should == "\e[33m80% the/filename/80\e[0m"
end
it "should return percents and filename and uncovered" do
- formatter = ConsoleFormatter.new(COVERAGE_80, ['a'])
+ formatter = ConsoleFormatter.new(COVERAGE_80, ['a'], 100)
result = formatter.format
result.should == "\e[31m0% a\e[0m\n" +
"\e[33m80% the/filename/80\e[0m"
end
it "should sort by percentage" do
- formatter = ConsoleFormatter.new(COVERAGE_100_90_80, [])
+ formatter = ConsoleFormatter.new(COVERAGE_100_90_80, [], 100)
result = formatter.format
result.should == "\e[33m80% the/filename/80\e[0m\n" +
"\e[33m90% the/filename/90\e[0m\n" +
- "\e[33m100% the/filename/100\e[0m"
+ "\e[32m100% the/filename/100\e[0m"
end
it "should sort by percentage uncovered too" do
- formatter = ConsoleFormatter.new(COVERAGE_100_90_80, ['a', 'b'])
+ formatter = ConsoleFormatter.new(COVERAGE_100_90_80, ['a', 'b'], 100)
result = formatter.format
result.should == "\e[31m0% a\e[0m\n" +
"\e[31m0% b\e[0m\n" +
"\e[33m80% the/filename/80\e[0m\n" +
"\e[33m90% the/filename/90\e[0m\n" +
- "\e[33m100% the/filename/100\e[0m"
+ "\e[32m100% the/filename/100\e[0m"
+ end
+
+ it "should put in green when >= threshold" do
+ formatter = ConsoleFormatter.new(COVERAGE_100_90_80, ['a', 'b'], 90)
@lkdjiin Owner
lkdjiin added a note

Yes! I'm happy to see a test with your new feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ result = formatter.format
+ result.should == "\e[31m0% a\e[0m\n" +
+ "\e[31m0% b\e[0m\n" +
+ "\e[33m80% the/filename/80\e[0m\n" +
+ "\e[32m90% the/filename/90\e[0m\n" +
+ "\e[32m100% the/filename/100\e[0m"
end
context "when 'single_line_report' is true" do
context "and there is some uncovered files" do
it "should return a message" do
- formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'])
+ formatter = ConsoleFormatter.new(COVERAGE_90, ['a', 'b', 'c'], 100)
result = formatter.format true
result.should == "\e[33mSome files are uncovered\e[0m"
end
end
context "and there is no uncovered files" do
it "should return nothing" do
- formatter = ConsoleFormatter.new(COVERAGE_90, [])
+ formatter = ConsoleFormatter.new(COVERAGE_90, [], 100)
result = formatter.format true
result.should == ""
end
Something went wrong with that request. Please try again.