Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactoring

  • Loading branch information...
commit 15eb1d8af6024c0d740fc1c8325019d5be1269d2 1 parent c736629
@jugyo authored
View
2  bin/cilite
@@ -76,7 +76,7 @@ options = Choice.choices
CiLite::Runner.start(
:branch => options[:branch],
- :test_command => options[:command],
+ :command => options[:command],
:interval => options[:interval]
)
View
31 lib/cilite/checker.rb
@@ -1,31 +0,0 @@
-module CiLite
- class Checker
- attr_reader :branch
- attr_accessor :last_hash
-
- def initialize(branch)
- @branch = branch
- end
-
- def if_updated(&block)
- update
- hash = head
- if KVS['HEAD'] != hash
- block.call(hash)
- KVS['HEAD'] = self.last_hash = hash
- end
- end
-
- def update
- unless system("git fetch origin && git reset --hard origin/#{branch}")
- raise "failed to update origin/#{branch}"
- end
- end
-
- def head
- hash = `git rev-parse origin/#{branch}`.chomp
- raise "failed to get HEAD commit of origin/#{branch}" unless $? == 0
- hash
- end
- end
-end
View
40 lib/cilite/runner.rb
@@ -4,12 +4,14 @@ def self.start(options)
self.new(options).start
end
- attr_reader :config, :checker
- attr_accessor :testing, :started
+ attr_reader :branch, :command, :interval
+ attr_accessor :started
def initialize(options)
- @config = (KVS['config'] || {}).merge(options)
- @checker = Checker.new(@config[:branch])
+ options = (KVS['config'] || {}).merge(options)
+ @branch = options[:branch]
+ @command = options[:command]
+ @interval = options[:interval]
end
def start
@@ -19,9 +21,9 @@ def start
begin
test_if_updated
rescue Exception => e
- puts "<red>#{e.message}</red>".termcolor
+ puts "<red>#{TermColor.escape(e.to_s)}</red>".termcolor
ensure
- sleep config[:interval]
+ sleep interval
end
end
end
@@ -29,25 +31,31 @@ def start
end
def test_if_updated
- checker.if_updated do |hash|
- begin
- self.testing = true
- test(hash)
- ensure
- self.testing = false
- end
+ hash = git_update
+ unless KVS[hash]
+ test(hash)
+ end
+ end
+
+ def git_update
+ if system("git fetch origin && git reset --hard origin/#{branch}")
+ hash = `git rev-parse origin/#{branch}`.chomp
+ raise "failed to get HEAD commit of origin/#{branch}" unless $? == 0
+ hash
+ else
+ raise "failed to update origin/#{branch}"
end
end
def test(hash)
- puts "start: #{hash}", config[:test_command]
+ puts "start: #{hash}", command
- build = Build.new(config[:test_command])
+ build = Build.new(command)
build.start
Log[hash] = build.to_hash.merge(
:hash => hash,
:created_at => Time.now,
- :branch => config[:branch]
+ :branch => branch
)
output_result(hash, build)
View
0  test/tester/test_build.rb → test/cilite/test_build.rb
File renamed without changes
View
0  test/tester/test_log.rb → test/cilite/test_log.rb
File renamed without changes
View
15 test/tester/test_runner.rb → test/cilite/test_runner.rb
@@ -3,11 +3,7 @@
class TestRunner < Test::Unit::TestCase
context 'main' do
setup do
- @runner = CiLite::Runner.new({:branch => 'foo', :test_command => 'bar', :interval => 10})
- end
-
- should 'Runner.new' do
- assert_equal(@runner.config[:branch], @runner.checker.branch)
+ @runner = CiLite::Runner.new({:branch => 'foo', :command => 'bar', :interval => 10})
end
should 'test if updated' do
@@ -17,7 +13,7 @@ class TestRunner < Test::Unit::TestCase
stub(test_build_stub).status { 0 }
stub(test_build_stub).output { 'output' }
stub(test_build_stub).success? { true }
- mock(CiLite::Build).new(@runner.config[:test_command]) { test_build_stub }
+ mock(CiLite::Build).new(@runner.command) { test_build_stub }
mock(CiLite::Log).[]=.with_any_args
stub(Time).now { 'now' }
@@ -25,5 +21,12 @@ class TestRunner < Test::Unit::TestCase
@runner.test('XXXX')
$stdout = STDOUT
end
+
+ should 'not test if not updated' do
+ KVS['foo'] = 'bar'
+ stub(@runner).git_update { 'foo' }
+ mock(@runner).test('foo').times(0)
+ @runner.test_if_updated
+ end
end
end
View
27 test/tester/test_checker.rb
@@ -1,27 +0,0 @@
-require 'helper'
-require 'fakefs'
-
-class TestChecker < Test::Unit::TestCase
- context 'main' do
- setup do
- KVS.dir = 'foo'
- KVS['HEAD'] = ''
- @checker = CiLite::Checker.new('master')
- stub(@checker).update
- end
-
- should 'check updated' do
- stub(@checker).head { 'foo' }
- block = lambda {}
- mock(block).call('foo')
- # NOTE: rr が思ったような動作をしてくれないのでこんな書き方になってます...
- @checker.if_updated do |hash|
- block.call(hash)
- end
- mock(block).call('foo').times(0)
- @checker.if_updated do |hash|
- block.call(hash)
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.