coveralls-lcov 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coveralls-lcov.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kenji Okimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Coveralls::Lcov
2
+
3
+ Upload coverage information generated by LCOV to coveralls.io.
4
+
5
+ coveralls-lcov supports travis-ci.org only.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'coveralls-lcov'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install coveralls-lcov
20
+
21
+ ## Usage
22
+
23
+ In .travis.yml
24
+
25
+ ```
26
+ install:
27
+ - sudo apt-get install -y lcov
28
+ - sudo gem install coveralls-lcov
29
+ before_script:
30
+ - ./autogen.sh
31
+ - ./configure --enable-coverage
32
+ script:
33
+ - make check
34
+ after_success:
35
+ - lcov --compat-libtool --directory . --capture --output-file coverage.info
36
+ - coveralls-lcov coverage.info
37
+ ```
38
+
39
+ or by hand
40
+
41
+ ```
42
+ $ coveralls-lcov --repo-token "YOUR TOKEN" coverage.info
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/<my-github-username>/coveralls-lcov/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "coveralls/lcov/runner"
4
+
5
+ Coveralls::Lcov::Runner.new(ARGV).run
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coveralls/lcov/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "coveralls-lcov"
8
+ spec.version = Coveralls::Lcov::VERSION
9
+ spec.authors = ["Kenji Okimoto"]
10
+ spec.email = ["okimoto@clear-code.com"]
11
+ spec.summary = %q{Post coverage information to coveralls.io}
12
+ spec.description = %q{Post coverage information to coveralls.io}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,7 @@
1
+ require "coveralls/lcov/version"
2
+
3
+ module Coveralls
4
+ module Lcov
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,74 @@
1
+
2
+ module Coveralls
3
+ module Lcov
4
+ class Converter
5
+ def initialize(tracefile)
6
+ @tracefile = tracefile
7
+ end
8
+
9
+ def convert
10
+ source_files = []
11
+ lcov_info = parse_tracefile
12
+ lcov_info.each do |filename, info|
13
+ source_files << generate_source_file(filename, info)
14
+ end
15
+ payload = {
16
+ :service_name => "travis-ci",
17
+ :service_job_id => ENV["TRAVIS_JOB_ID"],
18
+ :git => git_info,
19
+ :source_files => source_files,
20
+ }
21
+ payload
22
+ end
23
+
24
+ def parse_tracefile
25
+ lcov_info = Hash.new{|h,k| h[k] = {} }
26
+ source_file = nil
27
+ File.readlines(@tracefile).each do |line|
28
+ case line.chomp
29
+ when /\ASF:(.+)/
30
+ source_file = $1
31
+ when /\ADA:(\d+),(\d+)/
32
+ line_no = $1.to_i
33
+ count = $2.to_i
34
+ lcov_info[source_file][line_no] = count
35
+ when /\Aend_of_record/
36
+ source_file = nil
37
+ end
38
+ end
39
+ lcov_info
40
+ end
41
+
42
+ def generate_source_file(filename, info)
43
+ source = File.read(filename)
44
+ lines = source.lines
45
+ coverage = Array.new(lines.to_a.size)
46
+ source.lines.each_with_index do |line, index|
47
+ coverage[index] = info[index + 1]
48
+ end
49
+ top_src_dir = Dir.pwd
50
+ {
51
+ :name => filename.sub(%r!#{top_src_dir}/!, ""),
52
+ :source => source,
53
+ :coverage => coverage,
54
+ }
55
+ end
56
+
57
+ def git_info
58
+ {
59
+ :head => {
60
+ :id => `git log -1 --format=%H`,
61
+ :committer_email => `git log -1 --format=%ce`,
62
+ :committer_name => `git log -1 --format=%cN`,
63
+ :author_email => `git log -1 --format=%ae`,
64
+ :author_name => `git log -1 --format=%aN`,
65
+ :message => `git log -1 --format=%s`,
66
+ },
67
+ :remotes => [], # FIXME need this?
68
+ :branch => `git rev-parse --abbrev-ref HEAD`,
69
+ }
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,77 @@
1
+ require "optparse"
2
+ require "json"
3
+ require "net/http"
4
+ require "coveralls/lcov/converter"
5
+
6
+ module Coveralls
7
+ # URI: https://coveralls.io/api/v1/jobs
8
+ HOST = "coveralls.io"
9
+ PATH = "/api/v1/jobs"
10
+
11
+ module Lcov
12
+ class Runner
13
+ def initialize(argv)
14
+ @argv = argv
15
+ @repo_token = nil
16
+ @verbose = false
17
+ @dry_run = false
18
+ @parser = OptionParser.new(@argv)
19
+ @parser.banner = <<BANNER
20
+ Usage: coveralls-lcov [options] coverage.info
21
+
22
+ e.g. coveralls-lcov -v coverage.info
23
+
24
+ BANNER
25
+ @parser.on("-t", "--repo-token=TOKEN", "Repository token") do |token|
26
+ @repo_token = token
27
+ end
28
+ @parser.on("-v", "--verbose", "Print payload") do
29
+ @verbose = true
30
+ end
31
+ @parser.on("-n", "--dry-run", "Dry run") do
32
+ @dry_run = true
33
+ end
34
+ end
35
+
36
+ def run
37
+ @parser.parse!
38
+ unless @argv.size == 1
39
+ warn "Too many arguments! <#{@argv.join(",")}>"
40
+ warn @parser.help
41
+ exit false
42
+ end
43
+ tracefile = @argv.shift
44
+ converter = Converter.new(tracefile)
45
+ payload = converter.convert
46
+ payload[:repo_token] = @repo_token if @repo_token
47
+ payload_json = payload.to_json
48
+ puts payload_json if @verbose
49
+ unless @dry_run
50
+ post(payload_json)
51
+ end
52
+ end
53
+
54
+ def post(payload)
55
+ Net::HTTP.version_1_2
56
+
57
+ http = Net::HTTP.new(HOST, 443)
58
+ http.use_ssl = true
59
+ http.start do
60
+ request = Net::HTTP::Post.new(PATH)
61
+ request["content-type"] = "multipart/form-data; boundary=boundary"
62
+ request.body = <<BODY.gsub(/\n/, "\r\n")
63
+ --boundary
64
+ content-disposition: form-data; name="json_file"; filename="payload.json"
65
+
66
+ #{payload}
67
+
68
+ --boundary--
69
+ BODY
70
+ response = http.request(request)
71
+ p response
72
+ puts response.body
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module Coveralls
2
+ module Lcov
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coveralls-lcov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenji Okimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Post coverage information to coveralls.io
47
+ email:
48
+ - okimoto@clear-code.com
49
+ executables:
50
+ - coveralls-lcov
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/coveralls-lcov
60
+ - coveralls-lcov.gemspec
61
+ - lib/coveralls/lcov.rb
62
+ - lib/coveralls/lcov/converter.rb
63
+ - lib/coveralls/lcov/runner.rb
64
+ - lib/coveralls/lcov/version.rb
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Post coverage information to coveralls.io
90
+ test_files: []