glib2 0.20.0 → 0.90.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/ChangeLog +92 -0
  2. data/README +22 -10
  3. data/Rakefile +54 -72
  4. data/ext/glib2/depend +10 -0
  5. data/ext/glib2/extconf.rb +61 -0
  6. data/ext/glib2/glib2.def +89 -0
  7. data/{src → ext/glib2}/rbgcompat.h +0 -0
  8. data/{src → ext/glib2}/rbglib.c +17 -7
  9. data/{src → ext/glib2}/rbglib.h +2 -2
  10. data/{src → ext/glib2}/rbglib_bookmarkfile.c +0 -0
  11. data/{src → ext/glib2}/rbglib_completion.c +0 -0
  12. data/{src → ext/glib2}/rbglib_convert.c +0 -0
  13. data/{src → ext/glib2}/rbglib_error.c +0 -0
  14. data/{src → ext/glib2}/rbglib_fileutils.c +0 -0
  15. data/{src → ext/glib2}/rbglib_i18n.c +0 -0
  16. data/{src → ext/glib2}/rbglib_int64.c +0 -0
  17. data/{src → ext/glib2}/rbglib_iochannel.c +0 -0
  18. data/{src → ext/glib2}/rbglib_keyfile.c +0 -0
  19. data/{src → ext/glib2}/rbglib_maincontext.c +1 -3
  20. data/{src → ext/glib2}/rbglib_mainloop.c +0 -0
  21. data/{src → ext/glib2}/rbglib_messages.c +0 -0
  22. data/{src → ext/glib2}/rbglib_pollfd.c +0 -0
  23. data/{src → ext/glib2}/rbglib_shell.c +0 -0
  24. data/{src → ext/glib2}/rbglib_source.c +0 -0
  25. data/{src → ext/glib2}/rbglib_spawn.c +0 -0
  26. data/{src → ext/glib2}/rbglib_threads.c +0 -0
  27. data/{src → ext/glib2}/rbglib_timer.c +0 -0
  28. data/{src → ext/glib2}/rbglib_unicode.c +0 -0
  29. data/{src → ext/glib2}/rbglib_utils.c +0 -0
  30. data/{src → ext/glib2}/rbglib_win32.c +0 -0
  31. data/{src → ext/glib2}/rbgobj_boxed.c +0 -0
  32. data/{src → ext/glib2}/rbgobj_closure.c +0 -0
  33. data/{src → ext/glib2}/rbgobj_convert.c +0 -0
  34. data/{src → ext/glib2}/rbgobj_enums.c +0 -0
  35. data/{src → ext/glib2}/rbgobj_fundamental.c +0 -0
  36. data/{src → ext/glib2}/rbgobj_object.c +0 -0
  37. data/{src → ext/glib2}/rbgobj_param.c +0 -0
  38. data/{src → ext/glib2}/rbgobj_paramspecs.c +0 -0
  39. data/{src → ext/glib2}/rbgobj_signal.c +0 -0
  40. data/{src → ext/glib2}/rbgobj_strv.c +0 -0
  41. data/{src → ext/glib2}/rbgobj_type.c +0 -0
  42. data/{src → ext/glib2}/rbgobj_typeinstance.c +0 -0
  43. data/{src → ext/glib2}/rbgobj_typeinterface.c +0 -0
  44. data/{src → ext/glib2}/rbgobj_typemodule.c +0 -0
  45. data/{src → ext/glib2}/rbgobj_typeplugin.c +0 -0
  46. data/{src → ext/glib2}/rbgobj_value.c +0 -0
  47. data/{src → ext/glib2}/rbgobj_valuearray.c +0 -0
  48. data/{src → ext/glib2}/rbgobj_valuetypes.c +0 -0
  49. data/{src → ext/glib2}/rbgobject.c +0 -0
  50. data/{src → ext/glib2}/rbgobject.h +0 -0
  51. data/{src → ext/glib2}/rbgprivate.h +0 -0
  52. data/ext/glib2/rbgutil.c +316 -0
  53. data/{src → ext/glib2}/rbgutil.h +9 -9
  54. data/{src → ext/glib2}/rbgutil_callback.c +0 -0
  55. data/extconf.rb +48 -60
  56. data/{src/lib → lib}/glib-mkenums.rb +2 -2
  57. data/{src/lib → lib}/glib2.rb +28 -9
  58. data/lib/gnome2-win32-binary-downloader.rb +92 -0
  59. data/{src/lib → lib}/mkmf-gnome2.rb +76 -89
  60. data/test-unit/COPYING +56 -0
  61. data/test-unit/GPL +340 -0
  62. data/test-unit/History.txt +232 -0
  63. data/test-unit/Manifest.txt +110 -0
  64. data/test-unit/PSFL +271 -0
  65. data/test-unit/README.txt +75 -0
  66. data/test-unit/Rakefile +53 -0
  67. data/test-unit/TODO +5 -0
  68. data/test-unit/bin/testrb +5 -0
  69. data/test-unit/html/bar.png +0 -0
  70. data/test-unit/html/bar.svg +153 -0
  71. data/test-unit/html/developer.png +0 -0
  72. data/test-unit/html/developer.svg +469 -0
  73. data/test-unit/html/famfamfam-logo.png +0 -0
  74. data/test-unit/html/favicon.ico +0 -0
  75. data/test-unit/html/favicon.png +0 -0
  76. data/test-unit/html/favicon.svg +82 -0
  77. data/test-unit/html/heading-mark.png +0 -0
  78. data/test-unit/html/heading-mark.svg +393 -0
  79. data/test-unit/html/index.html +247 -0
  80. data/test-unit/html/index.html.ja +270 -0
  81. data/test-unit/html/install.png +0 -0
  82. data/test-unit/html/install.svg +636 -0
  83. data/test-unit/html/jp.png +0 -0
  84. data/test-unit/html/kinotan-failure.png +0 -0
  85. data/test-unit/html/kinotan-pass.png +0 -0
  86. data/test-unit/html/logo.png +0 -0
  87. data/test-unit/html/logo.svg +483 -0
  88. data/test-unit/html/reference.png +0 -0
  89. data/test-unit/html/rubyforge.png +0 -0
  90. data/test-unit/html/tango-logo.png +0 -0
  91. data/test-unit/html/test-unit.css +339 -0
  92. data/test-unit/html/tutorial.png +0 -0
  93. data/test-unit/html/tutorial.svg +559 -0
  94. data/test-unit/html/us.png +0 -0
  95. data/test-unit/images/color-diff.png +0 -0
  96. data/test-unit/lib/test/unit.rb +328 -0
  97. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  98. data/test-unit/lib/test/unit/assertions.rb +1334 -0
  99. data/test-unit/lib/test/unit/attribute.rb +125 -0
  100. data/test-unit/lib/test/unit/autorunner.rb +363 -0
  101. data/test-unit/lib/test/unit/collector.rb +36 -0
  102. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  103. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  104. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  105. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  106. data/test-unit/lib/test/unit/color-scheme.rb +106 -0
  107. data/test-unit/lib/test/unit/color.rb +96 -0
  108. data/test-unit/lib/test/unit/diff.rb +740 -0
  109. data/test-unit/lib/test/unit/error.rb +130 -0
  110. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  111. data/test-unit/lib/test/unit/failure.rb +136 -0
  112. data/test-unit/lib/test/unit/fixture.rb +176 -0
  113. data/test-unit/lib/test/unit/notification.rb +129 -0
  114. data/test-unit/lib/test/unit/omission.rb +191 -0
  115. data/test-unit/lib/test/unit/pending.rb +150 -0
  116. data/test-unit/lib/test/unit/priority.rb +180 -0
  117. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  118. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  119. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  120. data/test-unit/lib/test/unit/testcase.rb +483 -0
  121. data/test-unit/lib/test/unit/testresult.rb +121 -0
  122. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  123. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  124. data/test-unit/lib/test/unit/ui/console/testrunner.rb +430 -0
  125. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  126. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +82 -0
  127. data/test-unit/lib/test/unit/ui/testrunner.rb +53 -0
  128. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  129. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  130. data/test-unit/lib/test/unit/util/backtracefilter.rb +42 -0
  131. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  132. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  133. data/test-unit/lib/test/unit/util/output.rb +31 -0
  134. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  135. data/test-unit/lib/test/unit/version.rb +7 -0
  136. data/test-unit/sample/adder.rb +13 -0
  137. data/test-unit/sample/subtracter.rb +12 -0
  138. data/test-unit/sample/test_adder.rb +20 -0
  139. data/test-unit/sample/test_subtracter.rb +20 -0
  140. data/test-unit/sample/test_user.rb +23 -0
  141. data/test-unit/test/collector/test-descendant.rb +133 -0
  142. data/test-unit/test/collector/test-load.rb +442 -0
  143. data/test-unit/test/collector/test_dir.rb +406 -0
  144. data/test-unit/test/collector/test_objectspace.rb +100 -0
  145. data/test-unit/test/run-test.rb +15 -0
  146. data/test-unit/test/test-attribute.rb +86 -0
  147. data/test-unit/test/test-color-scheme.rb +69 -0
  148. data/test-unit/test/test-color.rb +47 -0
  149. data/test-unit/test/test-diff.rb +518 -0
  150. data/test-unit/test/test-emacs-runner.rb +60 -0
  151. data/test-unit/test/test-fixture.rb +287 -0
  152. data/test-unit/test/test-notification.rb +33 -0
  153. data/test-unit/test/test-omission.rb +81 -0
  154. data/test-unit/test/test-pending.rb +70 -0
  155. data/test-unit/test/test-priority.rb +119 -0
  156. data/test-unit/test/test-testcase.rb +544 -0
  157. data/test-unit/test/test_assertions.rb +1197 -0
  158. data/test-unit/test/test_error.rb +26 -0
  159. data/test-unit/test/test_failure.rb +33 -0
  160. data/test-unit/test/test_testresult.rb +113 -0
  161. data/test-unit/test/test_testsuite.rb +129 -0
  162. data/test-unit/test/testunit-test-util.rb +14 -0
  163. data/test-unit/test/ui/test_tap.rb +33 -0
  164. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  165. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  166. data/test-unit/test/util/test-output.rb +11 -0
  167. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  168. data/test-unit/test/util/test_observable.rb +102 -0
  169. data/test-unit/test/util/test_procwrapper.rb +36 -0
  170. data/test/run-test.rb +2 -6
  171. metadata +197 -100
  172. data/src/glib-enum-types.c +0 -1032
  173. data/src/glib-enum-types.h +0 -140
  174. data/src/lib/pkg-config.rb +0 -137
  175. data/src/rbgutil.c +0 -222
