Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Update README
  Fixed gem case in travis file
  Enabled gem publish from travis
  Added option to generate a plaintext percent file
  Ensure that XCS_SOURCE_DIR var is nil for dev test
  Removed bundler/setup (It was causing alcove/version to not be found.)
  Specify minitest version in gemspec.
  Travis build now runs tests
  Added rake ci to build and test
  Added a few tests.
  Update README.md
  Moved the scripty stuff into bin/alcove
  Minor style changes. ' replaced with " Removed explicit returns in most places. String#+ replaced with String#<<
  Fixed rename.
  Added TomDoc comments.
  Changed indentation to 2 spaces
  Cleanup and minor refactoring

Conflicts:
	README.md
  • Loading branch information
voidrender committed Feb 23, 2015
2 parents 88df96e + 5521a13 commit 25140f0
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 175 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
language: ruby
cache: bundler
rvm:
- 2.0.0
script: rake build
- 2.0.0
script: bundle exec rake ci
deploy:
provider: rubygems
api_key:
secure: QQevlWTpIwUsCHZf2kAbBc6YjedIV+T5IBvvNRnU5Uj/u+gbmpwtYqHuS0SYPGlAiCQFld7FpJ1K20FAsygUZqQaQqr8L85d++0qvaDqTmXm7OgLX4Q1ZxVYgCDA3MnDUY/oLnWmcQ7FwcvQH4yceuNXkBKLRm+OW4c2USvGNDk=
gem: alcove
on:
repo: ioveracker/Alcove
all_branches: true
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
source 'https://rubygems.org'
gem 'rake', '~> 10.4'
gem 'colored', '~> 1.2'

group :test do
gem 'minitest', '~> 5.5'
end
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# Alcove [![Gem Version](https://badge.fury.io/rb/alcove.svg)](http://badge.fury.io/rb/alcove) [![Build Status](https://travis-ci.org/ioveracker/Alcove.svg?branch=master)](https://travis-ci.org/ioveracker/Alcove)
# Alcove [![Gem Version](https://badge.fury.io/rb/alcove.svg)](http://badge.fury.io/rb/alcove) [![Build Status](https://travis-ci.org/ioveracker/Alcove.svg?branch=master)](https://travis-ci.org/ioveracker/Alcove) [![Code Climate](https://codeclimate.com/github/ioveracker/Alcove/badges/gpa.svg)](https://codeclimate.com/github/ioveracker/Alcove)
Painless code coverage reporting for Objective-C projects. Most of the heavy lifting is done by the venerable lcov. Alcove simply searches the nooks and crannies to collect the data needed to generate the report and ties everything together for you. Best of all, it's a gem with minimal depedencies, so installation is quick and painless.

## Installation

$ gem install alcove

If you don't have it already, you'll also need to install lcov.

*Homebrew*
You'll also need to install lcov.

With *Homebrew*:

$ brew install lcov

*MacPorts*
Or with *MacPorts*:

$ sudo port install lcov

