DTR 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -0
- data/README +58 -41
- data/Rakefile +76 -15
- data/TODO +12 -2
- data/bin/dtr +50 -29
- data/install.rb +2 -3
- data/lib/dtr.rb +65 -71
- data/lib/dtr/env_store.rb +58 -0
- data/lib/dtr/inject.rb +155 -0
- data/lib/dtr/inject_with_svn.rb +8 -0
- data/lib/dtr/inject_without_updating_codebase.rb +6 -0
- data/lib/dtr/raketasks.rb +48 -0
- data/lib/dtr/ruby_ext.rb +3 -25
- data/lib/dtr/runner.rb +174 -0
- data/lib/dtr/service_provider.rb +91 -0
- data/lib/dtr/svn.rb +20 -0
- data/test/inject_test.rb +25 -0
- data/test/scenario_tests.rb +172 -0
- data/test/svn_test.rb +11 -0
- data/test/test_helper.rb +25 -108
- metadata +13 -20
- data/lib/dtr/base.rb +0 -281
- data/lib/dtr/command_line.rb +0 -173
- data/lib/dtr/drb_dtr.rb +0 -275
- data/show_process_exit_code.bat +0 -5
- data/test/average_packer_test.rb +0 -32
- data/test/base_test.rb +0 -236
- data/test/original_test_reports_test.rb +0 -91
- data/test/ruby_ext_test.rb +0 -13
- data/test/ruby_runner_test.rb +0 -56
- data/test/scenario_setup_and_run_tests_simply.rb +0 -51
- data/test/server_test.rb +0 -39
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'dtr/env_store'
|
2
|
+
require 'drb'
|
3
|
+
require 'rinda/ring'
|
4
|
+
require 'rinda/tuplespace'
|
5
|
+
|
6
|
+
module DTR
|
7
|
+
class ServiceProvider
|
8
|
+
|
9
|
+
def self.broadcast_list=(list)
|
10
|
+
EnvStore.new[:broadcast_list] = list
|
11
|
+
end
|
12
|
+
|
13
|
+
PORT = 3344
|
14
|
+
BROADCAST_LIST = []
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
puts "-- Initializing drb service..."
|
18
|
+
env_store = EnvStore.new
|
19
|
+
(env_store[:broadcast_list] || ['localhost']).each do |broadcast|
|
20
|
+
BROADCAST_LIST << broadcast.untaint
|
21
|
+
puts "-- Added broadcast: #{broadcast}"
|
22
|
+
end
|
23
|
+
DRb.start_service
|
24
|
+
end
|
25
|
+
|
26
|
+
# start DTR server
|
27
|
+
def start
|
28
|
+
puts '-- Booting DTR server...'
|
29
|
+
Rinda::RingServer.new Rinda::TupleSpace.new, PORT
|
30
|
+
puts "-- DTR server started on port #{PORT}"
|
31
|
+
#set safe level to 1 here, now, runner can't set to 1, cause test should can do anything
|
32
|
+
#......
|
33
|
+
$SAFE = 1 unless $DEBUG # disable eval() and friends
|
34
|
+
# Wait until the user explicitly kills the server.
|
35
|
+
DRb.thread.join
|
36
|
+
end
|
37
|
+
|
38
|
+
def provide(runner)
|
39
|
+
renewer = Rinda::SimpleRenewer.new
|
40
|
+
tuple = [:name, :'DTR::Runner', runner.freeze, "DTR remote runner #{runner.name}"]
|
41
|
+
lookup_ring.write(tuple, renewer)
|
42
|
+
end
|
43
|
+
|
44
|
+
def lookup_runner
|
45
|
+
lookup_ring.take([:name, :'DTR::Runner', nil, nil])[2]
|
46
|
+
end
|
47
|
+
|
48
|
+
def runners
|
49
|
+
lookup_ring.read_all([:name, :'DTR::Runner', nil, nil]).collect {|rt| rt[2]}
|
50
|
+
end
|
51
|
+
|
52
|
+
def wait_until_teardown
|
53
|
+
lookup_ring.notify(nil, [:working_env, nil]).pop
|
54
|
+
end
|
55
|
+
|
56
|
+
def working_env
|
57
|
+
lookup_ring.read([:working_env, nil])[1]
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup_working_env(env)
|
61
|
+
clear_workspace
|
62
|
+
lookup_ring.write [:working_env, env]
|
63
|
+
end
|
64
|
+
|
65
|
+
def teardown_working_env
|
66
|
+
clear_workspace
|
67
|
+
end
|
68
|
+
|
69
|
+
def start_service
|
70
|
+
DRb.start_service
|
71
|
+
end
|
72
|
+
|
73
|
+
def stop_service
|
74
|
+
DRb.stop_service
|
75
|
+
end
|
76
|
+
|
77
|
+
def clear_workspace
|
78
|
+
runners.size.times do
|
79
|
+
lookup_runner.shutdown rescue nil
|
80
|
+
end
|
81
|
+
lookup_ring.read_all([:working_env, nil]).size.times do
|
82
|
+
lookup_ring.take [:working_env, nil] rescue nil
|
83
|
+
end rescue nil
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def lookup_ring
|
88
|
+
Rinda::TupleSpaceProxy.new(Rinda::RingFinger.new(BROADCAST_LIST, PORT).lookup_ring_any)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/dtr/svn.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module DTR
|
2
|
+
class SvnRepository
|
3
|
+
def revision
|
4
|
+
output = %x[svn info]
|
5
|
+
if /Revision: (\d+)/ =~ output
|
6
|
+
$1.to_i
|
7
|
+
else
|
8
|
+
$stderr.puts "Can't get svn revision, 'svn info' output: \n#{output}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_to(revision)
|
13
|
+
return nil if revision.nil?
|
14
|
+
return "echo 'code base is #{revision}'" if revision == self.revision
|
15
|
+
return "svn update -r #{revision}" if revision && (revision == 'HEAD' || revision > 0)
|
16
|
+
$stderr.puts "Error revision number: #{revision.inspect}"
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/inject_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'dtr/inject.rb'
|
3
|
+
|
4
|
+
class InjectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def teardown
|
7
|
+
DTR.reject
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_inject
|
11
|
+
DTR.inject
|
12
|
+
assert Test::Unit::TestCase.method_defined?(:__run__)
|
13
|
+
assert Test::Unit::TestSuite.method_defined?(:__run__)
|
14
|
+
assert Test::Unit::TestSuite.method_defined?(:dtr_injected?)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_reject
|
18
|
+
DTR.inject
|
19
|
+
DTR.reject
|
20
|
+
test_case = Test::Unit::TestCase.new('name')
|
21
|
+
assert_false test_case.respond_to?(:__run__)
|
22
|
+
assert test_case.respond_to?(:run)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'test/unit/ui/console/testrunner'
|
3
|
+
require 'dtr/service_provider'
|
4
|
+
require 'dtr/inject'
|
5
|
+
require 'dtr'
|
6
|
+
$be_silent = true
|
7
|
+
$repository = NullObject.new
|
8
|
+
|
9
|
+
module Test
|
10
|
+
module Unit
|
11
|
+
class TestResult
|
12
|
+
attr_reader :errors
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ScenarioTests < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
unless defined?(ATestCase)
|
21
|
+
require 'a_test_case'
|
22
|
+
require 'a_test_case2'
|
23
|
+
require 'a_failed_test_case'
|
24
|
+
require 'an_error_test_case'
|
25
|
+
require 'test_case_revision63_failed_but_revision64_passed'
|
26
|
+
require 'a_file_system_test_case'
|
27
|
+
end
|
28
|
+
DTR.inject
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
DTR.reject
|
33
|
+
$argv_dup = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_run_test_passed
|
37
|
+
$argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
|
38
|
+
suite = Test::Unit::TestSuite.new('run_test_passed')
|
39
|
+
suite << ATestCase.suite
|
40
|
+
suite << ATestCase2.suite
|
41
|
+
suite << AFileSystemTestCase.suite
|
42
|
+
|
43
|
+
@result = runit(suite)
|
44
|
+
|
45
|
+
assert @result.passed?
|
46
|
+
assert_equal 3, @result.run_count
|
47
|
+
assert_equal 0, @result.failure_count
|
48
|
+
assert_equal 0, @result.error_count
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_run_test_failed
|
52
|
+
$argv_dup = ['a_test_case.rb', 'a_failed_test_case.rb']
|
53
|
+
suite = Test::Unit::TestSuite.new('test_run_test_failed')
|
54
|
+
suite << ATestCase.suite
|
55
|
+
suite << AFailedTestCase.suite
|
56
|
+
|
57
|
+
@result = runit(suite)
|
58
|
+
|
59
|
+
assert !@result.passed?
|
60
|
+
assert_equal 2, @result.run_count
|
61
|
+
assert_equal 1, @result.failure_count
|
62
|
+
assert_equal 0, @result.error_count
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_run_test_error
|
66
|
+
$argv_dup = ['a_test_case.rb', 'an_error_test_case.rb']
|
67
|
+
suite = Test::Unit::TestSuite.new('test_run_test_error')
|
68
|
+
suite << ATestCase.suite
|
69
|
+
suite << AnErrorTestCase.suite
|
70
|
+
|
71
|
+
logger.debug { "dtr_injected: #{Test::Unit::TestSuite.method_defined?(:dtr_injected?)}" }
|
72
|
+
@result = runit(suite)
|
73
|
+
|
74
|
+
assert_false @result.passed?
|
75
|
+
assert_equal 2, @result.run_count
|
76
|
+
assert_equal 0, @result.failure_count
|
77
|
+
assert_equal 1, @result.error_count
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_run_suite_should_be_independence
|
81
|
+
$argv_dup = ['an_error_test_case.rb']
|
82
|
+
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 1')
|
83
|
+
suite << AnErrorTestCase.suite
|
84
|
+
|
85
|
+
@result = runit(suite)
|
86
|
+
|
87
|
+
assert_false @result.passed?
|
88
|
+
assert_equal 1, @result.run_count
|
89
|
+
assert_equal 0, @result.failure_count
|
90
|
+
assert_equal 1, @result.error_count
|
91
|
+
|
92
|
+
$argv_dup = ['a_test_case.rb']
|
93
|
+
suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 2')
|
94
|
+
suite << ATestCase.suite
|
95
|
+
|
96
|
+
@result = runit(suite)
|
97
|
+
|
98
|
+
assert @result.passed?
|
99
|
+
assert_equal 1, @result.run_count
|
100
|
+
assert_equal 0, @result.failure_count
|
101
|
+
assert_equal 0, @result.error_count
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_ignore_environment_file_not_exists
|
105
|
+
$argv_dup = ['a_test_case.rb', 'test_file_not_exists.rb']
|
106
|
+
suite = Test::Unit::TestSuite.new('test_run_test_file_not_exist')
|
107
|
+
suite << ATestCase.suite
|
108
|
+
|
109
|
+
@result = runit(suite)
|
110
|
+
|
111
|
+
assert @result.passed?
|
112
|
+
assert_equal 1, @result.run_count
|
113
|
+
assert_equal 0, @result.failure_count
|
114
|
+
assert_equal 0, @result.error_count
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_run_empty_test_suite_and_no_test_files_in_environment
|
118
|
+
$argv_dup = []
|
119
|
+
suite = Test::Unit::TestSuite.new('test_run_without_test_files')
|
120
|
+
|
121
|
+
@result = runit(suite)
|
122
|
+
|
123
|
+
assert @result.passed?
|
124
|
+
assert_equal 0, @result.run_count
|
125
|
+
assert_equal 0, @result.failure_count
|
126
|
+
assert_equal 0, @result.error_count
|
127
|
+
end
|
128
|
+
|
129
|
+
def runit(suite)
|
130
|
+
Test::Unit::UI::Console::TestRunner.run(suite, Test::Unit::UI::SILENT)
|
131
|
+
end
|
132
|
+
|
133
|
+
# def test_run_specific_revision_test
|
134
|
+
# new_injected_env ['test_case_revision63_failed_but_revision64_passed.rb'], 63
|
135
|
+
# suite = Test::Unit::TestSuite.new('test_run_revision63')
|
136
|
+
# suite << TestCaseRevision63FailedButRevision64Passed.suite
|
137
|
+
# @result = runit(suite)
|
138
|
+
#
|
139
|
+
# assert_false @result.passed?
|
140
|
+
# assert_equal 1, @result.run_count
|
141
|
+
# assert_equal 1, @result.failure_count
|
142
|
+
# assert_equal 0, @result.error_count
|
143
|
+
#
|
144
|
+
# new_injected_env ['test_case_revision63_failed_but_revision64_passed.rb'], 'HEAD'
|
145
|
+
# suite = Test::Unit::TestSuite.new('test_run_revision64')
|
146
|
+
# suite << TestCaseRevision63FailedButRevision64Passed.suite
|
147
|
+
# @result = runit(suite)
|
148
|
+
#
|
149
|
+
# assert @result.passed?
|
150
|
+
# assert_equal 1, @result.run_count
|
151
|
+
# assert_equal 0, @result.failure_count
|
152
|
+
# assert_equal 0, @result.error_count
|
153
|
+
# end
|
154
|
+
|
155
|
+
def test_run_test_specified_by_load_path
|
156
|
+
lib_path = File.expand_path(File.dirname(__FILE__) + '/../testdata/lib')
|
157
|
+
$LOAD_PATH.unshift lib_path
|
158
|
+
require 'lib_test_case'
|
159
|
+
$argv_dup = ['lib_test_case.rb']
|
160
|
+
suite = Test::Unit::TestSuite.new('test_run_test_specified_by_load_path')
|
161
|
+
suite << LibTestCase.suite
|
162
|
+
|
163
|
+
@result = runit(suite)
|
164
|
+
|
165
|
+
assert @result.passed?
|
166
|
+
assert_equal 1, @result.run_count
|
167
|
+
assert_equal 0, @result.failure_count
|
168
|
+
assert_equal 0, @result.error_count
|
169
|
+
ensure
|
170
|
+
$LOAD_PATH.delete lib_path
|
171
|
+
end
|
172
|
+
end
|
data/test/svn_test.rb
ADDED
data/test/test_helper.rb
CHANGED
@@ -1,108 +1,25 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def idle?
|
27
|
-
(@executing_test_files ||= nil).nil?
|
28
|
-
end
|
29
|
-
|
30
|
-
def setup(signature)
|
31
|
-
@log = log + 'setup ' + signature
|
32
|
-
@report_signature = signature
|
33
|
-
end
|
34
|
-
|
35
|
-
def run(runner_name, test_files, signature)
|
36
|
-
@report_signature = signature
|
37
|
-
raise 'I am busy, should not ask me do anymore' unless idle?
|
38
|
-
@executing_test_files = test_files
|
39
|
-
end
|
40
|
-
|
41
|
-
def log
|
42
|
-
@log ||= ''
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module Test
|
47
|
-
module Unit
|
48
|
-
class TestCase
|
49
|
-
def assert_false(o)
|
50
|
-
assert !o
|
51
|
-
end
|
52
|
-
|
53
|
-
def new_successful_test_file
|
54
|
-
new_test_file do |file, num|
|
55
|
-
file.syswrite(%{
|
56
|
-
require 'test/unit'
|
57
|
-
class TestFile#{num} < Test::Unit::TestCase
|
58
|
-
def test_succeeded
|
59
|
-
assert true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
})
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def new_failed_test_file
|
67
|
-
new_test_file do |file, num|
|
68
|
-
file.syswrite(%{
|
69
|
-
require 'test/unit'
|
70
|
-
class TestFile#{num} < Test::Unit::TestCase
|
71
|
-
def test_failed
|
72
|
-
assert false
|
73
|
-
end
|
74
|
-
end
|
75
|
-
})
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def new_error_test_file
|
80
|
-
new_test_file do |file, num|
|
81
|
-
file.syswrite(%{
|
82
|
-
require 'test/unit'
|
83
|
-
class TestFile#{num} < Test::Unit::TestCase
|
84
|
-
def test_error
|
85
|
-
raise 'error'
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_runtime_error
|
89
|
-
should.raise.runtime.error
|
90
|
-
end
|
91
|
-
end
|
92
|
-
})
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def new_test_file
|
97
|
-
@test_file_num ||= 0
|
98
|
-
@test_file_num += 1
|
99
|
-
file_name = "#{DTROPTIONS[:tmp_dir]}/test_file#{@test_file_num}.rb"
|
100
|
-
File.open(file_name, 'w') do |file|
|
101
|
-
yield file, @test_file_num
|
102
|
-
end
|
103
|
-
|
104
|
-
file_name
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../testdata')
|
4
|
+
|
5
|
+
module Test
|
6
|
+
module Unit
|
7
|
+
class TestCase
|
8
|
+
def assert_false(o)
|
9
|
+
assert !o
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestRepository
|
16
|
+
attr_accessor :revision
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@revision = 1
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_to(revision)
|
23
|
+
"echo 'update to #{revision}'"
|
24
|
+
end
|
25
|
+
end
|