uncool 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ ---
2
+ name : uncool
3
+ version : 1.0.0
4
+ released : 2010-08-05
5
+
6
+ requires:
7
+ - tracepoint 1.2+
8
+ - ansi
9
+ - syckle (build)
10
+ - box (build)
11
+ - ko (test)
@@ -0,0 +1,18 @@
1
+ ---
2
+ title : Uncool
3
+ suite : proutils
4
+ summary: Unit Test Coverage Tool
5
+ authors: Thomas Sawyer
6
+ contact: trans <transfire@gmail.com>
7
+ license: Apache 2.0
8
+
9
+ description:
10
+ Uncool is a unit testing coverage tool that monitors tests
11
+ recording all the methods covered for the tarageted namespaces.
12
+
13
+ resources:
14
+ home: http://proutils.github.com/uncool
15
+ repo: git://github.com/proutils/uncool.git
16
+
17
+ copyright: Copyright 2009 Thomas Sawyer
18
+
@@ -0,0 +1,79 @@
1
+ module Uncool
2
+
3
+ #
4
+ class Report
5
+
6
+ #
7
+ def initialize(analysis, options={})
8
+ @analysis = analysis
9
+ @options = options
10
+ end
11
+
12
+ #
13
+ def options
14
+ @options
15
+ end
16
+
17
+ #
18
+ def coverage
19
+ @analysis.coverage
20
+ end
21
+
22
+ #
23
+ def render
24
+ require 'erb'
25
+ rhtml = File.read(File.dirname(__FILE__) + '/report.rhtml')
26
+ ERB.new(rhtml).result(binding)
27
+ end
28
+
29
+ #
30
+ def save(logpath)
31
+ require 'fileutils'
32
+ dir = File.join(logpath, 'lemon')
33
+ file = File.join(dir, 'index.html')
34
+ FileUtils.mkdir_p(dir)
35
+ File.open(file, 'w'){ |w| w << render }
36
+ end
37
+
38
+ #
39
+ def display(format=nil)
40
+ case options[:format]
41
+ when 'tap'
42
+ display_tap
43
+ else
44
+ display_color
45
+ end
46
+ end
47
+
48
+ #
49
+ def display_color
50
+ require 'ansi'
51
+ puts "\nUnit Coverage"
52
+ i = 0
53
+ coverage.uniq.sort.each do |unit|
54
+ i += 1
55
+ if unit.covered?
56
+ puts "+ " + unit.to_s.ansi(:green)
57
+ else
58
+ puts "- " + unit.to_s.ansi(:red)
59
+ end
60
+ end
61
+ puts
62
+ end
63
+
64
+ #
65
+ def display_tap
66
+ i = 0
67
+ coverage.uniq.sort.each do |unit|
68
+ i += 1
69
+ if unit.covered?
70
+ puts "ok #{i} - " + unit.to_s
71
+ else
72
+ puts "not ok #{i} - " + unit.to_s
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,37 @@
1
+ <html>
2
+ <head>
3
+ <title>Lemon Coverage Report</title>
4
+ <style>
5
+ body{background:#221; margin: 0; padding: 0; color: yellow;}
6
+ #main{
7
+ width:600px; margin:0 auto;
8
+ }
9
+ #list {
10
+ color: #333;
11
+ border:1px solid #ccc;
12
+ background:white;
13
+ padding: 10px 20px 30px 20px;
14
+ min-height: 300px;
15
+ }
16
+ .green{color:green;}
17
+ .red{color:red;}
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div id="main">
22
+ Lemon
23
+ <div id="list">
24
+ <h1>Lemon Coverage Report</h1>
25
+ <% chart.sort.each do |(unit, yes)| %>
26
+ <% if yes %>
27
+ <div class="green"><%= unit.to_s %></div>
28
+ <% else %>
29
+ <div class="red"><%= unit.to_s %></div>
30
+ <% end %>
31
+ <% end %>
32
+ </div>
33
+ Lemon (c) 2010 Thomas Sawyer
34
+ </div>
35
+ </body>
36
+ </html>
37
+
@@ -0,0 +1,9 @@
1
+
2
+ alias_method :testcase, :feature
3
+ alias_method :TestCase, :Feature
4
+
5
+ class KO::Feature
6
+ alias_method :testunit, :scenario
7
+ alias_method :TestUnit, :Scenario
8
+ end
9
+
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ gem('tracepoint')
3
+
4
+ require 'tracepoint'
5
+ require 'uncool/analysis'
6
+
7
+ module Uncool
8
+
9
+ #
10
+ class Trace
11
+
12
+ #
13
+ attr :targets
14
+
15
+ #
16
+ attr :log
17
+
18
+ #
19
+ def initialize(targets, options={})
20
+ @targets = [targets].compact.flatten
21
+ @options = options
22
+ @log = []
23
+ end
24
+
25
+ #
26
+ def setup
27
+ tracker = self
28
+ TracePoint.trace do |tp|
29
+ #puts "#{tp.self.class}\t#{tp.callee}\t#{tp.event}\t#{tp.return?}"
30
+ if tp.event == 'call' or tp.event == 'c-call'
31
+ if tracker.target?(tp.self.class)
32
+ tracker.log << [tp.self, tp.callee]
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ #
39
+ def target?(mod)
40
+ return true if targets.empty?
41
+ targets.find do |target|
42
+ begin
43
+ target_class = eval(target, TOPLEVEL_BINDING) #Object.const_get(target)
44
+ rescue
45
+ nil
46
+ else
47
+ target_class == mod
48
+ end
49
+ end
50
+ end
51
+
52
+ #
53
+ def activate
54
+ setup
55
+ TracePoint.activate
56
+ end
57
+
58
+ #
59
+ def deactivate
60
+ TracePoint.deactivate
61
+ end
62
+
63
+ #
64
+ def to_analysis
65
+ Analysis.new(self, @options)
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,73 @@
1
+ module Uncool
2
+
3
+ #
4
+ class Unit
5
+ attr :target
6
+ attr :method
7
+ attr :function
8
+
9
+ def initialize(target, method, props={})
10
+ @target = target
11
+ @method = method.to_sym
12
+ @function = props[:function] ? true : false
13
+ @covered = props[:covered]
14
+
15
+ if @function
16
+ @private = !@target.public_methods.find{ |m| m.to_sym == @method }
17
+ else
18
+ @private = !@target.public_instance_methods.find{ |m| m.to_sym == @method }
19
+ end
20
+ end
21
+
22
+ # Method access is private or protected?
23
+ def private?
24
+ @private
25
+ end
26
+
27
+ # Marked as covered?
28
+ def covered?
29
+ @covered
30
+ end
31
+
32
+ #
33
+ def function?
34
+ @function
35
+ end
36
+
37
+ #
38
+ def hash
39
+ @target.hash ^ @method.hash ^ @function.hash
40
+ end
41
+
42
+ #
43
+ def to_s
44
+ if @function
45
+ "#{@target}.#{@method}"
46
+ else
47
+ "#{@target}##{@method}"
48
+ end
49
+ end
50
+ alias to_str to_s
51
+
52
+ def eql?(other)
53
+ return false unless Unit === other
54
+ return false unless target == other.target
55
+ return false unless method == other.method
56
+ return false unless function == other.function
57
+ return true
58
+ end
59
+
60
+ def inspect
61
+ "#{target}#{function ? '.' : '#'}#{method}"
62
+ end
63
+
64
+ def <=>(other)
65
+ c = (target.name <=> other.target.name)
66
+ return c unless c == 0
67
+ return -1 if function && !other.function
68
+ return 1 if !function && other.function
69
+ method.to_s <=> other.method.to_s
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,29 @@
1
+ Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION) # becuase Ruby 1.8~ gets in the way
2
+
3
+ module Uncool
4
+
5
+ def self.__DIR__
6
+ File.dirname(__FILE__)
7
+ end
8
+
9
+ def self.gemfile
10
+ @gemfile ||= (
11
+ require 'yaml'
12
+ YAML.load(File.new(__DIR__ + '/gemfile.yml'))
13
+ )
14
+ end
15
+
16
+ def self.profile
17
+ @profile ||= (
18
+ require 'yaml'
19
+ YAML.load(File.new(__DIR__ + '/profile.yml'))
20
+ )
21
+ end
22
+
23
+ def self.const_missing(name)
24
+ name = name.to_s.downcase
25
+ gemfile[name] || profile[name]
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,11 @@
1
+ ---
2
+ name : uncool
3
+ version : 1.0.0
4
+ released : 2010-08-05
5
+
6
+ requires:
7
+ - tracepoint 1.2+
8
+ - ansi
9
+ - syckle (build)
10
+ - box (build)
11
+ - ko (test)
@@ -0,0 +1,18 @@
1
+ ---
2
+ title : Uncool
3
+ suite : proutils
4
+ summary: Unit Test Coverage Tool
5
+ authors: Thomas Sawyer
6
+ contact: trans <transfire@gmail.com>
7
+ license: Apache 2.0
8
+
9
+ description:
10
+ Uncool is a unit testing coverage tool that monitors tests
11
+ recording all the methods covered for the tarageted namespaces.
12
+
13
+ resources:
14
+ home: http://proutils.github.com/uncool
15
+ repo: git://github.com/proutils/uncool.git
16
+
17
+ copyright: Copyright 2009 Thomas Sawyer
18
+
@@ -0,0 +1,14 @@
1
+ feature "Unit Test Coverage Report" do
2
+
3
+ scenario "coverage via command-line require" do
4
+ out = `ns="Example" ruby -Ilib -runcool test/fixtures/example_run.rb`
5
+ out.assert =~ /^\+.*?Example#f/
6
+ end
7
+
8
+ scenario "coverage via command-line tool" do
9
+ out = `ruby -Ilib -- ./bin/uncool-ruby -n Example test/fixtures/example_run.rb`
10
+ out.assert =~ /^\+.*?Example#f/
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,16 @@
1
+ feature "Unit Test Code Generation" do
2
+
3
+ scenario "Generate example via API" do
4
+ require 'uncool/app'
5
+ app = Uncool::App.new(:namespaces=>"Example")
6
+ out = app.generate(['test/fixtures/example_run.rb'])
7
+ out.assert =~ /^TestCase\ Example/
8
+ end
9
+
10
+ scenario "Generate example via command-line" do
11
+ out = `ruby -Ilib -- ./bin/uncool-ruby -g -n Example test/fixtures/example_run.rb`
12
+ out.assert =~ /^TestCase\ Example/
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,20 @@
1
+ class Example
2
+
3
+ def initialize(a=1)
4
+ @a = a
5
+ end
6
+
7
+ def f(x,y)
8
+ @a * x + y
9
+ end
10
+
11
+ def q(x,y)
12
+ x % y
13
+ end
14
+
15
+ def self.m(a,b)
16
+ a * b
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,7 @@
1
+ # Just a test dummy to try coverage against.
2
+
3
+ require File.dirname(__FILE__) + '/example.rb'
4
+
5
+ ex = Example.new
6
+ ex.f(1,2) == 3
7
+
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uncool
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Thomas Sawyer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-05 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: tracepoint
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 1
32
+ - 2
33
+ version: "1.2"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: ansi
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: syckle
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: box
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: ko
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: Uncool is a unit testing coverage tool that monitors tests recording all the methods covered for the tarageted namespaces.
93
+ email: transfire@gmail.com
94
+ executables:
95
+ - uncool-ruby
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - README.rdoc
100
+ files:
101
+ - bin/uncool-ruby
102
+ - lib/uncool/analysis.rb
103
+ - lib/uncool/app.rb
104
+ - lib/uncool/autolog.rb
105
+ - lib/uncool/cli.rb
106
+ - lib/uncool/generator/abstract.rb
107
+ - lib/uncool/generator/ko.rb
108
+ - lib/uncool/generator/lemon.rb
109
+ - lib/uncool/generator/qed.rb
110
+ - lib/uncool/lemon.svg
111
+ - lib/uncool/log.rb
112
+ - lib/uncool/meta/data.rb
113
+ - lib/uncool/meta/gemfile.yml
114
+ - lib/uncool/meta/profile.yml
115
+ - lib/uncool/report.rb
116
+ - lib/uncool/report.rhtml
117
+ - lib/uncool/syntax/ko.rb
118
+ - lib/uncool/trace.rb
119
+ - lib/uncool/unit.rb
120
+ - lib/uncool.rb
121
+ - meta/data.rb
122
+ - meta/gemfile.yml
123
+ - meta/profile.yml
124
+ - test/features/coverage_feature.rb
125
+ - test/features/generate_feature.rb
126
+ - test/fixtures/example.rb
127
+ - test/fixtures/example_run.rb
128
+ - HISTORY.rdoc
129
+ - LICENSE
130
+ - README.rdoc
131
+ has_rdoc: true
132
+ homepage: http://proutils.github.com/uncool
133
+ licenses:
134
+ - Apache 2.0
135
+ post_install_message:
136
+ rdoc_options:
137
+ - --title
138
+ - Uncool API
139
+ - --main
140
+ - README.rdoc
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project: uncool
164
+ rubygems_version: 1.3.7
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Unit Test Coverage Tool
168
+ test_files: []
169
+