dtr 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'dtr/base.rb'
3
+
4
+ class CmdTest < Test::Unit::TestCase
5
+ def setup
6
+ @env_store = DTR::EnvStore.new
7
+ @env_store[DTR::MESSAGE_KEY] = nil
8
+ end
9
+
10
+ def teardown
11
+ @env_store[DTR::MESSAGE_KEY] = nil if @env_store[DTR::MESSAGE_KEY]
12
+ DTROPTIONS[:run_with_monitor] = nil
13
+ end
14
+
15
+ def test_should_include_error_log_when_interrupt_by_command
16
+ DTROPTIONS[:run_with_monitor] = true
17
+ assert DTR::Cmd.execute("echo 'message'")
18
+ assert @env_store[DTR::MESSAGE_KEY].nil?
19
+
20
+ assert !DTR::Cmd.execute("not_a_cmd args")
21
+ assert @env_store[DTR::MESSAGE_KEY].last.include?("not_a_cmd")
22
+
23
+ assert !DTR::Cmd.execute("rake --rakefile #{File.dirname(__FILE__)}/../testdata/Rakefile not_exist_task")
24
+ assert @env_store[DTR::MESSAGE_KEY].last.include?("rake aborted!")
25
+ end
26
+
27
+ def test_identifier_of_working_env
28
+ assert_not_equal DTR::WorkingEnv.refresh[:identifier], DTR::WorkingEnv.refresh[:identifier]
29
+ end
30
+
31
+ end
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'dtr/base.rb'
3
+
4
+ class CmdTest < Test::Unit::TestCase
5
+ def setup
6
+ @env_store = DTR::EnvStore.new
7
+ @env_store[DTR::MESSAGE_KEY] = nil
8
+ end
9
+
10
+ def teardown
11
+ DTROPTIONS[:run_with_monitor] = nil
12
+ DTR.logger.level = Logger::ERROR
13
+ @env_store[DTR::MESSAGE_KEY] = nil if @env_store[DTR::MESSAGE_KEY]
14
+ end
15
+
16
+ def test_should_be_silent_when_logger_level_is_error
17
+ assert DTR.silent?
18
+ DTR.logger.level = Logger::INFO
19
+ assert !DTR.silent?
20
+ DTR.logger.level = Logger::DEBUG
21
+ assert !DTR.silent?
22
+ DTR.logger.level = Logger::ERROR
23
+ assert DTR.silent?
24
+ end
25
+
26
+ def test_should_put_message_into_queue_when_run_with_monitor
27
+ DTROPTIONS[:run_with_monitor] = true
28
+ DTR.logger.level = Logger::DEBUG
29
+ DTR.error('error')
30
+ assert_equal 1, @env_store[DTR::MESSAGE_KEY].size
31
+ DTR.error{'error'}
32
+ assert_equal 2, @env_store[DTR::MESSAGE_KEY].size
33
+
34
+ DTR.info('info')
35
+ assert_equal 3, @env_store[DTR::MESSAGE_KEY].size
36
+ DTR.info{'info'}
37
+ assert_equal 4, @env_store[DTR::MESSAGE_KEY].size
38
+
39
+ DTR.debug('debug')
40
+ assert_equal 5, @env_store[DTR::MESSAGE_KEY].size
41
+ DTR.debug{'debug'}
42
+ assert_equal 6, @env_store[DTR::MESSAGE_KEY].size
43
+ end
44
+
45
+ def test_shift_message
46
+ assert_nil @env_store[DTR::MESSAGE_KEY]
47
+ @env_store.shift(DTR::MESSAGE_KEY)
48
+ assert_nil @env_store[DTR::MESSAGE_KEY]
49
+ @env_store[DTR::MESSAGE_KEY] = ['message']
50
+ @env_store.shift(DTR::MESSAGE_KEY)
51
+ assert @env_store[DTR::MESSAGE_KEY].empty?
52
+ end
53
+
54
+ end
@@ -0,0 +1,166 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'test/unit/ui/console/testrunner'
3
+ require 'dtr/service_provider'
4
+ require 'dtr/test_unit'
5
+ require 'dtr'
6
+ require 'socket'
7
+ # DTROPTIONS[:log_level] = Logger::DEBUG
8
+
9
+ class Test::Unit::TestResult
10
+ attr_reader :failures, :errors
11
+ end
12
+
13
+ class ScenarioTests < Test::Unit::TestCase
14
+
15
+ def setup
16
+ unless defined?(ATestCase)
17
+ require 'a_test_case'
18
+ require 'a_test_case2'
19
+ require 'a_failed_test_case'
20
+ require 'an_error_test_case'
21
+ require 'a_file_system_test_case'
22
+ require 'scenario_test_case'
23
+ end
24
+ DTR.inject
25
+ end
26
+
27
+ def teardown
28
+ DTR.reject
29
+ $argv_dup = nil
30
+ end
31
+
32
+ def test_run_test_passed
33
+ $argv_dup = ['a_test_case.rb', 'a_test_case2.rb', 'a_file_system_test_case.rb']
34
+ suite = Test::Unit::TestSuite.new('run_test_passed')
35
+ suite << ATestCase.suite
36
+ suite << ATestCase2.suite
37
+ suite << AFileSystemTestCase.suite
38
+
39
+ @result = runit(suite)
40
+
41
+ assert @result.passed?
42
+ assert_equal 3, @result.run_count
43
+ assert_equal 0, @result.failure_count
44
+ assert_equal 0, @result.error_count
45
+ end
46
+
47
+ def test_run_test_failed
48
+ $argv_dup = ['a_test_case.rb', 'a_failed_test_case.rb']
49
+ suite = Test::Unit::TestSuite.new('test_run_test_failed')
50
+ suite << ATestCase.suite
51
+ suite << AFailedTestCase.suite
52
+
53
+ @result = runit(suite)
54
+
55
+ assert !@result.passed?
56
+ assert_equal 2, @result.run_count
57
+ assert_equal 1, @result.failure_count
58
+ assert_equal 0, @result.error_count
59
+ end
60
+
61
+ def test_run_test_error
62
+ $argv_dup = ['a_test_case.rb', 'an_error_test_case.rb']
63
+ suite = Test::Unit::TestSuite.new('test_run_test_error')
64
+ suite << ATestCase.suite
65
+ suite << AnErrorTestCase.suite
66
+
67
+ DTR.debug { "dtr_injected: #{Test::Unit::TestSuite.method_defined?(:dtr_injected?)}" }
68
+ @result = runit(suite)
69
+
70
+ assert_false @result.passed?
71
+ assert_equal 2, @result.run_count
72
+ assert_equal 0, @result.failure_count
73
+ assert_equal 1, @result.error_count
74
+ end
75
+
76
+ def test_run_suite_should_be_independence
77
+ $argv_dup = ['an_error_test_case.rb']
78
+ suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 1')
79
+ suite << AnErrorTestCase.suite
80
+
81
+ @result = runit(suite)
82
+
83
+ assert_false @result.passed?
84
+ assert_equal 1, @result.run_count
85
+ assert_equal 0, @result.failure_count
86
+ assert_equal 1, @result.error_count
87
+
88
+ $argv_dup = ['a_test_case.rb']
89
+ suite = Test::Unit::TestSuite.new('test_run_suite_should_be_independence 2')
90
+ suite << ATestCase.suite
91
+
92
+ @result = runit(suite)
93
+
94
+ assert @result.passed?
95
+ assert_equal 1, @result.run_count
96
+ assert_equal 0, @result.failure_count
97
+ assert_equal 0, @result.error_count
98
+ end
99
+
100
+ def test_should_ignore_environment_file_not_exists
101
+ $argv_dup = ['a_test_case.rb', 'test_file_not_exists.rb']
102
+ suite = Test::Unit::TestSuite.new('test_run_test_file_not_exist')
103
+ suite << ATestCase.suite
104
+
105
+ @result = runit(suite)
106
+
107
+ assert @result.passed?
108
+ assert_equal 1, @result.run_count
109
+ assert_equal 0, @result.failure_count
110
+ assert_equal 0, @result.error_count
111
+ end
112
+
113
+ def test_run_empty_test_suite_and_no_test_files_in_environment
114
+ $argv_dup = []
115
+ suite = Test::Unit::TestSuite.new('test_run_without_test_files')
116
+
117
+ @result = runit(suite)
118
+
119
+ assert @result.passed?
120
+ assert_equal 0, @result.run_count
121
+ assert_equal 0, @result.failure_count
122
+ assert_equal 0, @result.error_count
123
+ end
124
+
125
+ def test_run_test_specified_by_load_path
126
+ lib_path = File.expand_path(File.dirname(__FILE__) + '/../testdata/lib')
127
+ $LOAD_PATH.unshift lib_path
128
+ require 'lib_test_case'
129
+ $argv_dup = ['lib_test_case.rb']
130
+ suite = Test::Unit::TestSuite.new('test_run_test_specified_by_load_path')
131
+ suite << LibTestCase.suite
132
+
133
+ @result = runit(suite)
134
+
135
+ assert @result.passed?
136
+ assert_equal 1, @result.run_count
137
+ assert_equal 0, @result.failure_count
138
+ assert_equal 0, @result.error_count
139
+ ensure
140
+ $LOAD_PATH.delete lib_path
141
+ end
142
+
143
+ def test_message_of_errors_and_failures_should_include_runner_host_name
144
+ $argv_dup = ['scenario_test_case.rb']
145
+ suite = Test::Unit::TestSuite.new('test_should_wrapper_errors_by_dtr_remote_exception')
146
+ suite << ScenarioTestCase.suite
147
+
148
+ @result = runit(suite)
149
+
150
+ assert !@result.passed?
151
+ assert_equal 8, @result.run_count
152
+ assert_equal 3, @result.failure_count
153
+ assert_equal 4, @result.error_count
154
+
155
+ @result.errors.each do |e|
156
+ assert e.message.include?("from #{Socket.gethostname}")
157
+ end
158
+ @result.failures.each do |e|
159
+ assert e.message.include?("from #{Socket.gethostname}")
160
+ end
161
+ end
162
+
163
+ def runit(suite)
164
+ Test::Unit::UI::Console::TestRunner.run(suite, Test::Unit::UI::SILENT)
165
+ end
166
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'logger'
3
+
4
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../testdata')
6
+
7
+ DTROPTIONS = {:log_level => Logger::ERROR} unless defined?(DTROPTIONS)
8
+
9
+ module Test
10
+ module Unit
11
+ class TestCase
12
+ def assert_false(o)
13
+ assert !o
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'dtr/test_unit.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
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Li Xiao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-28 00:00:00 +08:00
13
+ default_executable: dtr
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: daemons
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7
23
+ version:
24
+ description:
25
+ email: swing1979@gmail.com
26
+ executables:
27
+ - dtr
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - LICENSE.txt
33
+ - TODO
34
+ - CHANGES
35
+ files:
36
+ - install.rb
37
+ - CHANGES
38
+ - LICENSE.TXT
39
+ - Rakefile
40
+ - README
41
+ - TODO
42
+ - bin/dtr
43
+ - lib/dtr/base.rb
44
+ - lib/dtr/raketasks.rb
45
+ - lib/dtr/runner.rb
46
+ - lib/dtr/service_provider.rb
47
+ - lib/dtr/test_unit.rb
48
+ - lib/dtr/test_unit_injection.rb
49
+ - lib/dtr.rb
50
+ - test/base_test.rb
51
+ - test/logger_test.rb
52
+ - test/scenario_tests.rb
53
+ - test/test_helper.rb
54
+ - test/test_unit_test.rb
55
+ - doc/jamis.rb
56
+ - LICENSE.txt
57
+ has_rdoc: true
58
+ homepage: http://dtr.rubyforge.org
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --line-numbers
62
+ - --inline-source
63
+ - --main
64
+ - README
65
+ - --title
66
+ - "\"DTR -- Distributed Test Runner"
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: dtr
84
+ rubygems_version: 1.0.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: DTR is a distributed test runner to run tests on distributed computers for decreasing build time.
88
+ test_files: []
89
+