easycov 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96b862186042f31d03bf6642fa0714e3644ec856
4
+ data.tar.gz: ec52a3bc841ecdf46951eeb184e405f6ee8dd9db
5
+ SHA512:
6
+ metadata.gz: ffa376fa75fb898e20a5973e95ec0242c2fb0733e79ba7635ede89b500611a34f37518ecd1859136181de174a3f078c28839ca7a0a7d0dd2286268085a0177d3
7
+ data.tar.gz: ecd01431d0e10a25cff6e346feb7fcbd4465fc93abf803749866cf33da63689ed6cc4d933b3efd71acfc7c2d8b2d495f0e54a4d229a2012ff08bb4caf12ba5e3
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "simplecov"
4
+ gem "multi_json"
5
+
6
+ group :development do
7
+ gem "yard", "~> 0.8"
8
+ gem "bundler", "~> 1.1"
9
+ gem "jeweler", :git => "https://github.com/chetan/jeweler.git", :branch => "bixby"
10
+
11
+ gem "minitest", "~> 4.0", :platforms => [:mri_19, :mri_20, :rbx]
12
+ end
13
+
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GIT
2
+ remote: https://github.com/chetan/jeweler.git
3
+ revision: c83ba18b074e82415052e80499a770bff87bf944
4
+ branch: bixby
5
+ specs:
6
+ jeweler (1.8.7)
7
+ builder
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ github_api (= 0.10.1)
11
+ highline (>= 1.6.15)
12
+ nokogiri (= 1.5.10)
13
+ rake
14
+ rdoc
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ addressable (2.3.5)
20
+ builder (3.2.2)
21
+ faraday (0.8.8)
22
+ multipart-post (~> 1.2.0)
23
+ git (1.2.6)
24
+ github_api (0.10.1)
25
+ addressable
26
+ faraday (~> 0.8.1)
27
+ hashie (>= 1.2)
28
+ multi_json (~> 1.4)
29
+ nokogiri (~> 1.5.2)
30
+ oauth2
31
+ hashie (2.0.5)
32
+ highline (1.6.19)
33
+ httpauth (0.2.0)
34
+ json (1.8.0)
35
+ jwt (0.1.8)
36
+ multi_json (>= 1.5)
37
+ minitest (4.7.5)
38
+ multi_json (1.8.0)
39
+ multi_xml (0.5.5)
40
+ multipart-post (1.2.0)
41
+ nokogiri (1.5.10)
42
+ oauth2 (0.9.2)
43
+ faraday (~> 0.8)
44
+ httpauth (~> 0.2)
45
+ jwt (~> 0.1.4)
46
+ multi_json (~> 1.0)
47
+ multi_xml (~> 0.5)
48
+ rack (~> 1.2)
49
+ rack (1.5.2)
50
+ rake (10.1.0)
51
+ rdoc (4.0.1)
52
+ json (~> 1.4)
53
+ simplecov (0.7.1)
54
+ multi_json (~> 1.0)
55
+ simplecov-html (~> 0.7.1)
56
+ simplecov-html (0.7.1)
57
+ yard (0.8.7.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.1)
64
+ jeweler!
65
+ minitest (~> 4.0)
66
+ multi_json
67
+ simplecov
68
+ yard (~> 0.8)
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require 'jeweler'
14
+
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "easycov"
17
+ gemspec.summary = "Ruby code coverage library"
18
+ gemspec.description = "An easy to use, simplecov-compatibile code coverage library for Ruby"
19
+ gemspec.email = "chetan@pixelcop.net"
20
+ gemspec.homepage = "http://github.com/chetan/easycov"
21
+ gemspec.authors = ["Chetan Sarva"]
22
+ gemspec.license = "MIT"
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'yard'
38
+ YARD::Rake::YardocTask.new
39
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/easycov.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "easycov"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chetan Sarva"]
12
+ s.date = "2013-09-25"
13
+ s.description = "An easy to use, simplecov-compatibile code coverage library for Ruby"
14
+ s.email = "chetan@pixelcop.net"
15
+ s.files = [
16
+ "Gemfile",
17
+ "Gemfile.lock",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "easycov.gemspec",
21
+ "lib/easycov.rb",
22
+ "lib/easycov/filters.rb"
23
+ ]
24
+ s.homepage = "http://github.com/chetan/easycov"
25
+ s.licenses = ["MIT"]
26
+ s.require_paths = ["lib"]
27
+ s.rubygems_version = "2.0.5"
28
+ s.summary = "Ruby code coverage library"
29
+
30
+ if s.respond_to? :specification_version then
31
+ s.specification_version = 4
32
+
33
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
34
+ s.add_runtime_dependency(%q<simplecov>, [">= 0"])
35
+ s.add_runtime_dependency(%q<multi_json>, [">= 0"])
36
+ s.add_development_dependency(%q<yard>, ["~> 0.8"])
37
+ s.add_development_dependency(%q<bundler>, ["~> 1.1"])
38
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
39
+ s.add_development_dependency(%q<minitest>, ["~> 4.0"])
40
+ else
41
+ s.add_dependency(%q<simplecov>, [">= 0"])
42
+ s.add_dependency(%q<multi_json>, [">= 0"])
43
+ s.add_dependency(%q<yard>, ["~> 0.8"])
44
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
45
+ s.add_dependency(%q<jeweler>, [">= 0"])
46
+ s.add_dependency(%q<minitest>, ["~> 4.0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<simplecov>, [">= 0"])
50
+ s.add_dependency(%q<multi_json>, [">= 0"])
51
+ s.add_dependency(%q<yard>, ["~> 0.8"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
53
+ s.add_dependency(%q<jeweler>, [">= 0"])
54
+ s.add_dependency(%q<minitest>, ["~> 4.0"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,59 @@
1
+
2
+ module EasyCov
3
+ module Filters
4
+
5
+ class << self
6
+ # Get the list of STDLIB load paths
7
+ def stdlib_paths
8
+ return @stdlib_paths if !@stdlib_paths.nil?
9
+
10
+ # load
11
+ opt, lib = ENV.delete("RUBYOPT"), ENV.delete("RUBYLIB")
12
+ @stdlib_paths ||= `ruby -e 'puts $:'`.strip.split(/\n/)
13
+ ENV["RUBYOPT"] = opt
14
+ ENV["RUBYLIB"] = lib
15
+
16
+ return @stdlib_paths
17
+ end
18
+ end
19
+
20
+ # Ignore files in <root>/test/
21
+ IGNORE_TESTS = lambda { |filename|
22
+ filename =~ %r{^#{EasyCov.root}/test/}
23
+ }
24
+
25
+ # Ignore all filfes outside EasyCov.root (pwd by default)
26
+ IGNORE_OUTSIDE_ROOT = lambda { |filename|
27
+ filename !~ /^#{EasyCov.root}/
28
+ }
29
+
30
+ # Ignore all ruby STDLIB files
31
+ IGNORE_STDLIB = lambda { |filename|
32
+ EasyCov::Filters.stdlib_paths.each do |path|
33
+ if filename =~ /^#{path}/ then
34
+ return true
35
+ end
36
+ end
37
+ false
38
+ }
39
+
40
+ # Ignore all gems (uses GEM_PATH if set, else /gems/ in filename)
41
+ IGNORE_GEMS = lambda { |filename|
42
+ if ENV["GEM_PATH"] && !ENV["GEM_PATH"].empty? then
43
+ # use GEM_PATH if avail
44
+ ENV["GEM_PATH"].split(':').each do |path|
45
+ if filename =~ /^#{path}/ then
46
+ return true
47
+ end
48
+ end
49
+
50
+ false
51
+
52
+ else
53
+ # simple regex
54
+ filename =~ %r{/gems/}
55
+ end
56
+ }
57
+
58
+ end
59
+ end
data/lib/easycov.rb ADDED
@@ -0,0 +1,185 @@
1
+
2
+ require "coverage"
3
+ require "fileutils"
4
+
5
+ require "simplecov"
6
+ require "multi_json"
7
+
8
+ require "easycov/filters"
9
+
10
+ module EasyCov
11
+
12
+ include EasyCov::Filters
13
+
14
+ class << self
15
+ attr_accessor :root, :path, :resolve_symlinks
16
+
17
+ # Start coverage engine
18
+ # Can be run multiple times without side-effect.
19
+ def start
20
+ return if ENV["DISABLE_EASYCOV"] == "1"
21
+ @resolve_symlinks = true if @resolve_symlinks.nil?
22
+ @path ||= File.expand_path("coverage")
23
+ @root ||= Dir.pwd # only set first time
24
+ Coverage.start
25
+ end
26
+
27
+ # Dump coverage to disk in a thread-safe way
28
+ def dump
29
+ return if ENV["DISABLE_EASYCOV"] == "1"
30
+ Coverage.start # always make sure we are started
31
+
32
+ FileUtils.mkdir_p(@path)
33
+
34
+ if ENV["PARALLEL_EASYCOV"] == "1" then
35
+ # in parallel mode, write output to separate files for each process
36
+ # to be merged later, via #merge
37
+ write_json(File.join(@path, ".tmp.#{$$}.resultset.json"))
38
+ return
39
+ end
40
+
41
+ # default is to lock the output file
42
+ output = File.join(@path, ".resultset.json")
43
+ EasyCov.lock(output) do
44
+ write_json(output)
45
+ end
46
+
47
+ end # dump
48
+
49
+ # Write coverage to disk and restart
50
+ def checkpoint
51
+ dump()
52
+ start()
53
+ end
54
+
55
+ # List of filters
56
+ def filters
57
+ @filters ||= []
58
+ end
59
+
60
+ # Add filter block
61
+ def filter(&block)
62
+ filters << block
63
+ end
64
+
65
+ # Set path to coverage dir
66
+ def path=(path)
67
+ @path = File.expand_path(path)
68
+ end
69
+
70
+ def install_exit_hook
71
+ return if ENV["DISABLE_EASYCOV"] == "1"
72
+ Kernel.at_exit do
73
+ EasyCov.checkpoint
74
+ end
75
+ end
76
+
77
+ # Merge all temporary coverage files into main file
78
+ def merge!
79
+
80
+ output = File.join(@path, ".resultset.json")
81
+ files = [ output ] + Dir.glob(File.join(@path, ".tmp.*.resultset.json"))
82
+
83
+ data = {}
84
+ files.each do |f|
85
+ next if !File.exists? f
86
+ data.merge!(MultiJson.load(File.read(f)))
87
+ File.delete(f)
88
+ end
89
+
90
+ # write to final dest
91
+ File.open(output+".tmp", 'w'){ |f| f.write(MultiJson.dump(data)) }
92
+ File.rename(output+".tmp", output)
93
+ end
94
+
95
+ # Create a flock on the given file
96
+ #
97
+ # @param [String] lockfile to lock on
98
+ # @param [Block]
99
+ def lock(lockfile, &block)
100
+ lockfile = "#{lockfile}.lock"
101
+
102
+ FileUtils.touch(lockfile)
103
+ lock = File.new(lockfile)
104
+ lock.flock(File::LOCK_EX)
105
+
106
+ block.call()
107
+
108
+ begin
109
+ lock.flock(File::LOCK_UN)
110
+ rescue
111
+ end
112
+
113
+ begin
114
+ File.delete(lockfile)
115
+ rescue
116
+ end
117
+ end
118
+
119
+
120
+
121
+ private
122
+
123
+ # Apply filters
124
+ def apply_filters(result)
125
+
126
+ ret = {}
127
+
128
+ if @resolve_symlinks then
129
+ # resolve any symlinks in paths
130
+ result.each do |file,cov|
131
+ next if not File.exists? file
132
+ f = File.realpath(file)
133
+ if f != file then
134
+ ret[f] = cov
135
+ else
136
+ ret[file] = cov
137
+ end
138
+ end
139
+
140
+ else
141
+ ret = result.dup
142
+ end
143
+
144
+ # apply filters
145
+ filters.each do |filter|
146
+ ret.delete_if { |file, cov|
147
+ filter.call(file)
148
+ }
149
+ end
150
+
151
+ return ret
152
+ end
153
+
154
+ def write_json(output)
155
+ # load existing if avail
156
+ data = File.exists?(output) ? MultiJson.load(File.read(output)) : {}
157
+
158
+ # merge our data
159
+ result = apply_filters(Coverage.result)
160
+
161
+ time = Time.new
162
+ name = "Test #{time.strftime('%Y%m%d.%H%M%S')} #{Random.rand(1_000_000)}"
163
+ data[name] = {
164
+ :coverage => result,
165
+ :timestamp => time.to_i
166
+ }
167
+
168
+ # write to tmp file then move, in case we err out
169
+ File.open(output+".tmp", 'w'){ |f| f.write(MultiJson.dump(data)) }
170
+ File.rename(output+".tmp", output)
171
+ end
172
+
173
+ end # self
174
+
175
+ TOP_PID = Process.pid
176
+ end
177
+
178
+ # Patch to use our path
179
+ module SimpleCov
180
+ class << self
181
+ def coverage_path
182
+ EasyCov.path
183
+ end
184
+ end
185
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easycov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chetan Sarva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ description: An easy to use, simplecov-compatibile code coverage library for Ruby
98
+ email: chetan@pixelcop.net
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - Rakefile
106
+ - VERSION
107
+ - easycov.gemspec
108
+ - lib/easycov.rb
109
+ - lib/easycov/filters.rb
110
+ homepage: http://github.com/chetan/easycov
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.0.5
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby code coverage library
134
+ test_files: []