activegroonga 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/NEWS.ja.rdoc +5 -0
- data/NEWS.rdoc +5 -0
- data/README.ja.rdoc +49 -0
- data/README.rdoc +49 -0
- data/Rakefile +175 -0
- data/lib/active_groonga.rb +75 -0
- data/lib/active_groonga/aggregations.rb +30 -0
- data/lib/active_groonga/associations.rb +93 -0
- data/lib/active_groonga/associations/belongs_to_association.rb +25 -0
- data/lib/active_groonga/attribute_methods.rb +36 -0
- data/lib/active_groonga/base.rb +1579 -0
- data/lib/active_groonga/column.rb +107 -0
- data/lib/active_groonga/dirty.rb +30 -0
- data/lib/active_groonga/fixtures.rb +92 -0
- data/lib/active_groonga/migration.rb +150 -0
- data/lib/active_groonga/rails_support.rb +31 -0
- data/lib/active_groonga/reflection.rb +30 -0
- data/lib/active_groonga/schema.rb +314 -0
- data/lib/active_groonga/schema_dumper.rb +147 -0
- data/lib/active_groonga/tasks.rb +16 -0
- data/lib/active_groonga/tasks/groonga.rake +162 -0
- data/lib/active_groonga/test_case.rb +21 -0
- data/lib/active_groonga/test_help.rb +21 -0
- data/lib/active_groonga/timestamp.rb +30 -0
- data/lib/active_groonga/validations.rb +26 -0
- data/lib/active_groonga/version.rb +24 -0
- data/license/LGPL +504 -0
- data/rails/README +28 -0
- data/rails/init.rb +70 -0
- data/rails_generators/model_groonga/USAGE +28 -0
- data/rails_generators/model_groonga/model_groonga_generator.rb +45 -0
- data/rails_generators/model_groonga/templates/fixtures.yml +17 -0
- data/rails_generators/model_groonga/templates/migration.rb +16 -0
- data/rails_generators/model_groonga/templates/model.rb +2 -0
- data/rails_generators/model_groonga/templates/unit_test.rb +8 -0
- data/test-unit/Rakefile +35 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +342 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +1149 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +306 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +538 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +161 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +360 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test-descendant.rb +135 -0
- data/test-unit/test/collector/test-load.rb +333 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +477 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test_assertions.rb +1082 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testcase.rb +478 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/active-groonga-test-utils.rb +234 -0
- data/test/fixtures/bookmark.rb +2 -0
- data/test/fixtures/task.rb +2 -0
- data/test/fixtures/user.rb +2 -0
- data/test/run-test.rb +51 -0
- data/test/test-associations.rb +24 -0
- data/test/test-base.rb +194 -0
- data/test/test-schema.rb +49 -0
- metadata +192 -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,161 @@
|
|
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
|
+
end
|
30
|
+
|
31
|
+
class Checker
|
32
|
+
class << self
|
33
|
+
def have_priority?(name)
|
34
|
+
singleton_class = (class << self; self; end)
|
35
|
+
singleton_class.method_defined?(priority_check_method_name(name))
|
36
|
+
end
|
37
|
+
|
38
|
+
def need_to_run?(test)
|
39
|
+
priority = test[:priority] || :normal
|
40
|
+
if have_priority?(priority)
|
41
|
+
send(priority_check_method_name(priority), test)
|
42
|
+
else
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_priority_must?(test)
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def run_priority_important?(test)
|
52
|
+
rand > 0.1
|
53
|
+
end
|
54
|
+
|
55
|
+
def run_priority_high?(test)
|
56
|
+
rand > 0.3
|
57
|
+
end
|
58
|
+
|
59
|
+
def run_priority_normal?(test)
|
60
|
+
rand > 0.5
|
61
|
+
end
|
62
|
+
|
63
|
+
def run_priority_low?(test)
|
64
|
+
rand > 0.75
|
65
|
+
end
|
66
|
+
|
67
|
+
def run_priority_never?(test)
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def priority_check_method_name(priority_name)
|
73
|
+
"run_priority_#{priority_name}?"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
attr_reader :test
|
78
|
+
def initialize(test)
|
79
|
+
@test = test
|
80
|
+
end
|
81
|
+
|
82
|
+
def setup
|
83
|
+
FileUtils.rm_f(passed_file)
|
84
|
+
end
|
85
|
+
|
86
|
+
def teardown
|
87
|
+
if @test.send(:passed?)
|
88
|
+
FileUtils.touch(passed_file)
|
89
|
+
else
|
90
|
+
FileUtils.rm_f(passed_file)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def need_to_run?
|
95
|
+
!previous_test_success? or self.class.need_to_run?(@test)
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
def previous_test_success?
|
100
|
+
File.exist?(passed_file)
|
101
|
+
end
|
102
|
+
|
103
|
+
def result_dir
|
104
|
+
components = [".test-result",
|
105
|
+
@test.class.name || "AnonymousTestCase",
|
106
|
+
escaped_method_name]
|
107
|
+
parent_directories = [File.dirname($0), Dir.pwd]
|
108
|
+
if Process.respond_to?(:uid)
|
109
|
+
parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
|
110
|
+
end
|
111
|
+
parent_directories.each do |parent_directory|
|
112
|
+
dir = File.expand_path(File.join(parent_directory, *components))
|
113
|
+
begin
|
114
|
+
FileUtils.mkdir_p(dir)
|
115
|
+
return dir
|
116
|
+
rescue Errno::EACCES
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
raise Errno::EACCES, parent_directories.join(", ")
|
121
|
+
end
|
122
|
+
|
123
|
+
def passed_file
|
124
|
+
File.join(result_dir, "passed")
|
125
|
+
end
|
126
|
+
|
127
|
+
def escaped_method_name
|
128
|
+
@test.method_name.to_s.gsub(/[!?=]$/) do |matched|
|
129
|
+
case matched
|
130
|
+
when "!"
|
131
|
+
".destructive"
|
132
|
+
when "?"
|
133
|
+
".predicate"
|
134
|
+
when "="
|
135
|
+
".equal"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
module ClassMethods
|
142
|
+
def priority(name, *tests)
|
143
|
+
unless Checker.have_priority?(name)
|
144
|
+
raise ArgumentError, "unknown priority: #{name}"
|
145
|
+
end
|
146
|
+
attribute(:priority, name, {:keep => true}, *tests)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def priority_setup
|
151
|
+
return unless Priority.enabled?
|
152
|
+
Checker.new(self).setup
|
153
|
+
end
|
154
|
+
|
155
|
+
def priority_teardown
|
156
|
+
return unless Priority.enabled?
|
157
|
+
Checker.new(self).teardown
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|