slather 0.0.232 → 0.0.233

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bbb2caf17f28f8fe8f73db141d508930399ba60
4
- data.tar.gz: 41a11f359af9d87b35813a953f245100ba990e6c
3
+ metadata.gz: 0dde61485c0ba365e1030ab355fceb8a83f54822
4
+ data.tar.gz: 5f52fc6736730b6c04d0fec21284d2972fa098a8
5
5
  SHA512:
6
- metadata.gz: b803cd88dbc314d6ad08c1af670c08485d33c3274a5206ac395156202a9bf7290c46a62c4b41a3cb5e5896d62f126ccf325d8740fbd01f2ee1b33853f3990f35
7
- data.tar.gz: f487734a7facc0130c11bf9c6d7d0ab5ba6447a73ab02369c58cb223bcdb39945e20423c3c0843d10244159aef82180d5825f79e6f0f69b1579364a3f98bb3a4
6
+ metadata.gz: 68313dc2637e7b9e59cabd5961a092bd6546ae958624877311eaf1823b86fb2d4bcab0ab71728c0b31c304c57c572907b53ae8eab0eeadabec4ec55853ec50df
7
+ data.tar.gz: 8551d85897124c58a9895a8a0448a4fd2152af1c90f118263e92da4f8ecbd8fcb8e80644fb9cf21e8b6ee672430d6a5338b26a8defc5f89d7e96860e725c3eac
data/bin/slather CHANGED
@@ -1,19 +1,54 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'clamp'
4
+ require 'yaml'
4
5
  require File.join(File.dirname(__FILE__), '..', 'lib', 'slather')
5
6
 
6
7
  Clamp do
7
8
 
8
- parameter "xcodeproj", "Path to the xcodeproj", :attribute_name => :xcodeproj_path
9
- option ["--build-directory", "-b"], "BUILD_DIRECTORY", "The directory where gcno files will be written to. Defaults to derived data."
9
+ self.default_subcommand = "coverage"
10
+
11
+ subcommand "coverage", "Computes coverage for the supplised project" do
12
+
13
+ option "--project, -p", "PROJECT", "Path to the xcodeproj", :attribute_name => :xcodeproj_path
14
+
15
+ option ["--coveralls", "-c"], :flag, "Post coverage results to coveralls"
16
+ option ["--simple-output", "-s"], :flag, "Post coverage results to coveralls"
17
+
18
+ option ["--build-directory", "-b"], "BUILD_DIRECTORY", "The directory where gcno files will be written to. Defaults to derived data."
19
+ option ["--ignore", "-i"], "IGNORE", "ignore files conforming to a path", :multivalued => true
20
+
21
+ def execute
22
+ puts "Slathering..."
23
+
24
+ xcodeproj_path_to_open = xcodeproj_path || Slather::Project.yml_file["xcodeproj"]
25
+
26
+ project = Slather::Project.open(xcodeproj_path_to_open)
27
+
28
+ if coveralls?
29
+ project.extend(Slather::CoverageService::Coveralls)
30
+ elsif simple_output?
31
+ project.extend(Slather::CoverageService::SimpleOutput)
32
+ end
33
+
34
+ project.ignore_list = ignore_list if !ignore_list.empty?
35
+ project.build_directory = build_directory if build_directory
36
+ project.post
37
+
38
+ puts "Done slathering!"
39
+ end
10
40
 
11
- def execute
12
- puts "Slathering..."
13
- project = Slather::Project.open(xcodeproj_path)
14
- project.build_directory = build_directory
15
- project.post_to_coveralls
16
- puts "Done slathering!"
17
41
  end
18
42
 
43
+ subcommand "setup", "Configures an xcodeproj for test coverage generation" do
44
+
45
+ parameter "[xcodeproj]", "Path to the xcodeproj", :attribute_name => :xcodeproj_path
46
+
47
+ def execute
48
+ project = Slather::Project.open(xcodeproj_path)
49
+ project.setup_for_coverage
50
+ project.save
51
+ end
52
+
53
+ end
19
54
  end
@@ -11,7 +11,7 @@ module Slather
11
11
  @source_file_pathname ||= begin
12
12
  base_filename = gcno_file_pathname.basename.sub_ext("")
13
13
  # TODO: Handle Swift
14
- path = Dir["#{project.main_group.real_path}/*/#{base_filename}.m"].first
14
+ path = Dir["#{project.main_group.real_path}/**/#{base_filename}.m"].first
15
15
  path && Pathname(path)
16
16
  end
17
17
  end
@@ -0,0 +1,27 @@
1
+ module Slather
2
+ module CoverageService
3
+ module Coveralls
4
+
5
+ def coverage_file_class
6
+ Slather::CoverallsCoverageFile
7
+ end
8
+
9
+ def coveralls_coverage_data
10
+ {
11
+ :service_job_id => ENV['TRAVIS_JOB_ID'],
12
+ :service_name => "travis-ci",
13
+ :source_files => coverage_files.map(&:as_json)
14
+ }.to_json
15
+ end
16
+ private :coveralls_coverage_data
17
+
18
+ def post
19
+ f = File.open('coveralls_json_file', 'w+')
20
+ f.write(coveralls_coverage_data)
21
+ `curl -s --form json_file=@#{f.path} https://coveralls.io/api/v1/jobs`
22
+ FileUtils.rm(f)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module Slather
2
+ module CoverageService
3
+ module SimpleOutput
4
+
5
+ def coverage_file_class
6
+ Slather::CoverallsCoverageFile
7
+ end
8
+
9
+ def post
10
+ total_project_lines = 0
11
+ total_project_lines_tested = 0
12
+ coverage_files.each do |coverage_file|
13
+ # ignore lines that don't count towards coverage (comments, whitespace, etc). These are nil in the array.
14
+ coverage_data = coverage_file.coverage_data.compact
15
+
16
+ lines_tested = coverage_data.select { |cd| cd > 0 }.count
17
+ total_lines = coverage_data.count
18
+ percentage = '%.2f' % [(lines_tested / total_lines.to_f) * 100.0]
19
+
20
+ total_project_lines_tested += lines_tested
21
+ total_project_lines += total_lines
22
+
23
+ puts "#{coverage_file.source_file_pathname_relative_to_project_root}: #{lines_tested} of #{total_lines} lines (#{percentage}%)"
24
+ end
25
+ total_percentage = '%.2f' % [(total_project_lines_tested / total_project_lines.to_f) * 100.0]
26
+ puts "Test Coverage: #{total_percentage}%"
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -1,11 +1,18 @@
1
1
  require 'fileutils'
