ActiveSambaLdap 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/NEWS.en +40 -0
  2. data/NEWS.ja +44 -0
  3. data/README.en +366 -0
  4. data/README.ja +361 -0
  5. data/Rakefile +168 -0
  6. data/bin/asl-groupadd +73 -0
  7. data/bin/asl-groupadd.help +1 -0
  8. data/bin/asl-groupdel +61 -0
  9. data/bin/asl-groupdel.help +1 -0
  10. data/bin/asl-groupmod +137 -0
  11. data/bin/asl-groupmod.help +1 -0
  12. data/bin/asl-groupshow +33 -0
  13. data/bin/asl-groupshow.help +1 -0
  14. data/bin/asl-passwd +90 -0
  15. data/bin/asl-passwd.help +1 -0
  16. data/bin/asl-populate +101 -0
  17. data/bin/asl-populate.help +1 -0
  18. data/bin/asl-purge +26 -0
  19. data/bin/asl-purge.help +1 -0
  20. data/bin/asl-samba-computeradd +96 -0
  21. data/bin/asl-samba-computeradd.help +1 -0
  22. data/bin/asl-samba-groupadd +57 -0
  23. data/bin/asl-samba-groupadd.help +1 -0
  24. data/bin/asl-samba-groupdel +55 -0
  25. data/bin/asl-samba-groupdel.help +1 -0
  26. data/bin/asl-samba-groupmod +99 -0
  27. data/bin/asl-samba-groupmod.help +1 -0
  28. data/bin/asl-samba-useradd +100 -0
  29. data/bin/asl-samba-useradd.help +1 -0
  30. data/bin/asl-samba-userdel +49 -0
  31. data/bin/asl-samba-userdel.help +1 -0
  32. data/bin/asl-samba-usermod +94 -0
  33. data/bin/asl-samba-usermod.help +1 -0
  34. data/bin/asl-useradd +264 -0
  35. data/bin/asl-useradd.help +1 -0
  36. data/bin/asl-userdel +84 -0
  37. data/bin/asl-userdel.help +1 -0
  38. data/bin/asl-usermod +335 -0
  39. data/bin/asl-usermod.help +1 -0
  40. data/bin/asl-usershow +33 -0
  41. data/bin/asl-usershow.help +1 -0
  42. data/lib/active_samba_ldap.rb +42 -0
  43. data/lib/active_samba_ldap/account_entry.rb +208 -0
  44. data/lib/active_samba_ldap/base.rb +137 -0
  45. data/lib/active_samba_ldap/command.rb +100 -0
  46. data/lib/active_samba_ldap/computer.rb +24 -0
  47. data/lib/active_samba_ldap/computer_account_entry.rb +34 -0
  48. data/lib/active_samba_ldap/configuration.rb +333 -0
  49. data/lib/active_samba_ldap/dc.rb +19 -0
  50. data/lib/active_samba_ldap/entry.rb +81 -0
  51. data/lib/active_samba_ldap/get_text_support.rb +12 -0
  52. data/lib/active_samba_ldap/group.rb +17 -0
  53. data/lib/active_samba_ldap/group_entry.rb +187 -0
  54. data/lib/active_samba_ldap/idmap.rb +19 -0
  55. data/lib/active_samba_ldap/ou.rb +20 -0
  56. data/lib/active_samba_ldap/populate.rb +257 -0
  57. data/lib/active_samba_ldap/reloadable.rb +15 -0
  58. data/lib/active_samba_ldap/samba_account_entry.rb +225 -0
  59. data/lib/active_samba_ldap/samba_entry.rb +26 -0
  60. data/lib/active_samba_ldap/samba_group_entry.rb +143 -0
  61. data/lib/active_samba_ldap/unix_id_pool.rb +43 -0
  62. data/lib/active_samba_ldap/user.rb +44 -0
  63. data/lib/active_samba_ldap/user_account_entry.rb +30 -0
  64. data/lib/active_samba_ldap/version.rb +3 -0
  65. data/lib/samba/encrypt.rb +86 -0
  66. data/misc/rd2html.rb +42 -0
  67. data/po/ja/active-samba-ldap.po +465 -0
  68. data/rails/README +30 -0
  69. data/rails/init.rb +33 -0
  70. data/rails_generators/scaffold_active_samba_ldap/scaffold_active_samba_ldap_generator.rb +27 -0
  71. data/rails_generators/scaffold_active_samba_ldap/templates/computer.rb +3 -0
  72. data/rails_generators/scaffold_active_samba_ldap/templates/dc.rb +3 -0
  73. data/rails_generators/scaffold_active_samba_ldap/templates/group.rb +3 -0
  74. data/rails_generators/scaffold_active_samba_ldap/templates/idmap.rb +3 -0
  75. data/rails_generators/scaffold_active_samba_ldap/templates/ldap.yml +24 -0
  76. data/rails_generators/scaffold_active_samba_ldap/templates/ou.rb +3 -0
  77. data/rails_generators/scaffold_active_samba_ldap/templates/samba_controller.rb +12 -0
  78. data/rails_generators/scaffold_active_samba_ldap/templates/samba_helper.rb +2 -0
  79. data/rails_generators/scaffold_active_samba_ldap/templates/samba_index.rhtml +17 -0
  80. data/rails_generators/scaffold_active_samba_ldap/templates/samba_populate.rhtml +15 -0
  81. data/rails_generators/scaffold_active_samba_ldap/templates/samba_purge.rhtml +10 -0
  82. data/rails_generators/scaffold_active_samba_ldap/templates/unix_id_pool.rb +3 -0
  83. data/rails_generators/scaffold_active_samba_ldap/templates/user.rb +3 -0
  84. data/setup.rb +1585 -0
  85. data/test-unit/History.txt +107 -0
  86. data/test-unit/README.txt +52 -0
  87. data/test-unit/Rakefile +40 -0
  88. data/test-unit/TODO +5 -0
  89. data/test-unit/bin/testrb +5 -0
  90. data/test-unit/lib/test/unit.rb +342 -0
  91. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  92. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  93. data/test-unit/lib/test/unit/attribute.rb +125 -0
  94. data/test-unit/lib/test/unit/autorunner.rb +329 -0
  95. data/test-unit/lib/test/unit/collector.rb +43 -0
  96. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  97. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  98. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  99. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  100. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  101. data/test-unit/lib/test/unit/color.rb +96 -0
  102. data/test-unit/lib/test/unit/diff.rb +538 -0
  103. data/test-unit/lib/test/unit/error.rb +124 -0
  104. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  105. data/test-unit/lib/test/unit/failure.rb +110 -0
  106. data/test-unit/lib/test/unit/fixture.rb +176 -0
  107. data/test-unit/lib/test/unit/notification.rb +125 -0
  108. data/test-unit/lib/test/unit/omission.rb +143 -0
  109. data/test-unit/lib/test/unit/pending.rb +146 -0
  110. data/test-unit/lib/test/unit/priority.rb +181 -0
  111. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  112. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  113. data/test-unit/lib/test/unit/testcase.rb +425 -0
  114. data/test-unit/lib/test/unit/testresult.rb +89 -0
  115. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  116. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  117. data/test-unit/lib/test/unit/ui/console/testrunner.rb +223 -0
  118. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  119. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  120. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  121. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  122. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  123. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  124. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  125. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  126. data/test-unit/lib/test/unit/version.rb +7 -0
  127. data/test-unit/sample/adder.rb +13 -0
  128. data/test-unit/sample/subtracter.rb +12 -0
  129. data/test-unit/sample/tc_adder.rb +18 -0
  130. data/test-unit/sample/tc_subtracter.rb +18 -0
  131. data/test-unit/sample/test_user.rb +22 -0
  132. data/test-unit/sample/ts_examples.rb +7 -0
  133. data/test-unit/test/collector/test-descendant.rb +135 -0
  134. data/test-unit/test/collector/test-load.rb +333 -0
  135. data/test-unit/test/collector/test_dir.rb +406 -0
  136. data/test-unit/test/collector/test_objectspace.rb +98 -0
  137. data/test-unit/test/run-test.rb +13 -0
  138. data/test-unit/test/test-attribute.rb +86 -0
  139. data/test-unit/test/test-color-scheme.rb +56 -0
  140. data/test-unit/test/test-color.rb +47 -0
  141. data/test-unit/test/test-diff.rb +477 -0
  142. data/test-unit/test/test-emacs-runner.rb +60 -0
  143. data/test-unit/test/test-fixture.rb +287 -0
  144. data/test-unit/test/test-notification.rb +33 -0
  145. data/test-unit/test/test-omission.rb +81 -0
  146. data/test-unit/test/test-pending.rb +70 -0
  147. data/test-unit/test/test-priority.rb +119 -0
  148. data/test-unit/test/test-testcase.rb +507 -0
  149. data/test-unit/test/test_assertions.rb +1082 -0
  150. data/test-unit/test/test_error.rb +26 -0
  151. data/test-unit/test/test_failure.rb +33 -0
  152. data/test-unit/test/test_testresult.rb +113 -0
  153. data/test-unit/test/test_testsuite.rb +129 -0
  154. data/test-unit/test/testunit-test-util.rb +14 -0
  155. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  156. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  157. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  158. data/test-unit/test/util/test_observable.rb +102 -0
  159. data/test-unit/test/util/test_procwrapper.rb +36 -0
  160. data/test/asl-test-utils.rb +276 -0
  161. data/test/command.rb +67 -0
  162. data/test/config.yaml.sample +17 -0
  163. data/test/run-test.rb +20 -0
  164. data/test/test_asl_groupadd.rb +69 -0
  165. data/test/test_asl_groupdel.rb +88 -0
  166. data/test/test_asl_groupmod.rb +259 -0
  167. data/test/test_asl_groupshow.rb +21 -0
  168. data/test/test_asl_passwd.rb +126 -0
  169. data/test/test_asl_populate.rb +92 -0
  170. data/test/test_asl_purge.rb +21 -0
  171. data/test/test_asl_useradd.rb +712 -0
  172. data/test/test_asl_userdel.rb +75 -0
  173. data/test/test_asl_usermod.rb +549 -0
  174. data/test/test_asl_usershow.rb +27 -0
  175. data/test/test_entry.rb +21 -0
  176. data/test/test_group.rb +21 -0
  177. data/test/test_password.rb +51 -0
  178. data/test/test_samba_encrypt.rb +35 -0
  179. data/test/test_user_home_directory.rb +43 -0
  180. metadata +314 -0
