Skip to content

Commit

Permalink
Initial implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 1, 2018
0 parents commit a703c9f
Show file tree
Hide file tree
Showing 17 changed files with 575 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
3 changes: 3 additions & 0 deletions .rspec
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
7 changes: 7 additions & 0 deletions .travis.yml
@@ -0,0 +1,7 @@
sudo: false
language: ruby

rvm:
- 2.6

before_install: gem install bundler -v 1.16.2
6 changes: 6 additions & 0 deletions Gemfile
@@ -0,0 +1,6 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in covered.gemspec
gemspec
61 changes: 61 additions & 0 deletions README.md
@@ -0,0 +1,61 @@
# Covered

Covered uses modern Ruby features to generate comprehensive coverage, including support for templates which are compiled into Ruby.

[![covered Status](https://secure.travis-ci.org/ioquatix/covered.svg)](http://travis-ci.org/ioquatix/covered)
[![Code Climate](https://codeclimate.com/github/ioquatix/covered.svg)](https://codeclimate.com/github/ioquatix/covered)
[![Coverage Status](https://coveralls.io/repos/ioquatix/covered/badge.svg)](https://coveralls.io/r/ioquatix/covered)

## Installation

Add this line to your application's Gemfile:

gem 'covered'

And then execute:

$ bundle

Or install it yourself as:

$ gem install covered

## Usage

For `rspec`, simply include the following from your `spec_helper.rb`

```ruby
require 'covered/rspec'
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## License

Released under the MIT license.

Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 6 additions & 0 deletions Rakefile
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
28 changes: 28 additions & 0 deletions covered.gemspec
@@ -0,0 +1,28 @@

require_relative "lib/covered/version"

Gem::Specification.new do |spec|
spec.name = "covered"
spec.version = Covered::VERSION
spec.authors = ["Samuel Williams"]
spec.email = ["samuel.williams@oriontransfer.co.nz"]

spec.summary = "A modern approach to code coverage."
spec.homepage = "https://github.com/ioquatix/covered"

# Specify which files should be added to the gem when it is released.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end

spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.required_ruby_version = '~> 2.6'

spec.add_dependency "rainbow"

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
end
25 changes: 25 additions & 0 deletions lib/covered.rb
@@ -0,0 +1,25 @@
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require_relative "covered/version"

require_relative "covered/report"
require_relative "covered/files"
require_relative "covered/capture"
25 changes: 25 additions & 0 deletions lib/covered/ast.rb
@@ -0,0 +1,25 @@
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

class RubyVM::AST::Node
def executable?
self.type =~ /CALL/
end
end
56 changes: 56 additions & 0 deletions lib/covered/capture.rb
@@ -0,0 +1,56 @@
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'rainbow'

module Covered
class Capture
def initialize(output)
@paths = {}

@line_trace = TracePoint.new(:line) do |trace_point|
if path = trace_point.path
# if path =~ /\.xnode$/
# binding.pry
# end
#
output.mark(path, trace_point.lineno)
end
end
#
# @call_trace = TracePoint.new(:c_call) do |trace_point|
# if trace_point.method_id == :eval
# end
# end
end

attr :paths

def enable
# @call_trace.enable
@line_trace.enable
end

def disable
@line_trace.disable
# @call_trace.disable
end
end
end
69 changes: 69 additions & 0 deletions lib/covered/eval.rb
@@ -0,0 +1,69 @@
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module Kernel
class << self
alias_method :original_eval, :eval

def eval(*args)
puts args.inspect
original_eval(*args)
end
end

private

alias_method :original_eval, :eval

def eval(*args)
puts args.inspect
original_eval(*args)
end
end

class Binding
alias_method :original_eval, :eval

def eval(*args)
puts args.inspect
original_eval(*args)
end
end

class BasicObject
alias_method :original_instance_eval, :instance_eval

def instance_eval(*args, &block)
puts args.inspect
original_instance_eval(*args, &block)
end
end

class Module
alias_method :original_module_eval, :module_eval

def module_eval(*args, &block)
puts args.inspect
original_module_eval(*args, &block)
end

remove_method :class_eval
alias_method :class_eval, :module_eval
end
81 changes: 81 additions & 0 deletions lib/covered/files.rb
@@ -0,0 +1,81 @@
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module Covered
class Files
def initialize
@paths = {}
end

attr :paths

def mark(path, lineno)
file = @paths[path] ||= []
if file[lineno]
file[lineno] += 1
else
file[lineno] = 1
end
end

def each(&block)
@paths.each(&block)
end
end

class Ignore
def initialize(pattern, output)
@pattern = pattern
@output = output
end

def mark(path, lineno)
@output.mark(path, lineno) unless @pattern.match? path
end
end

class Group
def initialize(patterns, output)
@patterns = patterns
@output = output
end

def mark(path, lineno)
@patterns.each do |pattern, output|
return output.mark(path, lineno) if pattern.match? path
end

@output.mark(path, lineno) if @output
end
end

class Relative
def initialize(root, output)
@root = root
@output = output
end

def mark(path, lineno)
if path.start_with? @root
@output.mark(path, lineno)
end
end
end
end

0 comments on commit a703c9f

Please sign in to comment.