File: test_functional.rb

package info (click to toggle)
rcov 0.8.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 464 kB
  • ctags: 558
  • sloc: ruby: 5,168; ansic: 446; lisp: 107; makefile: 6
file content (105 lines) | stat: -rw-r--r-- 3,206 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require 'test/unit'
require 'pathname'
require 'fileutils'

=begin
Updating functional testdata automatically is DANGEROUS, so I do manually.

== update functional test
cd ~/src/rcov/test
rcov="ruby ../bin/rcov -I../lib:../ext/rcovrt -o expected_coverage"

$rcov -a sample_04.rb
$rcov sample_04.rb
$rcov --gcc --include-file=sample --exclude=rcov sample_04.rb > expected_coverage/gcc-text.out

cp sample_05-old.rb sample_05.rb
$rcov --no-html --gcc --include-file=sample --exclude=rcov --save=coverage.info sample_05.rb > expected_coverage/diff-gcc-original.out
cp sample_05-new.rb sample_05.rb
$rcov --no-html --gcc -D --include-file=sample --exclude=rcov sample_05.rb > expected_coverage/diff-gcc-diff.out
$rcov --no-html -D --include-file=sample --exclude=rcov sample_05.rb > expected_coverage/diff.out
$rcov --no-html --no-color -D --include-file=sample --exclude=rcov sample_05.rb > expected_coverage/diff-no-color.out
$rcov --no-html --gcc --include-file=sample --exclude=rcov sample_05.rb > expected_coverage/diff-gcc-all.out
  
=end

class TestFunctional < Test::Unit::TestCase
  @@dir = Pathname(__FILE__).expand_path.dirname

  def strip_variable_sections(str)
    str.sub(/Generated on.+$/, '').sub(/Generated using the.+$/, '')
  end

  def cmp(file)
    content = lambda{|dir| strip_variable_sections(File.read(@@dir+dir+file))}
    assert_equal(content["expected_coverage"], content["actual_coverage"])
  end

  def with_testdir(&block)
    Dir.chdir(@@dir, &block)
  end

  def run_rcov(opts, script="sample_04.rb", opts_tail="")
    rcov = @@dir+"../bin/rcov"
    ruby_opts = "-I../lib:../ext/rcovrt"
    with_testdir do
      `cd #{@@dir}; ruby #{ruby_opts} #{rcov} #{opts} -o actual_coverage #{script} #{opts_tail}`
      yield if block_given?
    end
  end

  def test_annotation
    run_rcov("-a") do
      cmp "sample_04_rb.rb"
      cmp "sample_03_rb.rb"
    end
  end

  def test_html
    run_rcov("") do
      cmp "sample_04_rb.html"
      cmp "sample_03_rb.html"
    end
  end

  @@selection = "--include-file=sample --exclude=rcov"
  def test_text_gcc
    run_rcov("--gcc #{@@selection}",
             "sample_04.rb",
             "> actual_coverage/gcc-text.out") do
      cmp "gcc-text.out"
    end
  end

  def test_diff
    with_testdir { FileUtils.cp "sample_05-old.rb", "sample_05.rb" }
    run_rcov("--no-html --gcc #{@@selection} --save=coverage.info", "sample_05.rb",
             "> actual_coverage/diff-gcc-original.out") do
      cmp "diff-gcc-original.out"
    end

    with_testdir { FileUtils.cp "sample_05-new.rb", "sample_05.rb" }
    run_rcov("--no-html -D --gcc #{@@selection}", "sample_05.rb",
             "> actual_coverage/diff-gcc-diff.out") do
      cmp "diff-gcc-diff.out"
    end

    run_rcov("--no-html -D #{@@selection}", "sample_05.rb",
             "> actual_coverage/diff.out") do
      cmp "diff.out"
    end

    run_rcov("--no-html --no-color -D #{@@selection}", "sample_05.rb",
             "> actual_coverage/diff-no-color.out") do
      cmp "diff-no-color.out"
    end

    run_rcov("--no-html --gcc #{@@selection}", "sample_05.rb",
             "> actual_coverage/diff-gcc-all.out") do
      cmp "diff-gcc-all.out"
    end

    
  end

end