spicycode-rcov 0.8.1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/BLURB +149 -0
- data/CHANGES +177 -0
- data/LEGAL +36 -0
- data/LICENSE +56 -0
- data/Rakefile +193 -0
- data/Rantfile +76 -0
- data/THANKS +96 -0
- data/bin/rcov +552 -0
- data/ext/rcovrt/callsite.c +242 -0
- data/ext/rcovrt/extconf.rb +13 -0
- data/ext/rcovrt/rcovrt.c +331 -0
- data/lib/rcov/lowlevel.rb +147 -0
- data/lib/rcov/rant.rb +87 -0
- data/lib/rcov/rcovtask.rb +156 -0
- data/lib/rcov/report.rb +1249 -0
- data/lib/rcov/version.rb +13 -0
- data/lib/rcov/xx.rb +761 -0
- data/lib/rcov.rb +990 -0
- data/rcov.el +131 -0
- data/rcov.vim +38 -0
- data/readme_for_api +42 -0
- data/readme_for_rake +62 -0
- data/readme_for_rant +68 -0
- data/readme_for_vim +47 -0
- data/setup.rb +1588 -0
- data/test/assets/sample_01.rb +7 -0
- data/test/assets/sample_02.rb +5 -0
- data/test/assets/sample_03.rb +20 -0
- data/test/assets/sample_04.rb +10 -0
- data/test/assets/sample_05-new.rb +17 -0
- data/test/assets/sample_05-old.rb +13 -0
- data/test/assets/sample_05.rb +17 -0
- data/test/call_site_analyzer_test.rb +207 -0
- data/test/code_coverage_analyzer_test.rb +186 -0
- data/test/file_statistics_test.rb +471 -0
- data/test/functional_test.rb +94 -0
- data/test/turn_off_rcovrt.rb +4 -0
- metadata +98 -0
data/rcov.el
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
;;; rcov.el -- Ruby Coverage Analysis Tool
|
2
|
+
|
3
|
+
;;; Copyright (c) 2006 rubikitch <rubikitch@ruby-lang.org>
|
4
|
+
;;;
|
5
|
+
;;; Use and distribution subject to the terms of the rcov license.
|
6
|
+
|
7
|
+
(defvar rcov-xref-before-visit-source-hook nil
|
8
|
+
"Hook executed before jump.")
|
9
|
+
(defvar rcov-xref-after-visit-source-hook nil
|
10
|
+
"Hook executed after jump.")
|
11
|
+
(defvar rcov-command-line "rake rcov RCOVOPTS='--gcc --no-html'"
|
12
|
+
"Rcov command line to find uncovered code.
|
13
|
+
It is good to use rcov with Rake because it `cd's appropriate directory.
|
14
|
+
`--gcc' option is strongly recommended because `rcov' uses compilation-mode.")
|
15
|
+
(defvar rcovsave-command-line "rake rcov RCOVOPTS='--gcc --no-html --save=coverage.info'"
|
16
|
+
"Rcov command line to save coverage status. See also `rcov-command-line'.")
|
17
|
+
(defvar rcovdiff-command-line "rake rcov RCOVOPTS='-D --gcc --no-html'"
|
18
|
+
"Rcov command line to find new uncovered code. See also `rcov-command-line'.")
|
19
|
+
|
20
|
+
;;;; rcov-xref-mode
|
21
|
+
(define-derived-mode rcov-xref-mode ruby-mode "Rxref"
|
22
|
+
"Major mode for annotated Ruby scripts (coverage/*.rb) by rcov."
|
23
|
+
(setq truncate-lines t)
|
24
|
+
;; ruby-electric-mode / pabbrev-mode hijacks TAB binding.
|
25
|
+
(and ruby-electric-mode (ruby-electric-mode -1))
|
26
|
+
(and (boundp 'pabbrev-mode) pabbrev-mode (pabbrev-mode -1))
|
27
|
+
(suppress-keymap rcov-xref-mode-map)
|
28
|
+
(define-key rcov-xref-mode-map "\C-i" 'rcov-xref-next-tag)
|
29
|
+
(define-key rcov-xref-mode-map "\M-\C-i" 'rcov-xref-previous-tag)
|
30
|
+
(define-key rcov-xref-mode-map "\C-m" 'rcov-xref-visit-source)
|
31
|
+
(set (make-local-variable 'automatic-hscrolling) nil)
|
32
|
+
)
|
33
|
+
|
34
|
+
(defvar rcov-xref-tag-regexp "\\[\\[\\(.*?\\)\\]\\]")
|
35
|
+
|
36
|
+
(defun rcov-xref-next-tag (n)
|
37
|
+
"Go to next LINK."
|
38
|
+
(interactive "p")
|
39
|
+
(when (looking-at rcov-xref-tag-regexp)
|
40
|
+
(goto-char (match-end 0)))
|
41
|
+
(when (re-search-forward rcov-xref-tag-regexp nil t n)
|
42
|
+
(goto-char (match-beginning 0)))
|
43
|
+
(rcov-xref-show-link))
|
44
|
+
|
45
|
+
(defun rcov-xref-previous-tag (n)
|
46
|
+
"Go to previous LINK."
|
47
|
+
(interactive "p")
|
48
|
+
(re-search-backward rcov-xref-tag-regexp nil t n)
|
49
|
+
(rcov-xref-show-link))
|
50
|
+
|
51
|
+
(defvar rcov-xref-link-tempbuffer " *rcov-link*")
|
52
|
+
(defun rcov-xref-show-link ()
|
53
|
+
"Follow current LINK."
|
54
|
+
(let ((link (match-string 1))
|
55
|
+
(eol (point-at-eol)))
|
56
|
+
(save-excursion
|
57
|
+
(when (and link
|
58
|
+
(re-search-backward "# \\(>>\\|<<\\) " (point-at-bol) t))
|
59
|
+
(while (re-search-forward rcov-xref-tag-regexp eol t)
|
60
|
+
(let ((matched (match-string 1)))
|
61
|
+
(when (string= link matched)
|
62
|
+
(add-text-properties 0 (length matched) '(face highlight) matched))
|
63
|
+
(with-current-buffer (get-buffer-create rcov-xref-link-tempbuffer)
|
64
|
+
(insert matched "\n"))))
|
65
|
+
(let (message-log-max) ; inhibit *Messages*
|
66
|
+
(message "%s" (with-current-buffer rcov-xref-link-tempbuffer
|
67
|
+
(substring (buffer-string) 0 -1)))) ; chomp
|
68
|
+
(kill-buffer rcov-xref-link-tempbuffer)))))
|
69
|
+
|
70
|
+
|
71
|
+
;; copied from jw-visit-source
|
72
|
+
(defun rcov-xref-extract-file-lines (line)
|
73
|
+
"Extract a list of file/line pairs from the given line of text."
|
74
|
+
(let*
|
75
|
+
((unix_fn "[^ \t\n\r\"'([<{]+")
|
76
|
+
(dos_fn "[a-zA-Z]:[^ \t\n\r\"'([<{]+")
|
77
|
+
(flre (concat "\\(" unix_fn "\\|" dos_fn "\\):\\([0-9]+\\)"))
|
78
|
+
(start nil)
|
79
|
+
(result nil))
|
80
|
+
(while (string-match flre line start)
|
81
|
+
(setq start (match-end 0))
|
82
|
+
(setq result
|
83
|
+
(cons (list
|
84
|
+
(substring line (match-beginning 1) (match-end 1))
|
85
|
+
(string-to-int (substring line (match-beginning 2) (match-end 2))))
|
86
|
+
result)))
|
87
|
+
result))
|
88
|
+
|
89
|
+
(defun rcov-xref-select-file-line (candidates)
|
90
|
+
"Select a file/line candidate that references an existing file."
|
91
|
+
(cond ((null candidates) nil)
|
92
|
+
((file-readable-p (caar candidates)) (car candidates))
|
93
|
+
(t (rcov-xref-select-file-line (cdr candidates))) ))
|
94
|
+
|
95
|
+
(defun rcov-xref-visit-source ()
|
96
|
+
"If the current line contains text like '../src/program.rb:34', visit
|
97
|
+
that file in the other window and position point on that line."
|
98
|
+
(interactive)
|
99
|
+
(let* ((line (progn (looking-at rcov-xref-tag-regexp) (match-string 1)))
|
100
|
+
(candidates (rcov-xref-extract-file-lines line))
|
101
|
+
(file-line (rcov-xref-select-file-line candidates)))
|
102
|
+
(cond (file-line
|
103
|
+
(run-hooks 'rcov-xref-before-visit-source-hook)
|
104
|
+
(find-file (car file-line))
|
105
|
+
(goto-line (cadr file-line))
|
106
|
+
(run-hooks 'rcov-xref-after-visit-source-hook))
|
107
|
+
(t
|
108
|
+
(error "No source location on line.")) )))
|
109
|
+
|
110
|
+
;;;; Running rcov with various options.
|
111
|
+
(defun rcov-internal (cmdline)
|
112
|
+
"Run rcov with various options."
|
113
|
+
(compile-internal cmdline ""
|
114
|
+
nil nil nil (lambda (x) "*rcov*")))
|
115
|
+
|
116
|
+
(defun rcov ()
|
117
|
+
"Run rcov to find uncovered code."
|
118
|
+
(interactive)
|
119
|
+
(rcov-internal rcov-command-line))
|
120
|
+
|
121
|
+
(defun rcovsave ()
|
122
|
+
"Run rcov to save coverage status."
|
123
|
+
(interactive)
|
124
|
+
(rcov-internal rcovsave-command-line))
|
125
|
+
|
126
|
+
(defun rcovdiff ()
|
127
|
+
"Run rcov to find new uncovered code."
|
128
|
+
(interactive)
|
129
|
+
(rcov-internal rcovdiff-command-line))
|
130
|
+
|
131
|
+
(provide 'rcov)
|
data/rcov.vim
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
" Vim compiler file
|
2
|
+
" Language: Ruby
|
3
|
+
" Function: Code coverage information with rcov
|
4
|
+
" Maintainer: Mauricio Fernandez <mfp at acm dot org>
|
5
|
+
" Info:
|
6
|
+
" URL: http://eigenclass.org/hiki.rb?rcov
|
7
|
+
" ----------------------------------------------------------------------------
|
8
|
+
"
|
9
|
+
" Changelog:
|
10
|
+
" 0.1: initial version, shipped with rcov 0.6.0
|
11
|
+
"
|
12
|
+
" Comments:
|
13
|
+
" Initial attempt.
|
14
|
+
" ----------------------------------------------------------------------------
|
15
|
+
|
16
|
+
if exists("current_compiler")
|
17
|
+
finish
|
18
|
+
endif
|
19
|
+
let current_compiler = "rcov"
|
20
|
+
|
21
|
+
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
22
|
+
command -nargs=* CompilerSet setlocal <args>
|
23
|
+
endif
|
24
|
+
|
25
|
+
let s:cpo_save = &cpo
|
26
|
+
set cpo-=C
|
27
|
+
|
28
|
+
CompilerSet makeprg=rake\ $*\ RCOVOPTS=\"-D\ --no-html\ --no-color\"\ $*
|
29
|
+
|
30
|
+
CompilerSet errorformat=
|
31
|
+
\%+W\#\#\#\ %f:%l\,
|
32
|
+
\%-C\ \ \ ,
|
33
|
+
\%-C!!\
|
34
|
+
|
35
|
+
let &cpo = s:cpo_save
|
36
|
+
unlet s:cpo_save
|
37
|
+
|
38
|
+
" vim: nowrap sw=2 sts=2 ts=8 ff=unix :
|
data/readme_for_api
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
= +rcov+
|
3
|
+
|
4
|
+
+rcov+ is a:
|
5
|
+
1. tool for code coverage analysis for Ruby
|
6
|
+
2. library for collecting code coverage and execution count information
|
7
|
+
introspectively
|
8
|
+
|
9
|
+
If you want to use the command line tool, the output from
|
10
|
+
rcov -h
|
11
|
+
is self-explicative.
|
12
|
+
|
13
|
+
If you want to automate the execution of +rcov+ via Rake or Rant, take a look at
|
14
|
+
readme_for_rake[link:files/README_rake.html] or
|
15
|
+
readme_for_rant[link:files/README_rant.html], respectively.
|
16
|
+
|
17
|
+
If you want to use the associated library, read on.
|
18
|
+
|
19
|
+
== Usage of the +rcov+ runtime/library
|
20
|
+
|
21
|
+
+rcov+ is primarily a tool for code coverage analysis, but since 0.4.0 it
|
22
|
+
exposes some of its code so that you can build on top of its heuristics for
|
23
|
+
code analysis and its capabilities for coverage information and execution
|
24
|
+
count gathering.
|
25
|
+
|
26
|
+
The main classes of interest are Rcov::FileStatistics,
|
27
|
+
Rcov::CodeCoverageAnalyzer and Rcov::CallSiteAnalyzer.
|
28
|
+
|
29
|
+
Rcov::FileStatistics can use some heuristics to determine
|
30
|
+
which parts of the file are executable and which are mere comments.
|
31
|
+
|
32
|
+
Rcov::CodeCoverageAnalyzer is used to gather code coverage and execution
|
33
|
+
count information inside a running Ruby program.
|
34
|
+
|
35
|
+
Rcov::CallSiteAnalyzer is used to obtain information about where methods are
|
36
|
+
defined and who calls them.
|
37
|
+
|
38
|
+
The parts of +rcov+'s runtime meant to be reused (i.e. the external API) are
|
39
|
+
documented with RDoc. Those not meant to be used are clearly marked as so or
|
40
|
+
were deliberately removed from the present documentation.
|
41
|
+
|
42
|
+
|
data/readme_for_rake
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
== Code coverage analysis automation with Rake
|
3
|
+
|
4
|
+
Since 0.4.0, <tt>rcov</tt> features a <tt>Rcov::RcovTask</tt> task for rake
|
5
|
+
which can be used to automate test coverage analysis. Basic usage is as
|
6
|
+
follows:
|
7
|
+
|
8
|
+
require 'rcov/rcovtask'
|
9
|
+
Rcov::RcovTask.new do |t|
|
10
|
+
t.test_files = FileList['test/test*.rb']
|
11
|
+
# t.verbose = true # uncomment to see the executed command
|
12
|
+
end
|
13
|
+
|
14
|
+
This will create by default a task named <tt>rcov</tt>, and also a task to
|
15
|
+
remove the output directory where the XHTML report is generated.
|
16
|
+
The latter will be named <tt>clobber_rcob</tt>, and will be added to the main
|
17
|
+
<tt>clobber</tt> target.
|
18
|
+
|
19
|
+
=== Passing command line options to <tt>rcov</tt>
|
20
|
+
|
21
|
+
You can provide a description, change the name of the generated tasks (the
|
22
|
+
one used to generate the report(s) and the clobber_ one) and pass options to
|
23
|
+
<tt>rcov</tt>:
|
24
|
+
|
25
|
+
desc "Analyze code coverage of the unit tests."
|
26
|
+
Rcov::RcovTask.new(:coverage) do |t|
|
27
|
+
t.test_files = FileList['test/test*.rb']
|
28
|
+
t.verbose = true
|
29
|
+
## get a text report on stdout when rake is run:
|
30
|
+
t.rcov_opts << "--text-report"
|
31
|
+
## only report files under 80% coverage
|
32
|
+
t.rcov_opts << "--threshold 80"
|
33
|
+
end
|
34
|
+
|
35
|
+
That will generate a <tt>coverage</tt> task and the associated
|
36
|
+
<tt>clobber_coverage</tt> task to remove the directory the report is dumped
|
37
|
+
to ("<tt>coverage</tt>" by default).
|
38
|
+
|
39
|
+
You can specify a different destination directory, which comes handy if you
|
40
|
+
have several <tt>RcovTask</tt>s; the <tt>clobber_*</tt> will take care of
|
41
|
+
removing that directory:
|
42
|
+
|
43
|
+
desc "Analyze code coverage for the FileStatistics class."
|
44
|
+
Rcov::RcovTask.new(:rcov_sourcefile) do |t|
|
45
|
+
t.test_files = FileList['test/test_FileStatistics.rb']
|
46
|
+
t.verbose = true
|
47
|
+
t.rcov_opts << "--test-unit-only"
|
48
|
+
t.output_dir = "coverage.sourcefile"
|
49
|
+
end
|
50
|
+
|
51
|
+
Rcov::RcovTask.new(:rcov_ccanalyzer) do |t|
|
52
|
+
t.test_files = FileList['test/test_CodeCoverageAnalyzer.rb']
|
53
|
+
t.verbose = true
|
54
|
+
t.rcov_opts << "--test-unit-only"
|
55
|
+
t.output_dir = "coverage.ccanalyzer"
|
56
|
+
end
|
57
|
+
|
58
|
+
=== Options passed through the <tt>rake</tt> command line
|
59
|
+
|
60
|
+
You can override the options defined in the RcovTask by passing the new
|
61
|
+
options at the time you invoke rake.
|
62
|
+
The documentation for the Rcov::RcovTask explains how this can be done.
|
data/readme_for_rant
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
== Code coverage analysis automation with Rant
|
3
|
+
|
4
|
+
Since 0.5.0, <tt>rcov</tt> features a <tt>Rcov</tt> generator for eant
|
5
|
+
which can be used to automate test coverage analysis. Basic usage is as
|
6
|
+
follows:
|
7
|
+
|
8
|
+
require 'rcov/rant'
|
9
|
+
|
10
|
+
desc "Create a cross-referenced code coverage report."
|
11
|
+
gen Rcov do |g|
|
12
|
+
g.test_files = sys['test/test*.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
This will create by default a task named <tt>rcov</tt>.
|
16
|
+
|
17
|
+
=== Passing command line options to <tt>rcov</tt>
|
18
|
+
|
19
|
+
You can provide a description, change the name of the generated tasks (the
|
20
|
+
one used to generate the report(s) and the clobber_ one) and pass options to
|
21
|
+
<tt>rcov</tt>:
|
22
|
+
|
23
|
+
desc "Create cross-referenced code coverage report."
|
24
|
+
gen Rcov, :coverage do |g|
|
25
|
+
g.test_files = sys['test/test*.rb']
|
26
|
+
g.rcov_opts << "--threshold 80" << "--callsites"
|
27
|
+
end
|
28
|
+
|
29
|
+
That will generate a <tt>coverage</tt> task.
|
30
|
+
|
31
|
+
You can specify a different destination directory, which comes handy if you
|
32
|
+
have several rcov tasks:
|
33
|
+
|
34
|
+
desc "Analyze code coverage for the FileStatistics class."
|
35
|
+
gen Rcov, :rcov_sourcefile do |g|
|
36
|
+
g.libs << "ext/rcovrt"
|
37
|
+
g.test_files = sys['test/test_FileStatistics.rb']
|
38
|
+
g.rcov_opts << "--test-unit-only"
|
39
|
+
g.output_dir = "coverage.sourcefile"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Analyze code coverage for CodeCoverageAnalyzer."
|
43
|
+
gen Rcov, :rcov_ccanalyzer do |g|
|
44
|
+
g.libs << "ext/rcovrt"
|
45
|
+
g.test_files = sys['test/test_CodeCoverageAnalyzer.rb']
|
46
|
+
g.rcov_opts << "--test-unit-only"
|
47
|
+
g.output_dir = "coverage.ccanalyzer"
|
48
|
+
end
|
49
|
+
|
50
|
+
=== Options specified passed to the generator
|
51
|
+
|
52
|
+
The +Rcov+ generator recognizes the following options:
|
53
|
+
+libs+:: directories to be added to the <tt>$LOAD_PATH</tt>
|
54
|
+
+rcov_opts+:: array of options to be passed to rcov
|
55
|
+
+test_files+:: files to execute
|
56
|
+
+test_dirs+:: directories where to look for test files automatically
|
57
|
+
+pattern+:: pattern for automatic discovery of unit tests to be executed
|
58
|
+
+output_dir+:: directory where to leave the generated reports
|
59
|
+
|
60
|
+
+test_files+ overrides the combination of +test_dirs+ and +pattern+.
|
61
|
+
|
62
|
+
|
63
|
+
=== Options passed through the <tt>rake</tt> command line
|
64
|
+
|
65
|
+
You can override the options defined in the Rcov tasks by specifying them
|
66
|
+
using environment variables at the time rant is executed.
|
67
|
+
RCOVPATH=/my/modified/rcov rant rcov # use the specified rcov executable
|
68
|
+
RCOVOPTS="--no-callsites -x foo" rant rcov # pass those options to rcov
|
data/readme_for_vim
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
<tt>rcov.vim</tt> allows you to run unit tests from vim and enter quickfix mode in
|
3
|
+
order to jump to uncovered code introduced since the last run.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
Copy <tt>rcov.vim</tt> to the appropriate "compiler" directory (typically
|
7
|
+
<tt>$HOME/.vim/compiler</tt>).
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
=== Setting the reference point
|
12
|
+
|
13
|
+
+rcov+'s <tt>--text-coverage-diff</tt> mode compares the current coverage status against
|
14
|
+
the saved one. It therefore needs that information to be recorded
|
15
|
+
before you write new code (typically right after you perform a commit) in
|
16
|
+
order to have something to compare against.
|
17
|
+
|
18
|
+
You can save the current status with the <tt>--save</tt> option.
|
19
|
+
If you're running +rcov+ from Rake, you can do something like
|
20
|
+
rake rcov_units RCOVOPTS="-T --save --rails"
|
21
|
+
in order to take the current status as the reference point.
|
22
|
+
|
23
|
+
=== Finding new uncovered code
|
24
|
+
|
25
|
+
Type the following in command mode while editing your program:
|
26
|
+
:compiler rcov
|
27
|
+
|
28
|
+
rcov.vim assumes +rcov+ can be invoked with a rake task (see
|
29
|
+
readme_for_rake[link:files/README_rake.html] for
|
30
|
+
information on how to create it).
|
31
|
+
|
32
|
+
You can then execute +rcov+ and enter quickfix mode by typing
|
33
|
+
|
34
|
+
:make <taskname>
|
35
|
+
|
36
|
+
where taskname is the +rcov+ task you want to use; if you didn't override the
|
37
|
+
default name in the Rakefile, just
|
38
|
+
|
39
|
+
:make rcov
|
40
|
+
|
41
|
+
will do.
|
42
|
+
|
43
|
+
vim will then enter quickfix mode, allowing you to jump to the areas that were
|
44
|
+
not covered since the last time you saved the coverage data.
|
45
|
+
|
46
|
+
--------
|
47
|
+
# vim: ft=text :
|