summaryrefslogtreecommitdiff
path: root/lib/hoe/rcov.rb
blob: c3ba542c498314a812100bc9d8255845f3526193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
##
# RCov plugin for hoe.
#
# === Tasks Provided:
#
# rcov::               Analyze code coverage with tests

module Hoe::RCov

  ##
  # Activate the rcov dependencies.

  def activate_rcov_deps
    dependency "rcov", "~> 0.9", :development
  end

  ##
  # Define tasks for plugin.

  def define_rcov_tasks
    task :isolate # ensure it exists

    task :rcov => :isolate do
      sh(*make_rcov_cmd)
    end

    task :clobber_rcov do
      rm_rf "coverage"
    end

    task :clobber => :clobber_rcov

    # this is for my emacs rcov overlay stuff on emacswiki.
    task :rcov_overlay do
      path = ENV["FILE"]
      rcov, eol = Marshal.load(File.read("coverage.info")).last[path], 1
      puts rcov[:lines].zip(rcov[:coverage]).map { |line, coverage|
        bol, eol = eol, eol + line.length
        [bol, eol, "#ffcccc"] unless coverage
      }.compact.inspect
    end
  rescue LoadError
    # skip
    task :clobber_rcov # in case rcov didn't load
    # TODO: didn't load? this must be terribly historical
  end

  def make_rcov_cmd # :nodoc:
    rcov  = Gem.bin_wrapper "rcov"
    tests = test_globs.sort.map { |g| Dir.glob(g) }.flatten.map(&:inspect)

    cmd = %W[#{rcov}
             #{Hoe::RUBY_FLAGS}
             --text-report
             --no-color
             --save coverage.info
             -x ^/
             -x tmp/isolate
             --sort coverage
             --sort-reverse
             -o coverage
            ] + tests

    cmd
  end
end

task :clean => :clobber_rcov