## Xcode Project Configuration
If you haven't already, open your project in Xcode and update your non-test targets to Generate Test Coverage Files and Instrument Program Flow *for Debug configuration only*).
Open your project in Xcode and update your non-test targets to Generate Test Coverage Files and Instrument Program Flow (*for Debug configuration only*).
![Xcode](http://i.imgur.com/xdcg4er.png?1)

## Generating Reports
Now that you have the prerequisites out of the way, you can generate a report. Make sure you've recently executed your tests, then:

alcove --product-name <your-product-name>

Be sure to check out the --help for additional options for fine-tuning your report.

## Options

### --output-directory
Specify this option to change the output directory for the report. Any intermediate paths will be created.

### --percent-file
Generates a plaintext file `alcove-percent.txt` in the output directory, containing only the line coverage percentage.

### --product-name
The product name specified in your Xcode project.

Expand All @@ -40,8 +41,8 @@ A list of filters to use when gathering files for the report. Use this if you w
### --search-directory
Use this option to specify the directory to be searched for your product. Alcove plays nicely with the the structure on your development machine, as well as on an Xcode Server, but if you have some funky output directory for your build, you can specify its parent here.

## Demo
See [AlcoveDemo](https://github.com/ioveracker/AlcoveDemo) for a demo project.
## Troubleshooting
If something doesn't seem quite right, try cleaning the build folder and then run the tests again. Make sure you can generate a report for the [demo project](https://github.com/ioveracker/AlcoveDemo), too.

## Attribution
Shoutout to [@NateBank](https://github.com/NateBank) for the [name suggestion](https://www.youtube.com/watch?v=j1Q-a5zCmhc).
## Thanks
Shoutout to [@NateBank](https://github.com/NateBank) for the [name suggestion](https://www.youtube.com/watch?v=j1Q-a5zCmhc) and inspiration.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
require 'bundler/gem_tasks'
require 'rake/testtask'

task :ci => [:test, :build]

Rake::TestTask.new do |test|
test.pattern = "test/test_*.rb"
end
30 changes: 16 additions & 14 deletions alcove.gemspec
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
require './lib/alcove/version'
Gem::Specification.new do |s|
s.name = 'alcove'
s.version = Alcove::VERSION
s.date = '2015-02-10'
s.summary = "Painless code coverage reporting for Objective-C."
s.description = "Painless code coverage reporting for Xcode projects written in Objective-C."
s.authors = ['Isaac Overacker']
s.email = '[email protected]'
s.files = Dir["lib/**/*.rb"] + %w{ bin/alcove README.md LICENSE }
s.executables = 'alcove'
s.homepage = 'https://github.com/ioveracker/alcove'
s.license = 'MIT'
s.name = 'alcove'
s.version = Alcove::VERSION
s.version = "#{s.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
s.date = Date.today.to_s
s.summary = "Painless code coverage reporting for Objective-C."
s.description = "Painless code coverage reporting for Xcode projects written in Objective-C."
s.authors = ['Isaac Overacker']
s.email = '[email protected]'
s.files = Dir["lib/**/*.rb"] + %w{ bin/alcove README.md LICENSE }
s.executables = 'alcove'
s.homepage = 'https://github.com/ioveracker/alcove'
s.license = 'MIT'

s.add_runtime_dependency 'colored', '~> 1.2'
s.add_runtime_dependency 'colored', '~> 1.2'

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'minitest', '~> 5.5'
end
151 changes: 107 additions & 44 deletions bin/alcove
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,125 @@ require 'optparse'

options = OpenStruct.new
OptionParser.new do |opts|
opts.banner = "Usage: alcove --product-name <product-name> [options]"
opts.banner = "Usage: alcove --product-name <product-name> [options]"

opts.on('-h', '--help', 'Displays the help screen') do
puts opts
exit
end
opts.on("-h", "--help", "Displays the help screen") do
puts opts
exit
end

options.output_directory = 'alcove-report'
opts.on('-o', '--output-directory DIR', 'Place report in DIR instead of default') do |o|
options.output_directory = o
end
options.output_directory = "alcove-report"
opts.on("-o", "--output-directory DIR", "Place report in DIR instead of default") do |o|
options.output_directory = o
end

options.product_name = ''
opts.on('-p', '--product-name NAME', 'The name of your product') do |p|
options.product_name = p
end
opts.on("--percent-file", "Generate a file containing coverage percent") do |p|
options.generate_percent_file = true
end

options.remove_filter = []
opts.on('-r', '--remove-filter X,Y,Z...', ::Array, 'A list of filters (e.g. *.h,main.m)') do |r|
options.remove_filter = r
end
options.product_name = ""
opts.on("-p", "--product-name NAME", "The name of your product") do |p|
options.product_name = p
end

opts.on('-s', '--search-directory DIR', 'Search in DIR for coverage files') do |s|
options.search_directory = s
end
options.remove_filter = []
opts.on("-r", "--remove-filter X,Y,Z...", ::Array, "A list of filters (e.g. *.h,main.m)") do |r|
options.remove_filter = r
end

options.verbose = false
opts.on('-v', '--verbose', 'Output additional information') do
options.verbose = true
end
opts.on("-s", "--search-directory DIR", "Search in DIR for coverage files") do |s|
options.search_directory = s
end

opts.on_tail('--version', 'Show version') do
puts Alcove::VERSION
exit
end
options.verbose = false
opts.on("-v", "--verbose", "Output additional information") do
options.verbose = true
end

begin
opts.parse!(ARGV)
if options.product_name.length == 0
puts '--product-name is required'.yellow
puts opts
exit(1)
end
rescue OptionParser::InvalidOption => e
puts e
puts opts
exit(1)
opts.on_tail("--version", "Show version") do
puts Alcove::VERSION
exit
end

begin
opts.parse!(ARGV)
if options.product_name.length == 0
STDERR.puts "--product-name is required".yellow
puts opts
exit(1)
end
rescue OptionParser::InvalidOption => e
puts e
puts opts
exit(1)
end
end

def exit_with_code(code)
FileUtils.rm_rf(Alcove::TEMP_DIR)
exit(code)
end

alcoveOptions = OpenStruct.new
alcoveOptions.output_directory = options.output_directory
alcoveOptions.product_name = options.product_name
alcoveOptions.remove_filter = options.remove_filter
alcoveOptions.search_directory = options.search_directory
alcoveOptions.verbose = options.verbose

alcove = Alcove.new(alcoveOptions)
alcove.generate_report
puts " πŸ” Generating report..."

FileUtils.rm_rf(Alcove::TEMP_DIR)
FileUtils.mkdir(Alcove::TEMP_DIR)

if options.search_directory
search_directory = options.search_directory
else
search_directory = alcove.get_search_directory
end
alcove.copy_input_files_to_temp(search_directory, options.product_name)

gi_filename_absolute = File.join(Alcove::TEMP_DIR, "alcove-info.temp")
gen_success = alcove.gen_info_files(gi_filename_absolute)
if gen_success
puts " βœ… geninfo successful".green if options.verbose
else
STDERR.puts " 🚫 geninfo failed!".red
exit_with_code(1)
end

lcov_filename_absolute = File.join(Alcove::TEMP_DIR, "alcove-lcov.info")
lcov_success = alcove.lcov(gi_filename_absolute, options.remove_filter, lcov_filename_absolute)
if lcov_success
puts " βœ… lcov successful".green if options.verbose
else
STDERR.puts " 🚫 lcov failed!".red
exit_with_code(1)
end

genhtml_success, coverage_percent = alcove.genhtml(lcov_filename_absolute, options.output_directory)
if genhtml_success
puts "" if options.verbose
puts " βœ… Successfully generated report".green

coverage_string = " πŸ“Š Line coverage: #{coverage_percent}%"
if coverage_percent < 50
puts coverage_string.red
elsif coverage_percent < 85
puts coverage_string.yellow
else
puts coverage_string.green
end

puts " 🍻 Open #{options.output_directory}/index.html to view the report"

else
STDERR.puts " 🚫 genhtml failed!".red
exit_with_code(1)
end

if options.generate_percent_file
File.open("#{options.output_directory}/alcove-percent.txt", 'w') {|f|
f.write(coverage_percent)
}

end

exit_with_code(0)
Loading

0 comments on commit 25140f0

Please sign in to comment.