Permalink
Browse files

updated collector for ci

Change-Id: I567043df60862b262d50d6f89a896812dada515b
  • Loading branch information...
pmenglund committed Mar 9, 2012
1 parent c819a36 commit 73266a287b15ec2e1879c1ef9bc43fd7af1252d6
View
@@ -3,3 +3,6 @@
.yardoc
.DS_Store
collector/config/dev*.yml
+ci_result/
+spec_reports
+spec_coverage
View
@@ -10,6 +10,13 @@ gem "yajl-ruby"
group :test do
gem "rspec"
- gem "rcov", :platform => :ruby_18
- gem "simplecov", :platform => :ruby_19
+
+ gem "ci_reporter"
+
+ gem "rcov", :platforms => :ruby_18
+ gem "rcov_analyzer", ">= 0.2", :platforms => :ruby_18
+
+ gem "simplecov", :platforms => :ruby_19
+ gem "simplecov-clover", :platforms => :ruby_19
+ gem "simplecov-rcov", :platforms => :ruby_19
end
View
@@ -2,6 +2,9 @@ GEM
remote: http://rubygems.org/
specs:
addressable (2.2.6)
+ builder (3.0.0)
+ ci_reporter (1.7.0)
+ builder (>= 2.1.2)
daemons (1.1.6)
diff-lcs (1.1.3)
em-http-request (0.3.0)
@@ -24,6 +27,9 @@ GEM
rack (1.4.1)
rake (0.9.2.2)
rcov (1.0.0)
+ rcov_analyzer (0.2)
+ builder
+ rcov
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
@@ -35,7 +41,11 @@ GEM
simplecov (0.5.4)
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
+ simplecov-clover (0.0.1)
+ simplecov (>= 0.4.1)
simplecov-html (0.5.3)
+ simplecov-rcov (0.2.3)
+ simplecov (>= 0.4.1)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
@@ -54,13 +64,17 @@ PLATFORMS
ruby
DEPENDENCIES
+ ci_reporter
em-http-request
eventmachine (~> 0.12.11.cloudfoundry.3)
nats
rake
rcov
+ rcov_analyzer (>= 0.2)
rspec
simplecov
+ simplecov-clover
+ simplecov-rcov
vcap_common (~> 1.0.3)
vcap_logging
yajl-ruby
View
@@ -1,39 +1,43 @@
-require "bundler"
-require "rspec/core/rake_task"
+# Copyright (c) 2009-2012 VMware, Inc.
+
+$:.unshift(File.expand_path("../../rake", __FILE__))
-ENV["BUNDLE_GEMFILE"] = "Gemfile"
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __FILE__)
+
+require "rubygems"
+require "bundler"
+Bundler.setup(:default, :test)
-RSpec::Core::RakeTask.new("spec") do |t|
- t.rspec_opts = ["--format", "documentation", "--colour"]
- t.pattern = "spec/unit/**/*_spec.rb"
+require "rake"
+require "rake/dsl_definition"
+begin
+ require "rspec/core/rake_task"
+rescue
end
-task :default => :spec
+require "bundler_task"
+require "ci_task"
-if RUBY_VERSION < "1.9"
- desc "Run spec with coverage"
- RSpec::Core::RakeTask.new(:coverage => :cleanup_coverage) do |task|
- task.rcov = true
- task.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,spec/unit,spec/spec_helper.rb"]
- end
-else
- desc "Run spec with coverage"
- task :coverage => :cleanup_coverage do
- require "simplecov"
-
- SimpleCov.start do
- add_filter "/spec/"
-
- require "rspec/core"
- spec_dir = File.expand_path("../spec", __FILE__)
- RSpec::Core::Runner.disable_autorun!
- RSpec::Core::Runner.run [spec_dir], STDERR, STDOUT
+BundlerTask.new
+
+if defined?(RSpec)
+ task :default => :spec
+
+ desc "Run all tests"
+ task "spec" => "spec:unit"
+
+ namespace "spec" do
+ SPEC_OPTS = %w(--format progress --color)
+
+ desc "Run unit tests"
+ unit_rspec_task = RSpec::Core::RakeTask.new(:unit) do |t|
+ t.pattern = "spec/unit/**/*_spec.rb"
+ t.rspec_opts = SPEC_OPTS
end
- end
-end
+ CiTask.new do |task|
+ task.rspec_task = unit_rspec_task
+ end
-desc "Cleanup coverage"
-task :cleanup_coverage do
- rm_rf "coverage"
+ end
end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1 @@
+These files are copied form the bosh repo, and since they now live in two places they should be extracted into a gem...
View
@@ -0,0 +1,52 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+require "rake/tasklib"
+
+# HACK to get a clean ENV from Bundler. (already in Bundler 1.1+)
+if Gem::Version.new(Bundler::VERSION) < Gem::Version.new("1.1.0")
+ module Bundler
+ class << self
+ def with_original_env
+ bundled_env = ENV.to_hash
+ ENV.replace(ORIGINAL_ENV)
+ yield
+ ensure
+ ENV.replace(bundled_env.to_hash)
+ end
+
+ def with_clean_env
+ with_original_env do
+ ENV.delete_if { |k, _| k[0, 7] == "BUNDLE_" }
+ if ENV.has_key?("RUBYOPT")
+ ENV["RUBYOPT"] = ENV["RUBYOPT"].sub("-rbundler/setup", "")
+ end
+ yield
+ end
+ end
+ end
+ end
+end
+
+class BundlerTask < ::Rake::TaskLib
+ def initialize
+ namespace "bundler" do
+ desc "Install gems"
+ task "install" do
+ Bundler.with_clean_env do
+ sh("bundle install")
+ end
+ end
+
+ environments = %w(test development production)
+
+ environments.each do |env|
+ desc "Install gems for #{env}"
+ task "install:#{env}" do
+ Bundler.with_clean_env do
+ sh("bundle install --without #{(environments - [env]).join(" ")}")
+ end
+ end
+ end
+ end
+ end
+end
View
@@ -0,0 +1,60 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+require "pathname"
+require "rake/tasklib"
+
+class CiTask < ::Rake::TaskLib
+ attr_accessor :rspec_task
+ attr_accessor :test_reports_dir
+ attr_accessor :coverage_dir
+ attr_accessor :root_dir
+
+ def initialize
+ yield self
+
+ @root_dir ||= Dir.pwd
+ @test_reports_dir ||= File.join(@root_dir, "ci_result/reports")
+ @coverage_dir ||= File.join(@root_dir, "ci_result/coverage")
+
+ # TODO remove once CI is reconfigured
+ legacy_spec_coverage = File.join(@root_dir, "spec_coverage")
+ legacy_spec_reports = File.join(@root_dir, "spec_reports")
+
+ actual_rspec_task = Rake.application.lookup(@rspec_task.name)
+ rspec_task_description = actual_rspec_task.comment
+
+ if rspec_task_description && !rspec_task_description.empty?
+ desc("#{rspec_task_description} for CIs")
+ end
+ task("#{@rspec_task.name}:ci") do |task|
+ rm_rf(legacy_spec_coverage)
+ rm_rf(legacy_spec_reports)
+
+ rm_rf(@test_reports_dir)
+ rm_rf(@coverage_dir)
+
+ require "ci/reporter/rake/rspec"
+ ENV["CI_REPORTS"] = @test_reports_dir
+ Rake::Task["ci:setup:rspec"].execute
+
+ if RUBY_VERSION < "1.9"
+ @rspec_task.rcov = true
+ @rspec_task.rcov_opts =
+ %W{--exclude spec\/,vendor\/ -o "#{@coverage_dir}/rcov"}
+ actual_rspec_task.invoke
+ else
+ simple_cov_helper = File.expand_path("../simplecov_helper", __FILE__)
+ ENV["SPEC_OPTS"] = "#{ENV['SPEC_OPTS']} --require #{simple_cov_helper}"
+ ENV["SIMPLECOV"] = "1"
+ ENV["SIMPLECOV_ROOT"] = @root_dir
+ ENV["SIMPLECOV_EXCLUDE"] = "spec, vendor"
+ ENV["SIMPLECOV_DIR"] = Pathname.new(@coverage_dir).relative_path_from(
+ Pathname.new(root_dir)).to_s
+ actual_rspec_task.invoke
+ end
+
+ ln_s(@test_reports_dir, legacy_spec_reports)
+ ln_s(@coverage_dir, legacy_spec_coverage)
+ end
+ end
+end
View
@@ -0,0 +1,20 @@
+# Copyright (c) 2009-2012 VMware, Inc.
+
+require "rubygems"
+require "bundler"
+Bundler.setup(:default, :test)
+
+if ENV["SIMPLECOV"]
+ require "simplecov"
+ require "simplecov-rcov"
+
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
+ SimpleCov.root(ENV["SIMPLECOV_ROOT"])
+ if ENV["SIMPLECOV_EXCLUDE"]
+ ENV["SIMPLECOV_EXCLUDE"].split(",").each do |filter|
+ SimpleCov.add_filter(filter.strip)
+ end
+ end
+ SimpleCov.coverage_dir(ENV["SIMPLECOV_DIR"]) if ENV["SIMPLECOV_DIR"]
+ SimpleCov.start
+end

0 comments on commit 73266a2

Please sign in to comment.