2
2
  require 'xcodeproj'
3
3
  require 'json'
4
+ require 'yaml'
4
5
 
5
6
  module Slather
6
7
  class Project < Xcodeproj::Project
7
8
 
8
- attr_accessor :build_directory
9
+ attr_accessor :build_directory, :ignore_list
10
+
11
+ def self.open(xcodeproj)
12
+ proj = super
13
+ proj.configure_from_yml
14
+ proj
15
+ end
9
16
 
10
17
  def derived_data_dir
11
18
  File.expand_path('~') + "/Library/Developer/Xcode/DerivedData/"
@@ -18,37 +25,55 @@ module Slather
18
25
  private :build_directory
19
26
 
20
27
  def coverage_files
21
- Dir["#{build_directory}/**/*.gcno"].map do |file|
22
- coverage_file = Slather::CoverallsCoverageFile.new(file)
28
+ coverage_files = Dir["#{build_directory}/**/*.gcno"].map do |file|
29
+ coverage_file = coverage_file_class.new(file)
23
30
  coverage_file.project = self
24
- # If there's no source file for this gcno, or the gcno is old, it probably belongs to another project.
25
- if coverage_file.source_file_pathname
26
- stale_seconds_limit = 60
27
- if (Time.now - File.mtime(file) < stale_seconds_limit)
28
- next coverage_file
29
- else
30
- puts "Skipping #{file} -- older than #{stale_seconds_limit} seconds ago."
31
- end
31
+ # If there's no source file for this gcno, it probably belongs to another project.
32
+ if coverage_file.source_file_pathname && !(coverage_file.source_file_pathname_relative_to_project_root.to_s =~ /^(#{ignore_list.join("|")})$/)
33
+ coverage_file
34
+ else
35
+ nil
32
36
  end
33
- next nil
34
37
  end.compact
38
+
39
+ if coverage_files.empty?
40
+ raise StandardError, "No coverage files found. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.pbxproj`"
41
+ else
42
+ coverage_files
43
+ end
35
44
  end
36
45
  private :coverage_files
37
46
 
38
- def coveralls_coverage_data
39
- {
40
- :service_job_id => ENV['TRAVIS_JOB_ID'],
41
- :service_name => "travis-ci",
42
- :source_files => coverage_files.map(&:as_json)
43
- }.to_json
47
+ def self.yml_file
48
+ @yml_file ||= begin
49
+ yml_filename = '.slather.yml'
50
+ if File.exist?(yml_filename)
51
+ YAML.load_file(yml_filename)
52
+ else
53
+ {}
54
+ end
55
+ end
56
+ end
57
+
58
+ def configure_from_yml
59
+ self.build_directory = self.class.yml_file["build_directory"] if self.class.yml_file["build_directory"]
60
+ self.ignore_list = self.class.yml_file["ignore"] || []
61
+
62
+ coverage_service = self.class.yml_file["coverage_service"]
63
+ if coverage_service == "coveralls"
64
+ extend(Slather::CoverageService::Coveralls)
65
+ elsif coverage_service == "terminal"
66
+ extend(Slather::CoverageService::SimpleOutput)
67
+ elsif !self.class.method_defined?(:post)
68
+ raise ArgumentError, "value `#{coverage_service}` not valid for key `coverage_service` in #{self.class.yml_file.path}. Try `terminal` or `coveralls`"
69
+ end
44
70
  end
45
- private :coveralls_coverage_data
46
71
 
47
- def post_to_coveralls
48
- f = File.open('coveralls_json_file', 'w+')
49
- f.write(coveralls_coverage_data)
50
- `curl -s --form json_file=@#{f.path} https://coveralls.io/api/v1/jobs`
51
- FileUtils.rm(f)
72
+ def setup_for_coverage
73
+ build_configurations.each do |build_configuration|
74
+ build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
75
+ build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"] = "YES"
76
+ end
52
77
  end
53
78
 
54
79
  end
@@ -1,3 +1,3 @@
1
1
  module Slather
2
- VERSION = "0.0.232"
2
+ VERSION = "0.0.233"
3
3
  end
data/lib/slather.rb CHANGED
@@ -2,6 +2,8 @@ require 'slather/version'
2
2
  require 'slather/project'
3
3
  require 'slather/coverage_file'
4
4
  require 'slather/coveralls_coverage_file'
5
+ require 'slather/coverage_service/coveralls'
6
+ require 'slather/coverage_service/simple_output'
5
7
 
6
8
  module Slather
7
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.232
4
+ version: 0.0.233
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,8 @@ files:
110
110
  - bin/slather
111
111
  - lib/slather.rb
112
112
  - lib/slather/coverage_file.rb
113
+ - lib/slather/coverage_service/coveralls.rb
114
+ - lib/slather/coverage_service/simple_output.rb
113
115
  - lib/slather/coveralls_coverage_file.rb
114
116
  - lib/slather/project.rb
115
117
  - lib/slather/version.rb