Class: Emma::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/emma/control.rb

Constant Summary collapse

JAR =
File.expand_path("../emma.jar", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Control

Returns a new instance of Control.



7
8
9
10
# File 'lib/emma/control.rb', line 7

def initialize(opts = {})
  @em = opts[:metadata_file] || Tempfile.new("emma-metadata").path
  @ec = opts[:coverage_file] || Tempfile.new("emma-coverage").path
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



3
4
5
# File 'lib/emma/control.rb', line 3

def debug
  @debug
end

#ecObject

Returns the value of attribute ec.



3
4
5
# File 'lib/emma/control.rb', line 3

def ec
  @ec
end

#emObject

Returns the value of attribute em.



3
4
5
# File 'lib/emma/control.rb', line 3

def em
  @em
end

Instance Method Details

#emma(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/emma/control.rb', line 49

def emma(*args)
  puts "emma #{args.join ' '}" if debug
  proc = ChildProcess.new("java", "-cp", JAR, 'emma', *args.map { |e| e.to_s })
  proc.io.inherit!

  proc.start
  proc.wait

  if proc.exit_code != 0
    raise Error, "emma failed with exit code"
  end
end

#get(opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/emma/control.rb', line 12

def get(opts = {})
  merge = true
  merge = opts[:merge] if opts.key? :merge

  stop_collection = false
  stop_collection = opts[:stop_collection] if opts.key? :stop_collection

  emma "ctl", "-c", "coverage.get,#{@ec},#{merge},#{stop_collection}"
end

#instrument(paths, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/emma/control.rb', line 32

def instrument(paths, opts = {})
  paths  = Array(paths)
  mode   = opts[:mode] || 'fullcopy'
  filter = opts[:filter] || '*'
  merge  = opts[:merge] == false ? 'no' : 'yes'

  inputs = paths.map { |path| ['-instrpath', path] }.flatten

  emma 'instr',
       '-outmode', mode,
       '-outfile', @em,
       '-merge', merge,
       '-filter', filter,
       '-verbose',
       *inputs
end

#report(opts = {}) ⇒ Object



22
23
24
25
26
# File 'lib/emma/control.rb', line 22

def report(opts = {})
  format = opts[:format] || 'xml'

  emma "report", "-r", format, "-input", @em, "-input", @ec
end

#resetObject



28
29
30
# File 'lib/emma/control.rb', line 28

def reset
  emma "ctl", "-c", "coverage.reset"
end