@@ -0,0 +1,125 @@
1
+ require 'test/unit/util/backtracefilter'
2
+
3
+ module Test
4
+ module Unit
5
+ class Notification
6
+ include Util::BacktraceFilter
7
+ attr_reader :test_name, :location, :message
8
+
9
+ SINGLE_CHARACTER = 'N'
10
+ LABEL = "Notification"
11
+
12
+ # Creates a new Notification with the given location and
13
+ # message.
14
+ def initialize(test_name, location, message)
15
+ @test_name = test_name
16
+ @location = location
17
+ @message = message
18
+ end
19
+
20
+ # Returns a single character representation of a notification.
21
+ def single_character_display
22
+ SINGLE_CHARACTER
23
+ end
24
+
25
+ def label
26
+ LABEL
27
+ end
28
+
29
+ # Returns a brief version of the error description.
30
+ def short_display
31
+ "#{@test_name}: #{@message.split("\n")[0]}"
32
+ end
33
+
34
+ # Returns a verbose version of the error description.
35
+ def long_display
36
+ backtrace = filter_backtrace(location).join("\n")
37
+ "#{label}: #{@message}\n#{@test_name}\n#{backtrace}"
38
+ end
39
+
40
+ # Overridden to return long_display.
41
+ def to_s
42
+ long_display
43
+ end
44
+ end
45
+
46
+ class NotifiedError < StandardError
47
+ end
48
+
49
+
50
+ module TestCaseNotificationSupport
51
+ class << self
52
+ def included(base)
53
+ base.class_eval do
54
+ include NotificationHandler
55
+ end
56
+ end
57
+ end
58
+
59
+ # Notify some information.
60
+ #
61
+ # Example:
62
+ # def test_notification
63
+ # notify("I'm here!")
64
+ # # Reached here
65
+ # notify("Special!") if special_case?
66
+ # # Reached here too
67
+ # end
68
+ def notify(message, &block)
69
+ notification = Notification.new(name, filter_backtrace(caller), message)
70
+ add_notification(notification)
71
+ end
72
+
73
+ private
74
+ def add_notification(notification)
75
+ current_result.add_notification(notification)
76
+ end
77
+ end
78
+
79
+ module NotificationHandler
80
+ class << self
81
+ def included(base)
82
+ base.exception_handler(:handle_Notified_error)
83
+ end
84
+ end
85
+
86
+ private
87
+ def handle_Notified_error(exception)
88
+ return false unless exception.is_a?(NotifiedError)
89
+ notification = Notification.new(name,
90
+ filter_backtrace(exception.backtrace),
91
+ exception.message)
92
+ add_notification(notification)
93
+ true
94
+ end
95
+ end
96
+
97
+ module TestResultNotificationSupport
98
+ attr_reader :notifications
99
+
100
+ # Records a Test::Unit::Notification.
101
+ def add_notification(notification)
102
+ @notifications << notification
103
+ notify_fault(notification)
104
+ notify_changed
105
+ end
106
+
107
+ # Returns the number of notifications this TestResult has
108
+ # recorded.
109
+ def notification_count
110
+ @notifications.size
111
+ end
112
+
113
+ private
114
+ def initialize_containers
115
+ super
116
+ @notifications = []
117
+ @summary_generators << :notification_summary
118
+ end
119
+
120
+ def notification_summary
121
+ "#{notification_count} notifications"
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,143 @@
1
+ require 'test/unit/util/backtracefilter'
2
+
3
+ module Test
4
+ module Unit
5
+ class Omission
6
+ include Util::BacktraceFilter
7
+ attr_reader :test_name, :location, :message
8
+
9
+ SINGLE_CHARACTER = 'O'
10
+ LABEL = "Omission"
11
+
12
+ # Creates a new Omission with the given location and
13
+ # message.
14
+ def initialize(test_name, location, message)
15
+ @test_name = test_name
16
+ @location = location
17
+ @message = message
18
+ end
19
+
20
+ # Returns a single character representation of a omission.
21
+ def single_character_display
22
+ SINGLE_CHARACTER
23
+ end
24
+
25
+ def label
26
+ LABEL
27
+ end
28
+
29
+ # Returns a brief version of the error description.
30
+ def short_display
31
+ "#{@test_name}: #{@message.split("\n")[0]}"
32
+ end
33
+
34
+ # Returns a verbose version of the error description.
35
+ def long_display
36
+ backtrace = filter_backtrace(location).join("\n")
37
+ "#{label}: #{@message}\n#{@test_name}\n#{backtrace}"
38
+ end
39
+
40
+ # Overridden to return long_display.
41
+ def to_s
42
+ long_display
43
+ end
44
+ end
45
+
46
+ class OmittedError < StandardError
47
+ end
48
+
49
+
50
+ module TestCaseOmissionSupport
51
+ class << self
52
+ def included(base)
53
+ base.class_eval do
54
+ include OmissionHandler
55
+ end
56
+ end
57
+ end
58
+
59
+ # Omit the test of part of the test.
60
+ #
61
+ # Example:
62
+ # def test_omission
63
+ # omit
64
+ # # Not reached here
65
+ # end
66
+ #
67
+ # def test_omission_with_here
68
+ # omit do
69
+ # # Not ran here
70
+ # end
71
+ # # Reached here
72
+ # end
73
+ def omit(message=nil, &block)
74
+ message ||= "omitted."
75
+ if block_given?
76
+ omission = Omission.new(name, filter_backtrace(caller), message)
77
+ add_omission(omission)
78
+ else
79
+ raise OmittedError.new(message)
80
+ end
81
+ end
82
+
83
+ def omit_if(condition, *args, &block)
84
+ omit(*args, &block) if condition
85
+ end
86
+
87
+ def omit_unless(condition, *args, &block)
88
+ omit(*args, &block) unless condition
89
+ end
90
+
91
+ private
92
+ def add_omission(omission)
93
+ current_result.add_omission(omission)
94
+ end
95
+ end
96
+
97
+ module OmissionHandler
98
+ class << self
99
+ def included(base)
100
+ base.exception_handler(:handle_omitted_error)
101
+ end
102
+ end
103
+
104
+ private
105
+ def handle_omitted_error(exception)
106
+ return false unless exception.is_a?(OmittedError)
107
+ omission = Omission.new(name,
108
+ filter_backtrace(exception.backtrace),
109
+ exception.message)
110
+ add_omission(omission)
111
+ true
112
+ end
113
+ end
114
+
115
+ module TestResultOmissionSupport
116
+ attr_reader :omissions
117
+
118
+ # Records a Test::Unit::Omission.
119
+ def add_omission(omission)
120
+ @omissions << omission
121
+ notify_fault(omission)
122
+ notify_changed
123
+ end
124
+
125
+ # Returns the number of omissions this TestResult has
126
+ # recorded.
127
+ def omission_count
128
+ @omissions.size
129
+ end
130
+
131
+ private
132
+ def initialize_containers
133
+ super
134
+ @omissions = []
135
+ @summary_generators << :omission_summary
136
+ end
137
+
138
+ def omission_summary
139
+ "#{omission_count} omissions"
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,146 @@
1
+ require 'test/unit/util/backtracefilter'
2
+
3
+ module Test
4
+ module Unit
5
+ class Pending
6
+ include Util::BacktraceFilter
7
+ attr_reader :test_name, :location, :message
8
+
9
+ SINGLE_CHARACTER = 'P'
10
+ LABEL = "Pending"
11
+
12
+ # Creates a new Pending with the given location and
13
+ # message.
14
+ def initialize(test_name, location, message)
15
+ @test_name = test_name
16
+ @location = location
17
+ @message = message
18
+ end
19
+
20
+ # Returns a single character representation of a pending.
21
+ def single_character_display
22
+ SINGLE_CHARACTER
23
+ end
24
+
25
+ def label
26
+ LABEL
27
+ end
28
+
29
+ # Returns a brief version of the error description.
30
+ def short_display
31
+ "#{@test_name}: #{@message.split("\n")[0]}"
32
+ end
33
+
34
+ # Returns a verbose version of the error description.
35
+ def long_display
36
+ backtrace = filter_backtrace(location).join("\n")
37
+ "#{label}: #{@message}\n#{@test_name}\n#{backtrace}"
38
+ end
39
+
40
+ # Overridden to return long_display.
41
+ def to_s
42
+ long_display
43
+ end
44
+ end
45
+
46
+ class PendedError < StandardError
47
+ end
48
+
49
+
50
+ module TestCasePendingSupport
51
+ class << self
52
+ def included(base)
53
+ base.class_eval do
54
+ include PendingHandler
55
+ end
56
+ end
57
+ end
58
+
59
+ # Marks the test or part of the test is pending.
60
+ #
61
+ # Example:
62
+ # def test_pending
63
+ # pend
64
+ # # Not reached here
65
+ # end
66
+ #
67
+ # def test_pending_with_here
68
+ # pend do
69
+ # # Ran here
70
+ # # Fails if the block doesn't raise any error.
71
+ # # Because it means the block is passed unexpectedly.
72
+ # end
73
+ # # Reached here
74
+ # end
75
+ def pend(message=nil, &block)
76
+ message ||= "pended."
77
+ if block_given?
78
+ pending = nil
79
+ begin
80
+ yield
81
+ rescue Exception
82
+ pending = Pending.new(name, filter_backtrace(caller), message)
83
+ add_pending(pending)
84
+ end
85
+ unless pending
86
+ flunk("Pending block should not be passed: #{message}")
87
+ end
88
+ else
89
+ raise PendedError.new(message)
90
+ end
91
+ end
92
+
93
+ private
94
+ def add_pending(pending)
95
+ problem_occurred
96
+ current_result.add_pending(pending)
97
+ end
98
+ end
99
+
100
+ module PendingHandler
101
+ class << self
102
+ def included(base)
103
+ base.exception_handler(:handle_pended_error)
104
+ end
105
+ end
106
+
107
+ private
108
+ def handle_pended_error(exception)
109
+ return false unless exception.is_a?(PendedError)
110
+ pending = Pending.new(name,
111
+ filter_backtrace(exception.backtrace),
112
+ exception.message)
113
+ add_pending(pending)
114
+ true
115
+ end
116
+ end
117
+
118
+ module TestResultPendingSupport
119
+ attr_reader :pendings
120
+
121
+ # Records a Test::Unit::Pending.
122
+ def add_pending(pending)
123
+ @pendings << pending
124
+ notify_fault(pending)
125
+ notify_changed
126
+ end
127
+
128
+ # Returns the number of pendings this TestResult has
129
+ # recorded.
130
+ def pending_count
131
+ @pendings.size
132
+ end
133
+
134
+ private
135
+ def initialize_containers
136
+ super
137
+ @pendings = []
138
+ @summary_generators << :pending_summary
139
+ end
140
+
141
+ def pending_summary
142
+ "#{pending_count} pendings"
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,181 @@
1
+ require "fileutils"
2
+ require "tmpdir"
3
+
4
+ module Test
5
+ module Unit
6
+ module Priority
7
+ class << self
8
+ def included(base)
9
+ base.extend(ClassMethods)
10
+
11
+ base.class_eval do
12
+ setup :priority_setup, :before => :prepend
13
+ teardown :priority_teardown, :after => :append
14
+ end
15
+ end
16
+
17
+ @@enabled = false
18
+ def enabled?
19
+ @@enabled
20
+ end
21
+
22
+ def enable
23
+ @@enabled = true
24
+ end
25
+
26
+ def disable
27
+ @@enabled = false
28
+ end
29
+
30
+ @@default = :normal
31
+ def default
32
+ @@default || :normal
33
+ end
34
+
35
+ def default=(default)
36
+ @@default = default
37
+ end
38
+
39
+ def available_values
40
+ Checker.available_priorities
41
+ end
42
+ end
43
+
44
+ class Checker
45
+ class << self
46
+ def have_priority?(name)
47
+ singleton_class = (class << self; self; end)
48
+ singleton_class.method_defined?(priority_check_method_name(name))
49
+ end
50
+
51
+ def need_to_run?(test)
52
+ priority = test[:priority] || Priority.default
53
+ if have_priority?(priority)
54
+ send(priority_check_method_name(priority), test)
55
+ else
56
+ true
57
+ end
58
+ end
59
+
60
+ def available_priorities
61
+ methods(false).collect do |name|
62
+ /\Arun_priority_(.+)\?\z/ =~ name.to_s
63
+ $1
64
+ end.compact
65
+ end
66
+
67
+ def run_priority_must?(test)
68
+ true
69
+ end
70
+
71
+ def run_priority_important?(test)
72
+ rand > 0.1
73
+ end
74
+
75
+ def run_priority_high?(test)
76
+ rand > 0.3
77
+ end
78
+
79
+ def run_priority_normal?(test)
80
+ rand > 0.5
81
+ end
82
+
83
+ def run_priority_low?(test)
84
+ rand > 0.75
85
+ end
86
+
87
+ def run_priority_never?(test)
88
+ false
89
+ end
90
+
91
+ private
92
+ def priority_check_method_name(priority_name)
93
+ "run_priority_#{priority_name}?"
94
+ end
95
+ end
96
+
97
+ attr_reader :test
98
+ def initialize(test)
99
+ @test = test
100
+ end
101
+
102
+ def setup
103
+ FileUtils.rm_f(passed_file)
104
+ end
105
+
106
+ def teardown
107
+ if @test.send(:passed?)
108
+ FileUtils.touch(passed_file)
109
+ else
110
+ FileUtils.rm_f(passed_file)
111
+ end
112
+ end
113
+
114
+ def need_to_run?
115
+ !previous_test_success? or self.class.need_to_run?(@test)
116
+ end
117
+
118
+ private
119
+ def previous_test_success?
120
+ File.exist?(passed_file)
121
+ end
122
+
123
+ def result_dir
124
+ components = [".test-result",
125
+ @test.class.name || "AnonymousTestCase",
126
+ escaped_method_name]
127
+ parent_directories = [File.dirname($0), Dir.pwd]
128
+ if Process.respond_to?(:uid)
129
+ parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
130
+ end
131
+ parent_directories.each do |parent_directory|
132
+ dir = File.expand_path(File.join(parent_directory, *components))
133
+ begin
134
+ FileUtils.mkdir_p(dir)
135
+ return dir
136
+ rescue Errno::EACCES
137
+ end
138
+ end
139
+
140
+ raise Errno::EACCES, parent_directories.join(", ")
141
+ end
142
+
143
+ def passed_file
144
+ File.join(result_dir, "passed")
145
+ end
146
+
147
+ def escaped_method_name
148
+ @test.method_name.to_s.gsub(/[!?=]$/) do |matched|
149
+ case matched
150
+ when "!"
151
+ ".destructive"
152
+ when "?"
153
+ ".predicate"
154
+ when "="
155
+ ".equal"
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ module ClassMethods
162
+ def priority(name, *tests)
163
+ unless Checker.have_priority?(name)
164
+ raise ArgumentError, "unknown priority: #{name}"
165
+ end
166
+ attribute(:priority, name, {:keep => true}, *tests)
167
+ end
168
+ end
169
+
170
+ def priority_setup
171
+ return unless Priority.enabled?
172
+ Checker.new(self).setup
173
+ end
174
+
175
+ def priority_teardown
176
+ return unless Priority.enabled?
177
+ Checker.new(self).teardown
178
+ end
179
+ end
180
+ end
181
+ end