testability-driver 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/bin/start_app_perf +199 -0
- data/bin/tdriver-devtools +3 -0
- data/config/sut_parameters.rb +39 -0
- data/ext/extconf.rb +67 -0
- data/ext/native_extensions.c +70 -0
- data/lib/matti.rb +30 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +223 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
- data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
- data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
- data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
- data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1924 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +245 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +964 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +68 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +1865 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +7 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/xml_generator/update +3 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/generate.rb +892 -0
- data/lib/tdriver-devtools/doc/update +1 -0
- data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
- data/lib/tdriver-devtools/doc/xslt/template.xsl +1861 -0
- data/lib/tdriver-devtools/doc/xslt/update +3 -0
- data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
- data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +233 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +194 -0
- data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
- data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
- data/lib/tdriver.rb +26 -0
- data/lib/tdriver/base/behaviour/behaviour.rb +32 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +94 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +262 -0
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +111 -0
- data/lib/tdriver/base/behaviour/factory.rb +380 -0
- data/lib/tdriver/base/behaviour/loader.rb +28 -0
- data/lib/tdriver/base/command_data/command_data.rb +51 -0
- data/lib/tdriver/base/command_data/loader.rb +25 -0
- data/lib/tdriver/base/errors.rb +131 -0
- data/lib/tdriver/base/loader.rb +38 -0
- data/lib/tdriver/base/state_object.rb +270 -0
- data/lib/tdriver/base/sut/adapter.rb +28 -0
- data/lib/tdriver/base/sut/controller.rb +119 -0
- data/lib/tdriver/base/sut/factory.rb +287 -0
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +243 -0
- data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +96 -0
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +346 -0
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1268 -0
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +182 -0
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +119 -0
- data/lib/tdriver/base/sut/generic/commands/application.rb +219 -0
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +82 -0
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +58 -0
- data/lib/tdriver/base/sut/generic/plugin.rb +96 -0
- data/lib/tdriver/base/sut/loader.rb +35 -0
- data/lib/tdriver/base/sut/sut.rb +67 -0
- data/lib/tdriver/base/test_object/abstract.rb +179 -0
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +94 -0
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +787 -0
- data/lib/tdriver/base/test_object/factory.rb +618 -0
- data/lib/tdriver/base/test_object/identificator.rb +511 -0
- data/lib/tdriver/base/test_object/loader.rb +37 -0
- data/lib/tdriver/env.rb +21 -0
- data/lib/tdriver/loader.rb +36 -0
- data/lib/tdriver/matti.rb +35 -0
- data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +158 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +98 -0
- data/lib/tdriver/report/report.rb +47 -0
- data/lib/tdriver/report/report_api.rb +207 -0
- data/lib/tdriver/report/report_combine.rb +86 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +167 -0
- data/lib/tdriver/report/report_creator.rb +571 -0
- data/lib/tdriver/report/report_cucumber.rb +158 -0
- data/lib/tdriver/report/report_cucumber_listener.rb +337 -0
- data/lib/tdriver/report/report_cucumber_reporter.rb +335 -0
- data/lib/tdriver/report/report_data_presentation.rb +152 -0
- data/lib/tdriver/report/report_data_table.rb +64 -0
- data/lib/tdriver/report/report_execution_statistics.rb +284 -0
- data/lib/tdriver/report/report_file_capture.rb +159 -0
- data/lib/tdriver/report/report_grouping.rb +539 -0
- data/lib/tdriver/report/report_junit_xml.rb +147 -0
- data/lib/tdriver/report/report_rspec.rb +108 -0
- data/lib/tdriver/report/report_test_case_run.rb +621 -0
- data/lib/tdriver/report/report_test_run.rb +1286 -0
- data/lib/tdriver/report/report_test_unit.rb +175 -0
- data/lib/tdriver/report/report_writer.rb +1405 -0
- data/lib/tdriver/tdriver.rb +158 -0
- data/lib/tdriver/util/common.rb +24 -0
- data/lib/tdriver/util/common/array.rb +39 -0
- data/lib/tdriver/util/common/crc16.rb +100 -0
- data/lib/tdriver/util/common/environment.rb +153 -0
- data/lib/tdriver/util/common/error.rb +39 -0
- data/lib/tdriver/util/common/file.rb +315 -0
- data/lib/tdriver/util/common/gem.rb +108 -0
- data/lib/tdriver/util/common/kernel.rb +189 -0
- data/lib/tdriver/util/common/loader.rb +39 -0
- data/lib/tdriver/util/common/retryable.rb +98 -0
- data/lib/tdriver/util/common/string.rb +77 -0
- data/lib/tdriver/util/dbaccess/dbaccess.rb +188 -0
- data/lib/tdriver/util/dbaccess/dbconnection.rb +41 -0
- data/lib/tdriver/util/dbaccess/error.rb +35 -0
- data/lib/tdriver/util/dbaccess/loader.rb +29 -0
- data/lib/tdriver/util/dynamic_attribute_filter.rb +182 -0
- data/lib/tdriver/util/hooking.rb +434 -0
- data/lib/tdriver/util/loader.rb +65 -0
- data/lib/tdriver/util/localisation.rb +24 -0
- data/lib/tdriver/util/localisation/error.rb +32 -0
- data/lib/tdriver/util/localisation/loader.rb +28 -0
- data/lib/tdriver/util/localisation/localisation.rb +479 -0
- data/lib/tdriver/util/logger.rb +377 -0
- data/lib/tdriver/util/operator_data/error.rb +29 -0
- data/lib/tdriver/util/operator_data/loader.rb +26 -0
- data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
- data/lib/tdriver/util/other/config.rb +221 -0
- data/lib/tdriver/util/parameter.rb +24 -0
- data/lib/tdriver/util/parameter/error.rb +45 -0
- data/lib/tdriver/util/parameter/loader.rb +37 -0
- data/lib/tdriver/util/parameter/parameter.rb +285 -0
- data/lib/tdriver/util/parameter/parameter_hash.rb +101 -0
- data/lib/tdriver/util/parameter/parameter_template.rb +120 -0
- data/lib/tdriver/util/parameter/parameter_user_api.rb +84 -0
- data/lib/tdriver/util/parameter/parameter_xml.rb +247 -0
- data/lib/tdriver/util/plugin/abstract.rb +60 -0
- data/lib/tdriver/util/plugin/error.rb +25 -0
- data/lib/tdriver/util/plugin/loader.rb +28 -0
- data/lib/tdriver/util/plugin/service.rb +200 -0
- data/lib/tdriver/util/recorder.rb +292 -0
- data/lib/tdriver/util/stats.rb +90 -0
- data/lib/tdriver/util/user_data/error.rb +29 -0
- data/lib/tdriver/util/user_data/loader.rb +26 -0
- data/lib/tdriver/util/user_data/user_data.rb +103 -0
- data/lib/tdriver/util/video_rec.rb +264 -0
- data/lib/tdriver/util/xml/abstraction.rb +47 -0
- data/lib/tdriver/util/xml/builder.rb +54 -0
- data/lib/tdriver/util/xml/document.rb +32 -0
- data/lib/tdriver/util/xml/element.rb +32 -0
- data/lib/tdriver/util/xml/error.rb +46 -0
- data/lib/tdriver/util/xml/loader.rb +46 -0
- data/lib/tdriver/util/xml/nil_element.rb +89 -0
- data/lib/tdriver/util/xml/nodeset.rb +32 -0
- data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
- data/lib/tdriver/util/xml/parsers/loader.rb +22 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +111 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +54 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +147 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +42 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +187 -0
- data/lib/tdriver/util/xml/xml.rb +170 -0
- data/lib/tdriver/verify/verify.rb +687 -0
- data/lib/tdriver/verify/verify.rb_org +630 -0
- data/lib/tdriver/version.rb +21 -0
- data/xml/behaviours/generic.xml +495 -0
- data/xml/defaults/generic.xml +97 -0
- data/xml/defaults/sut_generic.xml +36 -0
- data/xml/parameters/tdriver_parameters.xml +23 -0
- data/xml/templates/generic.xml +227 -0
- metadata +327 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
|
|
2
|
+
module TDriverVerify
|
|
3
|
+
|
|
4
|
+
# Verifies that the block given to this method evaluates without throwing any exceptions. Verification is synchronized with all connected suts.
|
|
5
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
|
6
|
+
#
|
|
7
|
+
# === params
|
|
8
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
|
9
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
|
10
|
+
# === returns
|
|
11
|
+
# nil
|
|
12
|
+
# === raises
|
|
13
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
|
14
|
+
# VerificationError:: The verification failed.
|
|
15
|
+
def verify( timeout = nil, message = nil, &block )
|
|
16
|
+
|
|
17
|
+
logging_enabled = MobyUtil::Logger.instance.enabled
|
|
18
|
+
verify_caller = caller(1).first.to_s
|
|
19
|
+
begin
|
|
20
|
+
|
|
21
|
+
MobyUtil::Logger.instance.enabled = false
|
|
22
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
|
23
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
|
24
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
|
25
|
+
|
|
26
|
+
# Set the object creation timeout temporarily to the verification timeout if it is larger
|
|
27
|
+
original_sync_timeout = nil
|
|
28
|
+
if !timeout.nil? and (timeout.to_i < MobyBase::TestObjectFactory.instance.timeout)
|
|
29
|
+
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
|
30
|
+
MobyBase::TestObjectFactory.instance.timeout=(timeout.to_i)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
timeout_time = Time.new + (timeout.nil? ? 0 : timeout.to_i)
|
|
34
|
+
timeout_cycle_seconds = 0.5
|
|
35
|
+
|
|
36
|
+
loop do
|
|
37
|
+
|
|
38
|
+
begin # catch errors thrown in the provided block
|
|
39
|
+
|
|
40
|
+
yield
|
|
41
|
+
# no error => verification ok
|
|
42
|
+
break
|
|
43
|
+
|
|
44
|
+
rescue Exception => e
|
|
45
|
+
|
|
46
|
+
source_contents = ""
|
|
47
|
+
error_msg = ""
|
|
48
|
+
if Time.new > timeout_time
|
|
49
|
+
|
|
50
|
+
error_msg = "Verification at #{verify_caller} failed\n"
|
|
51
|
+
|
|
52
|
+
begin
|
|
53
|
+
source_contents = find_source(verify_caller)
|
|
54
|
+
rescue Exception
|
|
55
|
+
# failed to load line from file, do nothing
|
|
56
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
57
|
+
MobyUtil::Logger.instance.log "behaviour" , "WARNING;Failed to load source line: #{e.backtrace.inspect}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if !source_contents.empty?
|
|
61
|
+
error_msg << source_contents
|
|
62
|
+
end
|
|
63
|
+
error_msg << "\nNested exception:" << e.message << "\n"
|
|
64
|
+
Kernel::raise MobyBase::VerificationError.new(error_msg)
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
sleep timeout_cycle_seconds
|
|
71
|
+
|
|
72
|
+
if self.kind_of? MobyBase::SUT
|
|
73
|
+
self.refresh
|
|
74
|
+
else
|
|
75
|
+
#refresh all connected suts
|
|
76
|
+
MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
|
|
77
|
+
sut_attributes[:sut].refresh if sut_attributes[:is_connected]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
end # do
|
|
83
|
+
|
|
84
|
+
rescue Exception => e
|
|
85
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
86
|
+
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
|
87
|
+
Kernel::raise e
|
|
88
|
+
ensure
|
|
89
|
+
MobyBase::TestObjectFactory.instance.timeout=(original_sync_timeout) unless original_sync_timeout.nil?
|
|
90
|
+
end
|
|
91
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
92
|
+
MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
|
93
|
+
return nil
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Verifies that the block given to this method throws an exception while being evaluated. Verification is synchronized with all connected suts.
|
|
98
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
|
99
|
+
#
|
|
100
|
+
# === params
|
|
101
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
|
102
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
|
103
|
+
# === returns
|
|
104
|
+
# nil
|
|
105
|
+
# === raises
|
|
106
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
|
107
|
+
# VerificationError:: The verification failed.
|
|
108
|
+
def verify_not( timeout = nil, message = nil, &block )
|
|
109
|
+
|
|
110
|
+
logging_enabled = MobyUtil::Logger.instance.enabled
|
|
111
|
+
verify_caller = caller(1).first.to_s
|
|
112
|
+
|
|
113
|
+
begin
|
|
114
|
+
|
|
115
|
+
MobyUtil::Logger.instance.enabled = false
|
|
116
|
+
|
|
117
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
|
118
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?( Integer )
|
|
119
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?( String )
|
|
120
|
+
|
|
121
|
+
# Set the object creation timeout temporarily to the verification timeout if it is larger
|
|
122
|
+
original_sync_timeout = nil
|
|
123
|
+
|
|
124
|
+
if !timeout.nil? and ( timeout.to_i < MobyBase::TestObjectFactory.instance.timeout )
|
|
125
|
+
|
|
126
|
+
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
|
127
|
+
MobyBase::TestObjectFactory.instance.timeout=(timeout.to_i)
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
timeout_time = Time.new + (timeout.nil? ? 0 : timeout.to_i)
|
|
132
|
+
timeout_cycle_seconds = 0.5
|
|
133
|
+
|
|
134
|
+
loop do
|
|
135
|
+
|
|
136
|
+
artificial_exception_raised = false
|
|
137
|
+
|
|
138
|
+
begin # catch errors thrown in the provided block
|
|
139
|
+
|
|
140
|
+
yield
|
|
141
|
+
artificial_exception_raised = true
|
|
142
|
+
Kernel::raise "test"
|
|
143
|
+
|
|
144
|
+
rescue Exception => e
|
|
145
|
+
|
|
146
|
+
source_contents = ""
|
|
147
|
+
error_msg = ""
|
|
148
|
+
|
|
149
|
+
# an error was encountered => verification ok
|
|
150
|
+
break unless artificial_exception_raised
|
|
151
|
+
|
|
152
|
+
if Time.new > timeout_time
|
|
153
|
+
error_msg = "Verification at #{ verify_caller } failed\n"
|
|
154
|
+
source_contents = find_source( verify_caller )
|
|
155
|
+
error_msg << source_contents if !source_contents.empty?
|
|
156
|
+
Kernel::raise MobyBase::VerificationError.new( error_msg )
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
sleep timeout_cycle_seconds
|
|
160
|
+
|
|
161
|
+
if self.kind_of? MobyBase::SUT
|
|
162
|
+
|
|
163
|
+
self.refresh
|
|
164
|
+
|
|
165
|
+
else
|
|
166
|
+
|
|
167
|
+
#refresh all connected suts
|
|
168
|
+
MobyBase::SUTFactory.instance.connected_suts.each do | sut_id, sut_attributes |
|
|
169
|
+
sut_attributes[:sut].refresh if sut_attributes[ :is_connected ]
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end # do
|
|
177
|
+
|
|
178
|
+
rescue Exception => e
|
|
179
|
+
|
|
180
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
181
|
+
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
|
|
182
|
+
Kernel::raise e
|
|
183
|
+
ensure
|
|
184
|
+
MobyBase::TestObjectFactory.instance.timeout=(original_sync_timeout) unless original_sync_timeout.nil?
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
188
|
+
MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
|
|
189
|
+
return nil
|
|
190
|
+
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Verifies that the block given to this method evaluates to true. Verification is synchronized with all connected suts.
|
|
194
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
|
195
|
+
#
|
|
196
|
+
# === params
|
|
197
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
|
198
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
|
199
|
+
# === returns
|
|
200
|
+
# nil
|
|
201
|
+
# === raises
|
|
202
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
|
203
|
+
# VerificationError:: The verification failed.
|
|
204
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
|
205
|
+
def verify_true( timeout = nil, message = nil, &block )
|
|
206
|
+
|
|
207
|
+
logging_enabled = MobyUtil::Logger.instance.enabled
|
|
208
|
+
|
|
209
|
+
verify_caller = caller(1).first.to_s
|
|
210
|
+
|
|
211
|
+
begin
|
|
212
|
+
|
|
213
|
+
MobyUtil::Logger.instance.enabled = false
|
|
214
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
|
215
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
|
216
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
|
217
|
+
|
|
218
|
+
# Set the object creation timeout temporarily to the verification timeout if it is larger
|
|
219
|
+
original_sync_timeout = nil
|
|
220
|
+
|
|
221
|
+
if !timeout.nil? and (timeout.to_i < MobyBase::TestObjectFactory.instance.timeout)
|
|
222
|
+
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
|
223
|
+
MobyBase::TestObjectFactory.instance.timeout=(timeout.to_i)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
timeout_time = Time.new + (timeout.nil? ? 0 : timeout.to_i)
|
|
227
|
+
timeout_cycle_seconds = 0.5
|
|
228
|
+
|
|
229
|
+
loop do
|
|
230
|
+
|
|
231
|
+
begin # catch errors thrown due to verification results
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
begin # catch errors thrown in the provided block
|
|
235
|
+
result = yield
|
|
236
|
+
rescue Exception => e
|
|
237
|
+
error_msg = "Verification at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
|
238
|
+
error_msg << find_source(verify_caller)
|
|
239
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
240
|
+
error_msg << "\n" << e.inspect
|
|
241
|
+
raise MobyBase::VerificationError.new(error_msg)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
error_msg = "Verification at #{verify_caller} failed."
|
|
245
|
+
error_msg << find_source(verify_caller)
|
|
246
|
+
error_msg << "\nThe block did not return true. It returned: " << result.inspect
|
|
247
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
248
|
+
raise MobyBase::VerificationError.new(error_msg) unless result == true
|
|
249
|
+
|
|
250
|
+
# break loop if no exceptions thrown
|
|
251
|
+
break
|
|
252
|
+
|
|
253
|
+
rescue MobyBase::VerificationError => ve
|
|
254
|
+
|
|
255
|
+
# refresh and retry unless timeout reached
|
|
256
|
+
|
|
257
|
+
if Time.new > timeout_time
|
|
258
|
+
Kernel::raise ve
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
sleep timeout_cycle_seconds
|
|
262
|
+
|
|
263
|
+
if self.kind_of? MobyBase::SUT
|
|
264
|
+
self.refresh
|
|
265
|
+
else
|
|
266
|
+
|
|
267
|
+
#refresh all connected suts
|
|
268
|
+
MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
|
|
269
|
+
sut_attributes[:sut].refresh if sut_attributes[:is_connected]
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
rescue Exception => e
|
|
275
|
+
|
|
276
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
277
|
+
# an unexpected error has occurred
|
|
278
|
+
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
|
279
|
+
|
|
280
|
+
end # begin, catch any VerificationErrors
|
|
281
|
+
|
|
282
|
+
end # do
|
|
283
|
+
|
|
284
|
+
rescue Exception => e
|
|
285
|
+
|
|
286
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
287
|
+
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
|
|
288
|
+
Kernel::raise e
|
|
289
|
+
|
|
290
|
+
ensure
|
|
291
|
+
|
|
292
|
+
MobyBase::TestObjectFactory.instance.timeout=(original_sync_timeout) unless original_sync_timeout.nil?
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
296
|
+
MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
|
|
297
|
+
|
|
298
|
+
nil
|
|
299
|
+
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Verifies that the block given to this method evaluates to false. Verification is synchronized with all connected suts.
|
|
303
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
|
304
|
+
#
|
|
305
|
+
# === params
|
|
306
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
|
307
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
|
308
|
+
# === returns
|
|
309
|
+
# nil
|
|
310
|
+
# === raises
|
|
311
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
|
312
|
+
# VerificationError:: The verification failed.
|
|
313
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
|
314
|
+
def verify_false( timeout = nil, message = nil, &block )
|
|
315
|
+
|
|
316
|
+
logging_enabled = MobyUtil::Logger.instance.enabled
|
|
317
|
+
verify_caller = caller(1).first.to_s
|
|
318
|
+
|
|
319
|
+
begin
|
|
320
|
+
MobyUtil::Logger.instance.enabled = false
|
|
321
|
+
|
|
322
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
|
323
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
|
324
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
|
325
|
+
|
|
326
|
+
# Set the object creation timeout temporarily to the verification timeout if it is larger
|
|
327
|
+
original_sync_timeout = nil
|
|
328
|
+
|
|
329
|
+
if !timeout.nil? and (timeout.to_i < MobyBase::TestObjectFactory.instance.timeout)
|
|
330
|
+
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
|
331
|
+
MobyBase::TestObjectFactory.instance.timeout=(timeout.to_i)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
timeout_time = Time.new + ( timeout.nil? ? 0 : timeout.to_i )
|
|
335
|
+
timeout_cycle_seconds = 0.5
|
|
336
|
+
|
|
337
|
+
loop do
|
|
338
|
+
|
|
339
|
+
begin # catch errors thrown due to verification results
|
|
340
|
+
|
|
341
|
+
begin # catch errors thrown in the provided block
|
|
342
|
+
result = yield
|
|
343
|
+
rescue Exception => e
|
|
344
|
+
error_msg = "Verification at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
|
345
|
+
error_msg << find_source(verify_caller)
|
|
346
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
347
|
+
error_msg << "\n" << e.inspect
|
|
348
|
+
raise MobyBase::VerificationError.new(error_msg)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
error_msg = "Verification at #{verify_caller} failed:"
|
|
352
|
+
error_msg << find_source(verify_caller)
|
|
353
|
+
error_msg << "The block did not return false. It returned: " << result.inspect
|
|
354
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
355
|
+
raise MobyBase::VerificationError.new(error_msg) unless result == false
|
|
356
|
+
|
|
357
|
+
# break loop if no exceptions thrown
|
|
358
|
+
break
|
|
359
|
+
|
|
360
|
+
rescue MobyBase::VerificationError => ve
|
|
361
|
+
|
|
362
|
+
# refresh and retry unless timeout reached
|
|
363
|
+
|
|
364
|
+
if Time.new > timeout_time
|
|
365
|
+
Kernel::raise ve
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
sleep timeout_cycle_seconds
|
|
369
|
+
|
|
370
|
+
if self.kind_of? MobyBase::SUT
|
|
371
|
+
self.refresh
|
|
372
|
+
else
|
|
373
|
+
|
|
374
|
+
#refresh all connected suts
|
|
375
|
+
MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
|
|
376
|
+
sut_attributes[:sut].refresh if sut_attributes[:is_connected]
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
rescue Exception => e
|
|
382
|
+
|
|
383
|
+
# an unexpected error has occurred
|
|
384
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
385
|
+
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
|
386
|
+
|
|
387
|
+
end # begin, catch any VerificationErrors
|
|
388
|
+
|
|
389
|
+
end # do
|
|
390
|
+
|
|
391
|
+
rescue Exception => e
|
|
392
|
+
|
|
393
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
394
|
+
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n #{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
|
|
395
|
+
Kernel::raise e
|
|
396
|
+
|
|
397
|
+
ensure
|
|
398
|
+
|
|
399
|
+
MobyBase::TestObjectFactory.instance.timeout=(original_sync_timeout) unless original_sync_timeout.nil?
|
|
400
|
+
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
404
|
+
MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
|
|
405
|
+
nil
|
|
406
|
+
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# Verifies that the block given to this method evaluates to the expected value. Verification is synchronized with all connected suts.
|
|
410
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
|
411
|
+
#
|
|
412
|
+
# === params
|
|
413
|
+
# expected:: Expected result value of the block
|
|
414
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
|
415
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
|
416
|
+
# === returns
|
|
417
|
+
# nil
|
|
418
|
+
# === raises
|
|
419
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
|
420
|
+
# VerificationError:: The verification failed.
|
|
421
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
|
422
|
+
def verify_equal( expected, timeout = nil, message = nil, &block )
|
|
423
|
+
|
|
424
|
+
logging_enabled = MobyUtil::Logger.instance.enabled
|
|
425
|
+
verify_caller = caller(1).first.to_s
|
|
426
|
+
|
|
427
|
+
begin
|
|
428
|
+
|
|
429
|
+
MobyUtil::Logger.instance.enabled = false
|
|
430
|
+
|
|
431
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
|
432
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
|
433
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
|
434
|
+
|
|
435
|
+
# Set the object creation timeout temporarily to the verification timeout if it is larger
|
|
436
|
+
original_sync_timeout = nil
|
|
437
|
+
|
|
438
|
+
if !timeout.nil? and (timeout.to_i < MobyBase::TestObjectFactory.instance.timeout)
|
|
439
|
+
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
|
440
|
+
MobyBase::TestObjectFactory.instance.timeout=(timeout.to_i)
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
timeout_time = Time.new + (timeout.nil? ? 0 : timeout.to_i)
|
|
444
|
+
timeout_cycle_seconds = 0.5
|
|
445
|
+
|
|
446
|
+
loop do
|
|
447
|
+
|
|
448
|
+
begin # catch errors thrown due to verification results
|
|
449
|
+
|
|
450
|
+
begin # catch errors thrown in the provided block
|
|
451
|
+
result = yield
|
|
452
|
+
rescue Exception => e
|
|
453
|
+
error_msg = "Verification at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
|
454
|
+
error_msg << find_source(verify_caller)
|
|
455
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
456
|
+
error_msg << "\n" << e.inspect
|
|
457
|
+
raise MobyBase::VerificationError.new(error_msg)
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
error_msg = "Verification at #{verify_caller} failed:"
|
|
461
|
+
error_msg << find_source(verify_caller)
|
|
462
|
+
error_msg << "The block did not return #{expected.inspect}. It returned: " << result.inspect
|
|
463
|
+
error_msg << "\nDetails: " << message unless message.nil?
|
|
464
|
+
raise MobyBase::VerificationError.new(error_msg) unless result == expected
|
|
465
|
+
|
|
466
|
+
# break loop if no exceptions thrown
|
|
467
|
+
break
|
|
468
|
+
|
|
469
|
+
rescue MobyBase::VerificationError => ve
|
|
470
|
+
|
|
471
|
+
# refresh and retry unless timeout reached
|
|
472
|
+
|
|
473
|
+
if Time.new > timeout_time
|
|
474
|
+
Kernel::raise ve
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
sleep timeout_cycle_seconds
|
|
478
|
+
|
|
479
|
+
if self.kind_of? MobyBase::SUT
|
|
480
|
+
|
|
481
|
+
self.refresh
|
|
482
|
+
|
|
483
|
+
else
|
|
484
|
+
|
|
485
|
+
#refresh all connected suts
|
|
486
|
+
MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
|
|
487
|
+
sut_attributes[:sut].refresh if sut_attributes[:is_connected]
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
rescue Exception => e
|
|
493
|
+
|
|
494
|
+
# an unexpected error has occurred
|
|
495
|
+
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
|
496
|
+
|
|
497
|
+
end # begin, catch any VerificationErrors
|
|
498
|
+
|
|
499
|
+
end # do
|
|
500
|
+
|
|
501
|
+
rescue Exception => e
|
|
502
|
+
|
|
503
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
504
|
+
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
|
|
505
|
+
Kernel::raise e
|
|
506
|
+
ensure
|
|
507
|
+
MobyBase::TestObjectFactory.instance.timeout=(original_sync_timeout) unless original_sync_timeout.nil?
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
MobyUtil::Logger.instance.enabled = logging_enabled
|
|
511
|
+
MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
|
|
512
|
+
|
|
513
|
+
nil
|
|
514
|
+
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
private
|
|
519
|
+
|
|
520
|
+
# Searches for the given source file for a line
|
|
521
|
+
#
|
|
522
|
+
# === params
|
|
523
|
+
# from_file:: String defining the file to load. If at_line is nil, this argument can also contain a path and line number separated by : (eg. some_dir/some_file.rb:123).
|
|
524
|
+
# at_line:: (optional) Integer, number of the line (first line is 1).
|
|
525
|
+
# === returns
|
|
526
|
+
# String:: Contents of the line
|
|
527
|
+
# === throws
|
|
528
|
+
# RuntimeError:: from_file is not correctly formed, the file cannot be loaded or the line cannot be found.
|
|
529
|
+
def find_source(backtrace)
|
|
530
|
+
|
|
531
|
+
ret_str = "\n"
|
|
532
|
+
|
|
533
|
+
begin
|
|
534
|
+
|
|
535
|
+
call_stack = backtrace.to_s.split(':')
|
|
536
|
+
#puts "call_stack:" << backtrace.to_s
|
|
537
|
+
|
|
538
|
+
line_number = 0
|
|
539
|
+
if (call_stack.size() == 2)
|
|
540
|
+
line_number = call_stack[1].to_i
|
|
541
|
+
|
|
542
|
+
else
|
|
543
|
+
line_number = call_stack[call_stack.size()-2].to_i
|
|
544
|
+
end
|
|
545
|
+
#puts "line number: " << line_number.to_s
|
|
546
|
+
|
|
547
|
+
file_path = ""
|
|
548
|
+
if (call_stack.size() == 2)
|
|
549
|
+
file_path = call_stack[0]
|
|
550
|
+
else
|
|
551
|
+
(call_stack.size()-2).times do |index|
|
|
552
|
+
file_path << call_stack[index].to_s << ":"
|
|
553
|
+
end
|
|
554
|
+
file_path.slice!(file_path.size()-1) # remove the trailing colon
|
|
555
|
+
end
|
|
556
|
+
#puts "file path: " << file_path.to_s
|
|
557
|
+
|
|
558
|
+
lines_to_read = line_number >= 2 ? 3 : line_number
|
|
559
|
+
#puts "lines to read: " << lines_to_read.to_s
|
|
560
|
+
|
|
561
|
+
start_line = line_number #- (lines_to_read <= 1 ? 0 : 1)
|
|
562
|
+
#puts "start line:" << start_line.to_s
|
|
563
|
+
|
|
564
|
+
File.open(File.expand_path(file_path.to_s), "r") { |source|
|
|
565
|
+
|
|
566
|
+
lines = source.readlines
|
|
567
|
+
Kernel::raise RuntimeError.new("Only \"#{lines.size.to_s}\" lines exist in the source file.")if start_line >= lines.size
|
|
568
|
+
|
|
569
|
+
lines_to_read = (lines.size - start_line + 1) < 3 ? (lines.size - start_line + 1) : lines_to_read
|
|
570
|
+
|
|
571
|
+
# the array is zero based, first line is at position 0
|
|
572
|
+
lines_to_read.times do |index|
|
|
573
|
+
if (line_number == (start_line + index))
|
|
574
|
+
ret_str << "=> "
|
|
575
|
+
else
|
|
576
|
+
ret_str << " "
|
|
577
|
+
end
|
|
578
|
+
ret_str << lines[start_line + index - 1]
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
rescue Exception => e
|
|
584
|
+
|
|
585
|
+
#puts "exception:" << e.inspect
|
|
586
|
+
ret_str << "Unable to load source lines.\n" << e.inspect
|
|
587
|
+
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
return ret_str
|
|
591
|
+
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
# Searches the backtrace line that is next from verify itself
|
|
595
|
+
#
|
|
596
|
+
# === params
|
|
597
|
+
# backtrace:: Array, exception backtrace
|
|
598
|
+
# === returns
|
|
599
|
+
# Integer:: Index of bactrace item
|
|
600
|
+
# === throws
|
|
601
|
+
# RuntimeError:: backtrace is nil or empty or correct line not found.
|
|
602
|
+
def find_line(backtrace)
|
|
603
|
+
|
|
604
|
+
Kernel::raise RuntimeError.new("Backtrace was nil") if backtrace.nil?
|
|
605
|
+
Kernel::raise RuntimeError.new("Backtrace is empty") if backtrace.size <= 0
|
|
606
|
+
|
|
607
|
+
moby_found = false
|
|
608
|
+
|
|
609
|
+
backtrace.size.times do |index|
|
|
610
|
+
if (backtrace[index].include?("/util/lib/verify.rb:"))
|
|
611
|
+
moby_found = true
|
|
612
|
+
else
|
|
613
|
+
if (moby_found)
|
|
614
|
+
return index
|
|
615
|
+
end
|
|
616
|
+
end
|
|
617
|
+
end
|
|
618
|
+
Kernel::raise RuntimeError.new("Correct line not found from backtrace.")
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
def parse_caller(at)
|
|
622
|
+
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
|
|
623
|
+
file = Regexp.last_match[1]
|
|
624
|
+
line = Regexp.last_match[2].to_i
|
|
625
|
+
method = Regexp.last_match[3]
|
|
626
|
+
[file, line, method]
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
end
|