Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 523 lines (435 sloc) 16.71 kb
b0e887d @mfp Initial commit.
mfp authored
1 #!/usr/bin/env ruby
bbf8853 fFxes No file to analyze was found errorr. Taken from @valo.
Aaron Bedra authored
2 # -*- coding: iso-8859-1 -*-
55975a7 @mfp bin/rcov: Moved xx to rcov's DATA area. Updated legal info.
mfp authored
3 # rcov Copyright (c) 2004-2006 Mauricio Fernandez <mfp@acm.org>
4 #
5 # rcov originally based on
b0e887d @mfp Initial commit.
mfp authored
6 # module COVERAGE__ originally (c) NAKAMURA Hiroshi
7 # module PrettyCoverage originally (c) Simon Strandgaard
8 #
61b9661 @mfp bin/rcov: added email address, simplified name.
mfp authored
9 # rewritten & extended by Mauricio Fernández <mfp@acm.org>
b0e887d @mfp Initial commit.
mfp authored
10 #
55975a7 @mfp bin/rcov: Moved xx to rcov's DATA area. Updated legal info.
mfp authored
11 # See LEGAL and LICENSE for additional licensing information.
b0e887d @mfp Initial commit.
mfp authored
12 #
13 require 'cgi'
14 require 'rbconfig'
15 require 'optparse'
16 require 'ostruct'
17
18 SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
3a2a6fd @mfp bin/rcov, lib/rcov.rb, lib/rcov/lowlevel.rb, lib/rcov/version.rb: major ...
mfp authored
19 require 'rcov/version'
e9d50bf @spicycode Starting the formatter cleanup, adding them into separate files. Two t...
spicycode authored
20 require 'rcov/formatters'
878ac3d @mfp bin/rcov (main, RCOV__, CodeCoverageAnalyzer), test/test_CodeCoverageAna...
mfp authored
21
04bb7ee @mfp bin/rcov (HTMLCoverage, HTMLProfiling, TextReport, TextSummary, TextCove...
mfp authored
22 #{{{ "main" code
b0e887d @mfp Initial commit.
mfp authored
23 options = OpenStruct.new
24 options.color = true
25 options.range = 30.0
26 options.profiling = false
27 options.destdir = nil
28 options.loadpaths = []
f491d2a @mfp bin/rcov: implemented the plaintext (-t) and rich text (-T) modes.
mfp authored
29 options.textmode = false
e9d50bf @spicycode Starting the formatter cleanup, adding them into separate files. Two t...
spicycode authored
30 options.skip = Rcov::BaseFormatter::DEFAULT_OPTS[:ignore]
a9d119a @mfp bin/rcov (main, Formatter#add_file, #initialize): implemented --include-...
mfp authored
31 options.include = []
d130d3d @mfp bin/rcov: turned --no-html into --[no-]html.
mfp authored
32 options.html = true
3f399ef Support for new command-line option --css which allows user to specify a...
Corey authored
33 options.css = nil
d9b9026 @mfp bin/rcov, lib/rcov.rb (FileStatistics#initialize), lib/rcov/report.rb (F...
mfp authored
34 options.comments_run_by_default = false
bd1ce53 @mfp bin/rcov, ext/rcovrt/rcov.c: --test-unit-only, ABI checks and minor refa...
mfp authored
35 options.test_unit_only = false
dd535c5 @mfp bin/rcov, CHANGES: implemented --spec-only.
mfp authored
36 options.spec_only = false
93ec3b9 @mfp bin/rcov (Formatter, main), CHANGES: implemented --sort and --sort-rever...
mfp authored
37 options.sort = :name
38 options.sort_reverse = false
c57b2d0 @mfp bin/rcov (Formatter#sorted_file_pairs, main): implemented --threshold an...
mfp authored
39 options.output_threshold = 101
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
40 options.failure_threshold = nil
3df4fac @mfp bin/rcov (main): implemented --replace-progname; disabled by default.
mfp authored
41 options.replace_prog_name = false
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
42 options.callsites = false
c1f3f6e @mfp lib/rcov/report.rb (Formatter#reverse_cross_references_for, HTMLCoverage...
mfp authored
43 options.crossrefs = false
3a3ca70 @mfp bin/rcov (TextCoverageDiff, main): implemented --text-coverage-diff and ...
mfp authored
44 options.coverage_diff_file = "coverage.info"
45 options.coverage_diff_mode = :compare
39397de @mfp bin/rcov: --save can be used with any text formatter but --text-coverage...
mfp authored
46 options.coverage_diff_save = false
3a3ca70 @mfp bin/rcov (TextCoverageDiff, main): implemented --text-coverage-diff and ...
mfp authored
47 options.diff_cmd = "diff"
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
48 options.report_cov_bug_for = nil
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
49 options.aggregate_file = nil
e2a3687 @rubikitch combine -D with --gcc
rubikitch authored
50 options.gcc_output = false
eb3ccbb @mfp lib/rcov/report.rb, bin/rcov: implemented --charset.
mfp authored
51 options.charset = nil
b0e887d @mfp Initial commit.
mfp authored
52
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
53 EXTRA_HELP = <<-EOF
54
55 You can run several programs at once:
56 rcov something.rb somethingelse.rb
57
58 The parameters to be passed to the program under inspection can be specified
59 after --:
60
61 rcov -Ilib -t something.rb -- --theseopts --are --given --to --something.rb
62
3df4fac @mfp bin/rcov (main): implemented --replace-progname; disabled by default.
mfp authored
63 ARGV will be set to the specified parameters after --.
64 Keep in mind that all the programs are run under the same process
07d4fb5 @mfp bin/rcov: indicate that all programs share the same process in the helpm...
mfp authored
65 (i.e. they just get Kernel#load()'ed in sequence).
3df4fac @mfp bin/rcov (main): implemented --replace-progname; disabled by default.
mfp authored
66
67 $PROGRAM_NAME (aka. $0) will be set before each file is load()ed if
68 --replace-progname is used.
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
69 EOF
70
3d8121c @spicycode Deprecate test-unit/spec-only modes
spicycode authored
71 def deprecated(opt)
72 puts "#{opt} is now depricated. Please remove it from you Rakefile or scripts. It will be removed in the next release."
73 end
74
1deb495 @mfp bin/rcov (main): reworked command line options. Changed -t and -T.
mfp authored
75 #{{{ OptionParser
b0e887d @mfp Initial commit.
mfp authored
76 opts = OptionParser.new do |opts|
77 opts.banner = <<-EOF
78 rcov #{Rcov::VERSION} #{Rcov::RELEASE_DATE}
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
79 Usage: rcov [options] <script1.rb> [script2.rb] [-- --extra-options]
b0e887d @mfp Initial commit.
mfp authored
80 EOF
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
81 opts.separator ""
82 opts.separator "Options:"
490d1f4 @spicycode Cleaning up bin script
spicycode authored
83
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
84 opts.on("-o", "--output PATH", "Destination directory.") do |dir|
85 options.destdir = dir
86 end
87
88 opts.on("-I", "--include PATHS", "Prepend PATHS to $: (colon separated list)") do |paths|
89 options.loadpaths = paths.split(/:/)
90 end
91
92 opts.on("--[no-]comments", "Mark all comments by default.", "(default: --no-comments)") do |comments_run_p|
93 options.comments_run_by_default = comments_run_p
94 end
95
96 opts.on("--test-unit-only", "Only trace code executed inside TestCases.") do
97 deprecated("--test-unit-only")
98 end
99
100 opts.on("--spec-only", "Only trace code executed inside RSpec specs.") do
101 deprecated("--spec-only")
102 end
103
104 opts.on("-n", "--no-color", "Create colorblind-safe output.") do
105 options.color = false
106 end
107
108 opts.on("-i", "--include-file PATTERNS",
109 "Generate info for files matching a",
110 "pattern (comma-separated regexp list)") do |list|
111 begin
112 regexps = list.split(/,/).map{|x| Regexp.new(x) }
113 options.include += regexps
114 rescue RegexpError => e
115 raise OptionParser::InvalidArgument, e.message
b0e887d @mfp Initial commit.
mfp authored
116 end
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
117 end
118
119 opts.on("-x", "--exclude PATTERNS", "Don't generate info for files matching a","pattern (comma-separated regexp list)") do |list|
120 begin
121 regexps = list.split(/,/).map{|x| Regexp.new x}
490d1f4 @spicycode Cleaning up bin script
spicycode authored
122 options.skip += regexps
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
123 rescue RegexpError => e
490d1f4 @spicycode Cleaning up bin script
spicycode authored
124 raise OptionParser::InvalidArgument, e.message
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
125 end
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
126 end
127
128 opts.on("--exclude-only PATTERNS", "Skip info only for files matching the", "given patterns.") do |list|
129 begin
130 options.skip = list.split(/,/).map{|x| Regexp.new(x) }
131 rescue RegexpError => e
132 raise OptionParser::InvalidArgument, e.message
b0e887d @mfp Initial commit.
mfp authored
133 end
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
134 end
135
136 opts.on("--rails", "Skip config/, environment/ and vendor/.") do
137 options.skip.concat [%r{\bvendor/},%r{\bconfig/},%r{\benvironment/}]
138 end
139
140 opts.on("--[no-]callsites", "Show callsites in generated XHTML report.", "(somewhat slower; disabled by default)") do |val|
141 options.callsites = val
142 end
143
144 opts.on("--[no-]xrefs", "Generate fully cross-referenced report.", "(includes --callsites)") do |val|
145 options.crossrefs = val
146 options.callsites ||= val
147 end
148
149 opts.on("-p", "--profile", "Generate bogo-profiling info.") do
150 options.profiling = true
151 options.destdir ||= "profiling"
152 end
153
154 opts.on("-r", "--range RANGE", Float, "Color scale range for profiling info (dB).") do |val|
490d1f4 @spicycode Cleaning up bin script
spicycode authored
155 options.range = val
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
156 end
157
158 opts.on("-a", "--annotate", "Generate annotated source code.") do
159 options.html = false
160 options.textmode = :annotate
161 options.crossrefs = true
162 options.callsites = true
163 options.skip = [ %r!/test/unit/! ]
164 end
165
166 opts.on("-T", "--text-report", "Dump detailed plain-text report to stdout.", "(filename, LoC, total lines, coverage)") do
167 options.textmode = :report
168 end
169
170 opts.on("-t", "--text-summary", "Dump plain-text summary to stdout.") do
171 options.textmode = :summary
172 end
173
174 opts.on("--text-counts", "Dump execution counts in plaintext.") do
175 options.textmode = :counts
176 end
177
178 opts.on("--text-coverage", "Dump coverage info to stdout, using", "ANSI color sequences unless -n.") do
179 options.textmode = :coverage
180 end
181
182 opts.on("--gcc", "Dump uncovered line in GCC error format.") do
183 options.gcc_output = true
184 end
185
186 opts.on("--aggregate FILE", "Aggregate data from previous runs",
187 "in FILE. Overwrites FILE with the",
188 "merged data. FILE is created if",
189 "necessary.") do |file|
190 options.aggregate_file = file
191 end
192
193 opts.on("-D [FILE]", "--text-coverage-diff [FILE]",
194 "Compare code coverage with saved state",
195 "in FILE, defaults to coverage.info.",
196 "Implies --comments.") do |file|
197 options.textmode = :coverage_diff
198 options.comments_run_by_default = true
199 if options.coverage_diff_save
200 raise "You shouldn't use --save and --text-coverage-diff at a time."
201 end
202 options.coverage_diff_mode = :compare
203 options.coverage_diff_file = file if file && !file.empty?
204 end
205
206 opts.on("--save [FILE]", "Save coverage data to FILE,", "for later use with rcov -D.", "(default: coverage.info)") do |file|
207 options.coverage_diff_save = true
208 options.coverage_diff_mode = :record
209 if options.textmode == :coverage_diff
210 raise "You shouldn't use --save and --text-coverage-diff at a time."
211 end
212 options.coverage_diff_file = file if file && !file.empty?
213 end
214
215 opts.on("--[no-]html", "Generate HTML output.", "(default: --html)") do |val|
216 options.html = val
217 end
218
3f399ef Support for new command-line option --css which allows user to specify a...
Corey authored
219 opts.on("--css relative/path/to/custom.css", "Use a custom CSS file for HTML output.", "Specified as a relative path.") do |val|
220 options.css = val
221 end
222
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
223 opts.on("--sort CRITERION", [:name, :loc, :coverage], "Sort files in the output by the specified", "field (name, loc, coverage)") do |criterion|
224 options.sort = criterion
225 end
226
227 opts.on("--sort-reverse", "Reverse files in the output.") do
228 options.sort_reverse = true
229 end
230
231 opts.on("--threshold INT", "Only list files with coverage < INT %.", "(default: 101)") do |threshold|
232 begin
233 threshold = Integer(threshold)
234 raise if threshold <= 0 || threshold > 101
235 rescue Exception
236 raise OptionParser::InvalidArgument, threshold
237 end
238 options.output_threshold = threshold
239 end
240
241 opts.on("--failure-threshold [INT]", "Fail if the coverage is below the threshold", "(default: 100)") do |threshold|
242 options.failure_threshold = (threshold || 100).to_i
243 options.textmode = :failure_report
244 end
86bcabd @spicycode Removing validator links options
spicycode authored
245
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
246 opts.on("--charset CHARSET", "Charset used in Content-Type declaration of HTML reports.") do |c|
247 options.charset = c
248 end
249
250 opts.on("--only-uncovered", "Same as --threshold 100") do
251 options.output_threshold = 100
252 end
253
254 opts.on("--replace-progname", "Replace $0 when loading the .rb files.") do
255 options.replace_prog_name = true
256 end
257
258 opts.on("-w", "Turn warnings on (like ruby).") do
259 $VERBOSE = true
260 end
261
262 opts.on("--no-rcovrt", "Do not use the optimized C runtime.", "(will run 30-300 times slower)") do
263 $rcov_do_not_use_rcovrt = true
264 end
265
266 opts.on("--diff-cmd PROGNAME", "Use PROGNAME for --text-coverage-diff.",
267 "(default: diff)") do |cmd|
268 options.diff_cmd = cmd
269 end
270
271 opts.separator ""
272
273 opts.on_tail("-h", "--help", "Show extended help message") do
274 require 'pp'
275 puts opts
276 puts <<EOF
efe60cf @mfp bin/rcov (Formatter, main): also ignore vendor/, show ignored files in h...
mfp authored
277
278 Files matching any of the following regexps will be omitted in the report(s):
279 #{PP.pp(options.skip, "").chomp}
280 EOF
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
281 puts EXTRA_HELP
282 exit
283 end
284
285 opts.on_tail("--report-cov-bug SELECTOR", "Report coverage analysis bug for the",
286 "method specified by SELECTOR", "(format: Foo::Bar#method, A::B.method)") do |selector|
287 case selector
288 when /([^.]+)(#|\.)(.*)/ then options.report_cov_bug_for = selector
289 else
290 raise OptionParser::InvalidArgument, selector
291 end
292 options.textmode = nil
293 options.html = false
294 options.callsites = true
295 end
296 opts.on_tail("--version", "Show version") do
297 puts "rcov " + Rcov::VERSION + " " + Rcov::RELEASE_DATE
298 exit
299 end
b0e887d @mfp Initial commit.
mfp authored
300 end
301
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
302 $ORIGINAL_ARGV = ARGV.clone
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
303 if (idx = ARGV.index("--"))
490d1f4 @spicycode Cleaning up bin script
spicycode authored
304 extra_args = ARGV[idx+1..-1]
305 ARGV.replace(ARGV[0,idx])
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
306 else
490d1f4 @spicycode Cleaning up bin script
spicycode authored
307 extra_args = []
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
308 end
309
534b1fa @mfp bin/rcov: detect invalid command-line options and output usage info.
mfp authored
310 begin
490d1f4 @spicycode Cleaning up bin script
spicycode authored
311 opts.parse! ARGV
312 rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument => e
313 puts opts
314 puts
315 puts e.message
316 exit(-1)
534b1fa @mfp bin/rcov: detect invalid command-line options and output usage info.
mfp authored
317 end
490d1f4 @spicycode Cleaning up bin script
spicycode authored
318
b0e887d @mfp Initial commit.
mfp authored
319 options.destdir ||= "coverage"
4465832 @mfp bin/rcov: allow to run rcov against a data file with no input code.
mfp authored
320 unless ARGV[0] or options.aggregate_file && File.file?(options.aggregate_file)
490d1f4 @spicycode Cleaning up bin script
spicycode authored
321 puts opts
322 exit
b0e887d @mfp Initial commit.
mfp authored
323 end
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
324
325 # {{{ set loadpath
326 options.loadpaths.reverse_each{|x| $:.unshift x}
327
328 #{{{ require 'rcov': do it only now in order to be able to run rcov on itself
329 # since we need to set $: before.
330
331 require 'rcov'
332
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
333 options.callsites = true if options.report_cov_bug_for
e2a3687 @rubikitch combine -D with --gcc
rubikitch authored
334 options.textmode = :gcc if !options.textmode and options.gcc_output
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
335
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
336 def rcov_load_aggregate_data(file)
490d1f4 @spicycode Cleaning up bin script
spicycode authored
337 require 'zlib'
338 begin
339 old_data = nil
340 Zlib::GzipReader.open(file){|gz| old_data = Marshal.load(gz) }
341 rescue
342 old_data = {}
343 end
344 old_data || {}
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
345 end
346
347 def rcov_save_aggregate_data(file)
e9d50bf @spicycode Starting the formatter cleanup, adding them into separate files. Two t...
spicycode authored
348 require 'zlib'
349 Zlib::GzipWriter.open(file) do |f|
350 Marshal.dump({:callsites => $rcov_callsite_analyzer, :coverage => $rcov_code_coverage_analyzer}, f)
351 end
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
352 end
353
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
354 if options.callsites
490d1f4 @spicycode Cleaning up bin script
spicycode authored
355 if options.aggregate_file
356 saved_aggregate_data = rcov_load_aggregate_data(options.aggregate_file)
357 if saved_aggregate_data[:callsites]
358 $rcov_callsite_analyzer = saved_aggregate_data[:callsites]
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
359 end
490d1f4 @spicycode Cleaning up bin script
spicycode authored
360 end
361 $rcov_callsite_analyzer ||= Rcov::CallSiteAnalyzer.new
362 $rcov_callsite_analyzer.install_hook
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
363 else
490d1f4 @spicycode Cleaning up bin script
spicycode authored
364 $rcov_callsite_analyzer = nil
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
365 end
366
367 # {{{ create formatters
04bb7ee @mfp bin/rcov (HTMLCoverage, HTMLProfiling, TextReport, TextSummary, TextCove...
mfp authored
368 formatters = []
369 make_formatter = lambda do |klass|
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
370 klass.new(:destdir => options.destdir, :color => options.color,
371 :fsr => options.range, :textmode => options.textmode,
372 :ignore => options.skip, :dont_ignore => options.include,
d9b9026 @mfp bin/rcov, lib/rcov.rb (FileStatistics#initialize), lib/rcov/report.rb (F...
mfp authored
373 :sort => options.sort,
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
374 :sort_reverse => options.sort_reverse,
375 :output_threshold => options.output_threshold,
3a3ca70 @mfp bin/rcov (TextCoverageDiff, main): implemented --text-coverage-diff and ...
mfp authored
376 :callsite_analyzer => $rcov_callsite_analyzer,
377 :coverage_diff_mode => options.coverage_diff_mode,
378 :coverage_diff_file => options.coverage_diff_file,
c1f3f6e @mfp lib/rcov/report.rb (Formatter#reverse_cross_references_for, HTMLCoverage...
mfp authored
379 :callsites => options.callsites,
380 :cross_references => options.crossrefs,
d9b9026 @mfp bin/rcov, lib/rcov.rb (FileStatistics#initialize), lib/rcov/report.rb (F...
mfp authored
381 :diff_cmd => options.diff_cmd,
e2a3687 @rubikitch combine -D with --gcc
rubikitch authored
382 :comments_run_by_default => options.comments_run_by_default,
9ca71db @mfp lib/rcov/report.rb, bin/rcov: implemented --[no-]validator-links.
mfp authored
383 :gcc_output => options.gcc_output,
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
384 :charset => options.charset,
3f399ef Support for new command-line option --css which allows user to specify a...
Corey authored
385 :css => options.css,
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
386 :failure_threshold => options.failure_threshold
3a3ca70 @mfp bin/rcov (TextCoverageDiff, main): implemented --text-coverage-diff and ...
mfp authored
387 )
b0e887d @mfp Initial commit.
mfp authored
388 end
389
d130d3d @mfp bin/rcov: turned --no-html into --[no-]html.
mfp authored
390 if options.html
490d1f4 @spicycode Cleaning up bin script
spicycode authored
391 if options.profiling
392 formatters << make_formatter[Rcov::HTMLProfiling]
393 else
394 formatters << make_formatter[Rcov::HTMLCoverage]
395 end
04bb7ee @mfp bin/rcov (HTMLCoverage, HTMLProfiling, TextReport, TextSummary, TextCove...
mfp authored
396 end
490d1f4 @spicycode Cleaning up bin script
spicycode authored
397
398 textual_formatters = { :counts => Rcov::FullTextReport, :coverage => Rcov::FullTextReport,
399 :gcc => Rcov::FullTextReport, :annotate => Rcov::RubyAnnotation,
3a3ca70 @mfp bin/rcov (TextCoverageDiff, main): implemented --text-coverage-diff and ...
mfp authored
400 :summary => Rcov::TextSummary, :report => Rcov::TextReport,
265e849 adding failure-threshold option to make verifying coverage a breeze
Aaron Bedra authored
401 :coverage_diff => Rcov::TextCoverageDiff, :failure_report => Rcov::FailureReport }
b0e887d @mfp Initial commit.
mfp authored
402
04bb7ee @mfp bin/rcov (HTMLCoverage, HTMLProfiling, TextReport, TextSummary, TextCove...
mfp authored
403 if textual_formatters[options.textmode]
490d1f4 @spicycode Cleaning up bin script
spicycode authored
404 formatters << make_formatter[textual_formatters[options.textmode]]
04bb7ee @mfp bin/rcov (HTMLCoverage, HTMLProfiling, TextReport, TextSummary, TextCove...
mfp authored
405 end
3a2a6fd @mfp bin/rcov, lib/rcov.rb, lib/rcov/lowlevel.rb, lib/rcov/version.rb: major ...
mfp authored
406
680b75f modifying the formatters checking logic for ensuring that the failur_rep...
Jay authored
407
408 if options.failure_threshold.nil? == false && options.textmode != :failure_report
409 formatters << make_formatter[textual_formatters[:failure_report]]
410 end
411
39397de @mfp bin/rcov: --save can be used with any text formatter but --text-coverage...
mfp authored
412 formatters << make_formatter[Rcov::TextCoverageDiff] if options.coverage_diff_save
413
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
414 if options.aggregate_file
490d1f4 @spicycode Cleaning up bin script
spicycode authored
415 saved_aggregate_data ||= rcov_load_aggregate_data(options.aggregate_file)
416 if saved_aggregate_data[:coverage]
417 $rcov_code_coverage_analyzer = saved_aggregate_data[:coverage]
418 end
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
419 end
490d1f4 @spicycode Cleaning up bin script
spicycode authored
420
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
421 $rcov_code_coverage_analyzer ||= Rcov::CodeCoverageAnalyzer.new
878ac3d @mfp bin/rcov (main, RCOV__, CodeCoverageAnalyzer), test/test_CodeCoverageAna...
mfp authored
422
bd1ce53 @mfp bin/rcov, ext/rcovrt/rcov.c: --test-unit-only, ABI checks and minor refa...
mfp authored
423 # must be registered before test/unit puts its own
f6a3558 @mfp bin/rcov: rethrow exceptions generated by traced scripts (patch by Kurt ...
mfp authored
424
425
426 # The exception to rethrow after reporting has been handled.
427 $__rcov_exit_exception = nil
428
bd1ce53 @mfp bin/rcov, ext/rcovrt/rcov.c: --test-unit-only, ABI checks and minor refa...
mfp authored
429 END {
878ac3d @mfp bin/rcov (main, RCOV__, CodeCoverageAnalyzer), test/test_CodeCoverageAna...
mfp authored
430 $rcov_code_coverage_analyzer.remove_hook
ba355d5 @mfp bin/rcov (Formatter, HTMLCoverage, main): implemented --callsites.
mfp authored
431 $rcov_callsite_analyzer.remove_hook if $rcov_callsite_analyzer
4c2cd8c @mfp bin/rcov: implemented --aggregate.
mfp authored
432 rcov_save_aggregate_data(options.aggregate_file) if options.aggregate_file
878ac3d @mfp bin/rcov (main, RCOV__, CodeCoverageAnalyzer), test/test_CodeCoverageAna...
mfp authored
433 $rcov_code_coverage_analyzer.dump_coverage_info(formatters)
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
434 if options.report_cov_bug_for
435 defsite = $rcov_callsite_analyzer.defsite(options.report_cov_bug_for)
436 if !defsite
437 $stderr.puts <<-EOF
438 Couldn't find definition site of #{options.report_cov_bug_for}.
439 Was it executed at all?
440 EOF
441 exit(-1)
442 end
443 lines, mark_info, count_info = $rcov_code_coverage_analyzer.data(defsite.file)
444 puts <<EOF
445
446 Please fill in the blanks in the following report.
447
6d480d0 @spicycode Release 0.8.3.0
spicycode authored
448
449 You can post bugs to
450 http://github.com/relevance/rcov/issues
0f61cb1 @mfp bin/rcov: implemented --report-cov-bug.
mfp authored
451
452 Thank you!
453
454 =============================================================================
455 Bug report generated on #{Time.new}
456
457 Ruby version: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})
458 Platform: #{RUBY_PLATFORM}
459 rcov version: #{Rcov::VERSION}
460 rcovrt loaded? #{$".any?{|x| /\brcovrt\b/ =~ x} }
461 using RubyGems? #{$".any?{|x| /\brubygems\b/ =~ x} }
462 Command-line arguments: #{$ORIGINAL_ARGV.inspect}
463 Coverage analysis bug in: #{options.report_cov_bug_for}
464
465 Line(s) ____________ should be ______ (red/green).
466
467 Raw coverage information (feel free to remove useless data, but please leave
468 some context around the faulty lines):
469
470 EOF
471 defsite.line.upto(SCRIPT_LINES__[defsite.file].size) do |i|
472 puts "%7d:%5d:%s" % [count_info[i-1], i, lines[i-1]]
473 end
474 exit
475 end
bbf8853 fFxes No file to analyze was found errorr. Taken from @valo.
Aaron Bedra authored
476 if !formatters.empty? and formatters.all?{|formatter| formatter.sorted_file_pairs.empty? }
78e8be3 @mfp bin/rcov: display a warning message when all files are ignored by the fo...
mfp authored
477 require 'pp'
478 $stderr.puts <<-EOF
479
480 No file to analyze was found. All the files loaded by rcov matched one of the
481 following expressions, and were thus ignored:
482 #{PP.pp(options.skip, "").chomp}
483
484 You can solve this by doing one or more of the following:
485 * rename the files not to be ignored so they don't match the above regexps
a9d119a @mfp bin/rcov (main, Formatter#add_file, #initialize): implemented --include-...
mfp authored
486 * use --include-file to give a list of patterns for files not to be ignored
78e8be3 @mfp bin/rcov: display a warning message when all files are ignored by the fo...
mfp authored
487 * use --exclude-only to give the new list of regexps to match against
488 * structure your code as follows:
489 test/test_*.rb for the test cases
490 lib/**/*.rb for the target source code whose coverage you want
491 making sure that the test/test_*.rb files are loading from lib/, e.g. by
492 using the -Ilib command-line argument, adding
493 $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
494 to test/test_*.rb, or running rcov via a Rakefile (read the RDoc
495 documentation or README.rake in the source distribution).
496 EOF
497 end
f6a3558 @mfp bin/rcov: rethrow exceptions generated by traced scripts (patch by Kurt ...
mfp authored
498
499 raise $__rcov_exit_exception if $__rcov_exit_exception
bd1ce53 @mfp bin/rcov, ext/rcovrt/rcov.c: --test-unit-only, ABI checks and minor refa...
mfp authored
500 }
501
3d8121c @spicycode Deprecate test-unit/spec-only modes
spicycode authored
502 $rcov_code_coverage_analyzer.install_hook
bd1ce53 @mfp bin/rcov, ext/rcovrt/rcov.c: --test-unit-only, ABI checks and minor refa...
mfp authored
503
1deb495 @mfp bin/rcov (main): reworked command line options. Changed -t and -T.
mfp authored
504 #{{{ Load scripts
f6a3558 @mfp bin/rcov: rethrow exceptions generated by traced scripts (patch by Kurt ...
mfp authored
505 begin
711d7fd @abedra add warning message about ruby 1.9 support
abedra authored
506 if RUBY_VERSION =~ /1.9/
507 puts "** WARNING: Ruby 1.9 Support is experimental at best. Don't expect correct results! **"
508 end
490d1f4 @spicycode Cleaning up bin script
spicycode authored
509 pending_scripts = ARGV.clone
510 ARGV.replace extra_args
511 until pending_scripts.empty?
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
512 prog = pending_scripts.shift
3df4fac @mfp bin/rcov (main): implemented --replace-progname; disabled by default.
mfp authored
513 if options.replace_prog_name
490d1f4 @spicycode Cleaning up bin script
spicycode authored
514 $0 = File.basename(File.expand_path(prog))
3df4fac @mfp bin/rcov (main): implemented --replace-progname; disabled by default.
mfp authored
515 end
0bf32cc @mfp bin/rcov: allow the execution of multiple scripts.
mfp authored
516 load prog
490d1f4 @spicycode Cleaning up bin script
spicycode authored
517 end
f6a3558 @mfp bin/rcov: rethrow exceptions generated by traced scripts (patch by Kurt ...
mfp authored
518 rescue Object => err
519 $__rcov_exit_exception = err
520 end
dcf459b @mfp bin/rcov: allow the script to be load()ed separately.
mfp authored
521
e03e007 @mfp bin/rcov, lib/xx-0.1.0.rb: refactored HTML generation to use xx.
mfp authored
522 __END__
Something went wrong with that request. Please try again.