@@ -0,0 +1,121 @@
1
+ #--
2
+ # Author:: Nathaniel Talbott.
3
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
4
+ # License:: Ruby license.
5
+
6
+ require 'test/unit/util/observable'
7
+ require 'test/unit/failure'
8
+ require 'test/unit/error'
9
+ require 'test/unit/omission'
10
+ require 'test/unit/pending'
11
+ require 'test/unit/notification'
12
+
13
+ module Test
14
+ module Unit
15
+ module NullResultContainerInitializer
16
+ private
17
+ def initialize_containers
18
+ end
19
+ end
20
+
21
+ # Collects Test::Unit::Failure and Test::Unit::Error so that
22
+ # they can be displayed to the user. To this end, observers
23
+ # can be added to it, allowing the dynamic updating of, say, a
24
+ # UI.
25
+ class TestResult
26
+ include Util::Observable
27
+ include NullResultContainerInitializer
28
+ include TestResultFailureSupport
29
+ include TestResultErrorSupport
30
+ include TestResultPendingSupport
31
+ include TestResultOmissionSupport
32
+ include TestResultNotificationSupport
33
+
34
+ CHANGED = "CHANGED"
35
+ FAULT = "FAULT"
36
+
37
+ attr_reader :run_count, :pass_count, :assertion_count, :faults
38
+
39
+ # Constructs a new, empty TestResult.
40
+ def initialize
41
+ @run_count, @pass_count, @assertion_count = 0, 0, 0
42
+ @summary_generators = []
43
+ @problem_checkers = []
44
+ @faults = []
45
+ initialize_containers
46
+ end
47
+
48
+ # Records a test run.
49
+ def add_run
50
+ @run_count += 1
51
+ notify_changed
52
+ end
53
+
54
+ def add_pass
55
+ @pass_count += 1
56
+ end
57
+
58
+ # Records an individual assertion.
59
+ def add_assertion
60
+ @assertion_count += 1
61
+ notify_changed
62
+ end
63
+
64
+ # Returns a string contain the recorded runs, assertions,
65
+ # failures and errors in this TestResult.
66
+ def summary
67
+ ["#{run_count} tests",
68
+ "#{assertion_count} assertions",
69
+ *@summary_generators.collect {|generator| send(generator)}].join(", ")
70
+ end
71
+
72
+ # Returnes a string that shows result status.
73
+ def status
74
+ if passed?
75
+ if pending_count > 0
76
+ "pending"
77
+ elsif omission_count > 0
78
+ "omission"
79
+ elsif notification_count > 0
80
+ "notification"
81
+ else
82
+ "pass"
83
+ end
84
+ elsif error_count > 0
85
+ "error"
86
+ elsif failure_count > 0
87
+ "failure"
88
+ end
89
+ end
90
+
91
+ def to_s
92
+ summary
93
+ end
94
+
95
+ # Returns whether or not this TestResult represents
96
+ # successful completion.
97
+ def passed?
98
+ @problem_checkers.all? {|checker| not send(checker)}
99
+ end
100
+
101
+ def pass_percentage
102
+ n_tests = @run_count - omission_count
103
+ if n_tests.zero?
104
+ 0
105
+ else
106
+ 100.0 * (@pass_count / n_tests.to_f)
107
+ end
108
+ end
109
+
110
+ private
111
+ def notify_changed
112
+ notify_listeners(CHANGED, self)
113
+ end
114
+
115
+ def notify_fault(fault)
116
+ @faults << fault
117
+ notify_listeners(FAULT, fault)
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,110 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ require 'test/unit/error'
8
+
9
+ module Test
10
+ module Unit
11
+
12
+ # A collection of tests which can be #run.
13
+ #
14
+ # Note: It is easy to confuse a TestSuite instance with
15
+ # something that has a static suite method; I know because _I_
16
+ # have trouble keeping them straight. Think of something that
17
+ # has a suite method as simply providing a way to get a
18
+ # meaningful TestSuite instance.
19
+ class TestSuite
20
+ attr_reader :name, :tests
21
+
22
+ STARTED = name + "::STARTED"
23
+ FINISHED = name + "::FINISHED"
24
+
25
+ # Creates a new TestSuite with the given name.
26
+ def initialize(name="Unnamed TestSuite", test_case=nil)
27
+ @name = name
28
+ @tests = []
29
+ @test_case = test_case
30
+ end
31
+
32
+ # Runs the tests and/or suites contained in this
33
+ # TestSuite.
34
+ def run(result, &progress_block)
35
+ yield(STARTED, name)
36
+ run_startup(result)
37
+ @tests.each do |test|
38
+ test.run(result, &progress_block)
39
+ end
40
+ run_shutdown(result)
41
+ yield(FINISHED, name)
42
+ end
43
+
44
+ # Adds the test to the suite.
45
+ def <<(test)
46
+ @tests << test
47
+ self
48
+ end
49
+
50
+ def delete(test)
51
+ @tests.delete(test)
52
+ end
53
+
54
+ # Retuns the rolled up number of tests in this suite;
55
+ # i.e. if the suite contains other suites, it counts the
56
+ # tests within those suites, not the suites themselves.
57
+ def size
58
+ total_size = 0
59
+ @tests.each { |test| total_size += test.size }
60
+ total_size
61
+ end
62
+
63
+ def empty?
64
+ tests.empty?
65
+ end
66
+
67
+ # Overridden to return the name given the suite at
68
+ # creation.
69
+ def to_s
70
+ @name
71
+ end
72
+
73
+ # It's handy to be able to compare TestSuite instances.
74
+ def ==(other)
75
+ return false unless(other.kind_of?(self.class))
76
+ return false unless(@name == other.name)
77
+ @tests == other.tests
78
+ end
79
+
80
+ private
81
+ def run_startup(result)
82
+ return if @test_case.nil? or !@test_case.respond_to?(:startup)
83
+ begin
84
+ @test_case.startup
85
+ rescue Exception
86
+ raise unless handle_exception($!, result)
87
+ end
88
+ end
89
+
90
+ def run_shutdown(result)
91
+ return if @test_case.nil? or !@test_case.respond_to?(:shutdown)
92
+ begin
93
+ @test_case.shutdown
94
+ rescue Exception
95
+ raise unless handle_exception($!, result)
96
+ end
97
+ end
98
+
99
+ def handle_exception(exception, result)
100
+ case exception
101
+ when *ErrorHandler::PASS_THROUGH_EXCEPTIONS
102
+ false
103
+ else
104
+ result.add_error(Error.new(@test_case.name, exception))
105
+ true
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,14 @@
1
+ module Test
2
+ module Unit
3
+ module UI
4
+ module Console
5
+ module OutputLevel
6
+ SILENT = 0
7
+ PROGRESS_ONLY = 1
8
+ NORMAL = 2
9
+ VERBOSE = 3
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,430 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright::
5
+ # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
+ # * Copyright (c) 2008-2009 Kouhei Sutou <kou@clear-code.com>
7
+ # License:: Ruby license.
8
+
9
+ require 'test/unit/color-scheme'
10
+ require 'test/unit/ui/testrunner'
11
+ require 'test/unit/ui/testrunnermediator'
12
+ require 'test/unit/ui/console/outputlevel'
13
+
14
+ module Test
15
+ module Unit
16
+ module UI
17
+ module Console
18
+
19
+ # Runs a Test::Unit::TestSuite on the console.
20
+ class TestRunner < UI::TestRunner
21
+ include OutputLevel
22
+
23
+ # Creates a new TestRunner for running the passed
24
+ # suite. If quiet_mode is true, the output while
25
+ # running is limited to progress dots, errors and
26
+ # failures, and the final result. io specifies
27
+ # where runner output should go to; defaults to
28
+ # STDOUT.
29
+ def initialize(suite, options={})
30
+ super
31
+ @output_level = @options[:output_level] || NORMAL
32
+ @output = @options[:output] || STDOUT
33
+ @use_color = @options[:use_color]
34
+ @use_color = guess_color_availability if @use_color.nil?
35
+ @color_scheme = @options[:color_scheme] || ColorScheme.default
36
+ @reset_color = Color.new("reset")
37
+ @progress_row = 0
38
+ @progress_row_max = @options[:progress_row_max]
39
+ @progress_row_max ||= guess_progress_row_max
40
+ @already_outputted = false
41
+ @indent = 0
42
+ @top_level = true
43
+ @faults = []
44
+ end
45
+
46
+ private
47
+ def setup_mediator
48
+ super
49
+ output_setup_end
50
+ end
51
+
52
+ def output_setup_end
53
+ suite_name = @suite.to_s
54
+ suite_name = @suite.name if @suite.kind_of?(Module)
55
+ output("Loaded suite #{suite_name}")
56
+ end
57
+
58
+ def attach_to_mediator
59
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
60
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
61
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
62
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
63
+ @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
64
+ @mediator.add_listener(TestSuite::STARTED, &method(:test_suite_started))
65
+ @mediator.add_listener(TestSuite::FINISHED, &method(:test_suite_finished))
66
+ end
67
+
68
+ def add_fault(fault)
69
+ @faults << fault
70
+ output_progress(fault.single_character_display, fault_color(fault))
71
+ @already_outputted = true if fault.critical?
72
+ end
73
+
74
+ def started(result)
75
+ @result = result
76
+ output_started
77
+ end
78
+
79
+ def output_started
80
+ output("Started")
81
+ end
82
+
83
+ def finished(elapsed_time)
84
+ nl if output?(NORMAL) and !output?(VERBOSE)
85
+ @faults.each_with_index do |fault, index|
86
+ nl
87
+ output_single("%3d) " % (index + 1))
88
+ output_fault(fault)
89
+ end
90
+ nl
91
+ output("Finished in #{elapsed_time} seconds.")
92
+ nl
93
+ output(@result, result_color)
94
+ output("%g%% passed" % @result.pass_percentage, result_color)
95
+ end
96
+
97
+ def output_fault(fault)
98
+ if @use_color and fault.is_a?(Failure) and
99
+ fault.inspected_expected and fault.inspected_actual
100
+ output_single(fault.label, fault_color(fault))
101
+ output(":")
102
+ output_fault_backtrace(fault)
103
+ output_fault_message(fault)
104
+ else
105
+ label, detail = format_fault(fault).split(/\r?\n/, 2)
106
+ output(label, fault_color(fault))
107
+ output(detail)
108
+ end
109
+ end
110
+
111
+ def output_fault_backtrace(fault)
112
+ backtrace = fault.location
113
+ if backtrace.size == 1
114
+ output(fault.test_name +
115
+ backtrace[0].sub(/\A(.+:\d+).*/, ' [\\1]') +
116
+ ":")
117
+ else
118
+ output(fault.test_name)
119
+ backtrace.each_with_index do |entry, i|
120
+ if i.zero?
121
+ prefix = "["
122
+ postfix = ""
123
+ elsif i == backtrace.size - 1
124
+ prefix = " "
125
+ postfix = "]:"
126
+ else
127
+ prefix = " "
128
+ postfix = ""
129
+ end
130
+ output(" #{prefix}#{entry}#{postfix}")
131
+ end
132
+ end
133
+ end
134
+
135
+ def output_fault_message(fault)
136
+ output(fault.user_message) if fault.user_message
137
+ output_single("<")
138
+ output_single(fault.inspected_expected, color("pass"))
139
+ output("> expected but was")
140
+ output_single("<")
141
+ output_single(fault.inspected_actual, color("failure"))
142
+ output(">")
143
+ from, to = prepare_for_diff(fault.expected, fault.actual)
144
+ if from and to
145
+ differ = ColorizedReadableDiffer.new(from.split(/\r?\n/),
146
+ to.split(/\r?\n/),
147
+ self)
148
+ if differ.need_diff?
149
+ output("")
150
+ output("diff:")
151
+ differ.diff
152
+ end
153
+ end
154
+ end
155
+
156
+ def format_fault(fault)
157
+ fault.long_display
158
+ end
159
+
160
+ def test_started(name)
161
+ return unless output?(VERBOSE)
162
+
163
+ name = name.sub(/\(.+?\)\z/, '')
164
+ right_space = 8 * 2
165
+ left_space = @progress_row_max - right_space
166
+ left_space = left_space - indent.size - name.size
167
+ tab_stop = "\t" * ([left_space - 1, 0].max / 8)
168
+ output_single("#{indent}#{name}:#{tab_stop}", nil, VERBOSE)
169
+ @test_start = Time.now
170
+ end
171
+
172
+ def test_finished(name)
173
+ unless @already_outputted
174
+ output_progress(".", color("pass"))
175
+ end
176
+ @already_outputted = false
177
+
178
+ return unless output?(VERBOSE)
179
+
180
+ output(": (%f)" % (Time.now - @test_start), nil, VERBOSE)
181
+ end
182
+
183
+ def test_suite_started(name)
184
+ if @top_level
185
+ @top_level = false
186
+ return
187
+ end
188
+
189
+ output_single(indent, nil, VERBOSE)
190
+ if /\A[A-Z]/ =~ name
191
+ _color = color("case")
192
+ else
193
+ _color = color("suite")
194
+ end
195
+ output_single(name, _color, VERBOSE)
196
+ output(": ", nil, VERBOSE)
197
+ @indent += 2
198
+ end
199
+
200
+ def test_suite_finished(name)
201
+ @indent -= 2
202
+ end
203
+
204
+ def indent
205
+ if output?(VERBOSE)
206
+ " " * @indent
207
+ else
208
+ ""
209
+ end
210
+ end
211
+
212
+ def nl(level=NORMAL)
213
+ output("", nil, level)
214
+ end
215
+
216
+ def output(something, color=nil, level=NORMAL)
217
+ return unless output?(level)
218
+ output_single(something, color, level)
219
+ @output.puts
220
+ end
221
+
222
+ def output_single(something, color=nil, level=NORMAL)
223
+ return false unless output?(level)
224
+ if @use_color and color
225
+ something = "%s%s%s" % [color.escape_sequence,
226
+ something,
227
+ @reset_color.escape_sequence]
228
+ end
229
+ @output.write(something)
230
+ @output.flush
231
+ true
232
+ end
233
+
234
+ def output_progress(mark, color=nil)
235
+ if output_single(mark, color, PROGRESS_ONLY)
236
+ return unless @progress_row_max > 0
237
+ @progress_row += mark.size
238
+ if @progress_row >= @progress_row_max
239
+ nl unless @output_level == VERBOSE
240
+ @progress_row = 0
241
+ end
242
+ end
243
+ end
244
+
245
+ def output?(level)
246
+ level <= @output_level
247
+ end
248
+
249
+ def color(name)
250
+ _color = @color_scheme[name]
251
+ _color ||= @color_scheme["success"] if name == "pass"
252
+ _color ||= ColorScheme.default[name]
253
+ _color
254
+ end
255
+
256
+ def fault_color(fault)
257
+ color(fault.class.name.split(/::/).last.downcase)
258
+ end
259
+
260
+ def result_color
261
+ color(@result.status)
262
+ end
263
+
264
+ def guess_color_availability
265
+ return false unless @output.tty?
266
+ case ENV["TERM"]
267
+ when /term(?:-color)?\z/, "screen"
268
+ true
269
+ else
270
+ return true if ENV["EMACS"] == "t"
271
+ false
272
+ end
273
+ end
274
+
275
+ def guess_progress_row_max
276
+ term_width = guess_term_width
277
+ if term_width.zero?
278
+ if ENV["EMACS"] == "t"
279
+ -1
280
+ else
281
+ 79
282
+ end
283
+ else
284
+ term_width
285
+ end
286
+ end
287
+
288
+ def guess_term_width
289
+ Integer(ENV["TERM_WIDTH"] || 0)
290
+ rescue ArgumentError
291
+ 0
292
+ end
293
+ end
294
+
295
+ class ColorizedReadableDiffer < Diff::ReadableDiffer
296
+ def initialize(from, to, runner)
297
+ @runner = runner
298
+ super(from, to)
299
+ end
300
+
301
+ def need_diff?(options={})
302
+ operations.each do |tag,|
303
+ return true if [:replace, :equal].include?(tag)
304
+ end
305
+ false
306
+ end
307
+
308
+ private
309
+ def output_single(something, color=nil)
310
+ @runner.send(:output_single, something, color)
311
+ end
312
+
313
+ def output(something, color=nil)
314
+ @runner.send(:output, something, color)
315
+ end
316
+
317
+ def color(name)
318
+ @runner.send(:color, name)
319
+ end
320
+
321
+ def cut_off_ratio
322
+ 0
323
+ end
324
+
325
+ def default_ratio
326
+ 0
327
+ end
328
+
329
+ def tag(mark, color_name, contents)
330
+ _color = color(color_name)
331
+ contents.each do |content|
332
+ output_single(mark, _color)
333
+ output_single(" ")
334
+ output(content)
335
+ end
336
+ end
337
+
338
+ def tag_deleted(contents)
339
+ tag("-", "diff-deleted-tag", contents)
340
+ end
341
+
342
+ def tag_inserted(contents)
343
+ tag("+", "diff-inserted-tag", contents)
344
+ end
345
+
346
+ def tag_equal(contents)
347
+ tag(" ", "normal", contents)
348
+ end
349
+
350
+ def tag_difference(contents)
351
+ tag("?", "diff-difference-tag", contents)
352
+ end
353
+
354
+ def diff_line(from_line, to_line)
355
+ to_operations = []
356
+ from_line, to_line, _operations = line_operations(from_line, to_line)
357
+
358
+ no_replace = true
359
+ _operations.each do |tag,|
360
+ if tag == :replace
361
+ no_replace = false
362
+ break
363
+ end
364
+ end
365
+
366
+ output_single("?", color("diff-difference-tag"))
367
+ output_single(" ")
368
+ _operations.each do |tag, from_start, from_end, to_start, to_end|
369
+ from_width = compute_width(from_line, from_start, from_end)
370
+ to_width = compute_width(to_line, to_start, to_end)
371
+ case tag
372
+ when :replace
373
+ output_single(from_line[from_start...from_end],
374
+ color("diff-deleted"))
375
+ if (from_width < to_width)
376
+ output_single(" " * (to_width - from_width))
377
+ end
378
+ to_operations << Proc.new do
379
+ output_single(to_line[to_start...to_end],
380
+ color("diff-inserted"))
381
+ if (to_width < from_width)
382
+ output_single(" " * (from_width - to_width))
383
+ end
384
+ end
385
+ when :delete
386
+ output_single(from_line[from_start...from_end],
387
+ color("diff-deleted"))
388
+ unless no_replace
389
+ to_operations << Proc.new {output_single(" " * from_width)}
390
+ end
391
+ when :insert
392
+ if no_replace
393
+ output_single(to_line[to_start...to_end],
394
+ color("diff-inserted"))
395
+ else
396
+ output_single(" " * to_width)
397
+ to_operations << Proc.new do
398
+ output_single(to_line[to_start...to_end],
399
+ color("diff-inserted"))
400
+ end
401
+ end
402
+ when :equal
403
+ output_single(from_line[from_start...from_end])
404
+ unless no_replace
405
+ to_operations << Proc.new {output_single(" " * to_width)}
406
+ end
407
+ else
408
+ raise "unknown tag: #{tag}"
409
+ end
410
+ end
411
+ output("")
412
+
413
+ unless to_operations.empty?
414
+ output_single("?", color("diff-difference-tag"))
415
+ output_single(" ")
416
+ to_operations.each do |operation|
417
+ operation.call
418
+ end
419
+ output("")
420
+ end
421
+ end
422
+ end
423
+ end
424
+ end
425
+ end
426
+ end
427
+
428
+ if __FILE__ == $0
429
+ Test::Unit::UI::Console::TestRunner.start_command_line_test
430
+ end