Permalink
Browse files

wip

  • Loading branch information...
1 parent 63b3726 commit 15ae8f59cf6f53fc09df53befa1204e175f117eb Jared Grippe committed with Jan 7, 2012
View
@@ -12,6 +12,7 @@ PATH
json
log4r
open4
+ popen4
redis-namespace (~> 1)
resque (~> 1.19.0)
right_aws
@@ -24,6 +25,7 @@ PATH
GEM
remote: http://rubygems.org/
specs:
+ Platform (0.4.0)
SystemTimer (1.2.3)
actionpack (3.1.3)
activemodel (= 3.1.3)
@@ -46,7 +48,7 @@ GEM
childprocess (0.2.5)
ffi (~> 1.0.6)
columnize (0.3.5)
- daemons (1.1.4)
+ daemons (1.1.5)
diff-lcs (1.1.3)
erubis (2.7.0)
ffi (1.0.11)
@@ -56,17 +58,20 @@ GEM
json (1.6.3)
linecache (0.46)
rbx-require-relative (> 0.0.4)
- log4r (1.1.9)
+ log4r (1.1.10)
macaddr (1.5.0)
systemu (>= 2.4.0)
multi_json (1.0.4)
open4 (1.3.0)
+ popen4 (0.1.2)
+ Platform (>= 0.4.0)
+ open4 (>= 0.4.0)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
- rack-protection (1.1.4)
+ rack-protection (1.2.0)
rack
rack-test (0.6.1)
rack (>= 1.0)
@@ -98,7 +103,7 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
- sass (3.1.11)
+ sass (3.1.12)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.3.1)
@@ -109,7 +114,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- systemu (2.4.1)
+ systemu (2.4.2)
thor (0.14.6)
tilt (1.3.3)
uuid (2.3.4)
View
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "right_aws"
s.add_runtime_dependency "SystemTimer"
s.add_runtime_dependency "childprocess"
+ s.add_runtime_dependency "popen4"
s.add_runtime_dependency "log4r"
s.add_runtime_dependency "json"
s.add_runtime_dependency "open4"
@@ -10,7 +10,7 @@ def self.with_clean_env
ENV.delete("BUNDLE_GEMFILE")
ENV["RUBYOPT"] = ENV["RUBYOPT"].gsub('-rbundler/setup', ' ') if ENV["RUBYOPT"]
- yield
+ return yield
}
end
@@ -11,7 +11,7 @@ class Formatter
include ::Cucumber::Formatter::Io
def initialize step_mother, path_or_io, options
- @io = ensure_io(path_or_io, "runtimes")
+ @io = ensure_io(path_or_io, "hobson_status")
end
def before_feature feature
@@ -1,8 +1,10 @@
require 'pathname'
+require 'popen4'
+require 'childprocess'
class Hobson::Project::Workspace
- autoload :Execution, 'hobson/project/workspace/execution'
+ # autoload :Execution, 'hobson/project/workspace/execution'
attr_reader :project
@@ -19,14 +21,14 @@ def root
def checkout! sha
logger.info "checking out #{sha}"
- execute! "git fetch && git reset --hard #{sha} && git clean -df"
+ execute "git fetch && git reset --hard #{sha} && git clean -df"
end
- def ready?
+ def exists?
root.exist? && root.join('.git').directory?
end
- def prepare!
+ def create!
root.parent.mkpath
`git clone "#{project.url}" "#{root}"` or raise "unable to create workspace"
end
@@ -48,7 +50,7 @@ def bundler
end
def prepare
- execute! 'bundle install' if bundler?
+ execute 'bundle install' if bundler?
root.join('log').mkpath
end
@@ -58,14 +60,16 @@ def prepare
--quiet
--require features
--require #{Hobson.lib.join('hobson/cucumber')}
- --format Hobson::Cucumber::Formatter
+ --format pretty
--format pretty --out log/cucumber
+ --format Hobson::Cucumber::Formatter --out log/hobson_status
],
'specs' => %W[
rspec
--require #{Hobson.lib.join('hobson/rspec')}
- --format Hobson::RSpec::Formatter
+ --format documentation
--format documentation --out log/rspec
+ --format Hobson::RSpec::Formatter --out log/hobson_status
],
}
@@ -82,90 +86,76 @@ def run_tests tests, &report_progress
}
# run each test type
- %w{features specs}.each{|type|
+ %w{features specs test_units}.each{|type|
next if tests[type].blank?
logger.info "running #{type} tests"
- commands = bundler + TEST_COMMANDS[type] + tests[type]
- execute!(*commands) do |stdout, stderr|
- stdout.split("\n").each{|line|
+
+ command = "cd #{root.to_s.inspect} && "
+ command << "bundle exec " if bundler?
+ command << (TEST_COMMANDS[type] + tests[type]).join(' ')
+ command << ">> log/hobson_#{type}.log"
+
+ logger.debug "command: #{command}"
+
+ file = root.join('log/hobson_status')
+ FileUtils.touch(file)
+ status = root.join('log/hobson_status').open
+ process = ChildProcess.new(command)
+ process.io.inherit!
+
+ update = proc{
+ status.read.split("\n").each{|line|
if line =~ /^TEST:([^:]+):(START|COMPLETE):(\d+)(?::(PASS|FAIL|PENDING))?$/
report_progress.call($1, $2.downcase.to_sym, Time.at($3.to_i), $4)
end
}
+ }
+
+ with_clean_env{ process.start }
+ update.call while process.alive?
+ update.call
+ status.close
+
+ if process.crashed?
+ raise ExecutionError, "#{command.inspect} crashed with exit code #{process.exit_code}"
end
}
+ tests
end
ExecutionError = Class.new(StandardError)
- def execute! *args, &block
- execution = execute(*args, &block)
- if execution.failed?
- logger.error "COMMAND FAILED (#{execution.exit_code}) #{execution.args.inspect}"
- raise ExecutionError, "COMMAND: #{execution.args.inspect}\nEXIT: #{execution.exit_code}"
- end
- execution
- end
-
def execute *args, &block
- prepare! unless ready?
+ create! unless exists?
command = "cd #{root.to_s.inspect} && #{args.join(' ')}"
command = "source #{rvm_source_file.inspect} && rvm rvmrc trust #{root.to_s.inspect} > /dev/null && #{command}" if rvm?
command = "bash -lc #{command.inspect}"
logger.info "executing: #{command.inspect}"
- execution = Execution.new(command, &block)
+ with_clean_env{
+ output = nil
+ errors = nil
+ status = POpen4::popen4(command){|stdout, stderr, stdin|
+ output = stdout.read
+ errors = stderr.read
+ }
+ raise ExecutionError, "#{command.inspect} could not be started" if status.nil?
+ raise ExecutionError, "#{command.inspect} crashed with exit code #{$?.exitstatus}\n#{errors}" unless $?.success?
+ return output
+ }
+ end
+
+ def with_clean_env &block
Hobson::Bundler.with_clean_env{
# TODO this should probably be somewhere better
ENV['RAILS_ENV'] = 'test'
ENV['DISPLAY' ] = ':1'
- execution.start
- }
-
- execution.read_loop{|out, err|
- logger.info "\n\n?????\n\n"
- logger.info out if out.present?
- logger.error err if err.present?
- yield out, err if block_given?
+ return yield
}
end
-
- # process = ChildProcess.new(command)
- # process.io.stdout = Tempfile.new("hobson_exec")
- # process.io.stderr = Tempfile.new("hobson_exec")
- # stdout = File.open(process.io.stdout.path)
- # stderr = File.open(process.io.stderr.path)
-
- # Hobson::Bundler.with_clean_env{
- # # TODO this should probably be somewhere better
- # ENV['RAILS_ENV'] = 'test'
- # ENV['DISPLAY' ] = ':1'
- # process.start
- # }
-
- # read = proc do
- # out, err = stdout.read, stderr.read
- # logger.debug out if out.present?
- # logger.debug err if err.present?
- # if (out+err).include?('Segmentation fault')
- # raise ExecutionError, "#{cmd}\n\n#{out}\n#{err}"
- # end
- # yield out, err if block_given?
- # end
-
- # while process.alive?
- # read.call
- # sleep 0.25
- # end
-
- # read.call
-
- # process
- # end
-
def inspect
"#<#{self.class} project:#{project.name} root:#{root}>"
end
Oops, something went wrong. Retry.

0 comments on commit 15ae8f5

Please sign in to comment.