colorcode_convert_rgb 0.1.0

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.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +23 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +40 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/colorcode_convert_rgb.gemspec +30 -0
  10. data/exe/colorcode_convert_rgb +4 -0
  11. data/lib/colorcode_convert_rgb.rb +7 -0
  12. data/lib/colorcode_convert_rgb/cli.rb +13 -0
  13. data/lib/colorcode_convert_rgb/version.rb +3 -0
  14. data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
  15. data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
  16. data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
  17. data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
  18. data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
  19. data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
  20. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
  21. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
  22. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
  23. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
  24. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
  25. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
  26. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
  27. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
  28. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
  29. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
  30. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
  31. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
  32. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
  33. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
  34. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
  35. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
  36. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
  37. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
  38. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
  39. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
  40. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
  41. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
  42. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
  43. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
  44. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
  45. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
  46. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
  47. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
  48. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
  49. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
  50. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
  51. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
  52. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
  53. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
  54. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
  55. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
  56. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
  57. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
  58. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
  59. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
  60. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
  61. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
  62. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
  63. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
  64. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
  65. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
  66. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
  67. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
  68. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
  69. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
  70. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
  71. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
  72. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
  73. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
  74. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
  75. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
  76. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
  77. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
  78. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
  79. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
  80. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
  81. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
  82. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
  83. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
  84. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
  85. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
  86. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
  87. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
  88. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
  89. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
  90. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
  91. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
  92. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
  93. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
  94. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
  95. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
  96. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
  97. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
  98. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
  99. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
  100. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
  101. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
  102. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
  103. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
  104. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
  105. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
  106. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
  107. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
  108. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
  109. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
  110. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
  111. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
  112. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
  113. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
  114. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
  115. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
  116. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
  117. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
  118. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
  119. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
  120. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
  121. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
  122. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
  123. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
  124. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
  125. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
  126. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
  127. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
  128. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
  129. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
  130. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
  131. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
  132. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
  133. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
  134. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
  135. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
  136. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
  137. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
  138. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
  139. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
  140. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
  141. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
  142. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
  143. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
  144. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
  145. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
  146. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
  147. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
  148. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
  149. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
  150. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
  151. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
  152. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
  153. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
  154. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
  155. data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
  156. data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
  157. data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
  158. metadata +214 -0
@@ -0,0 +1,807 @@
1
+ # encoding: UTF-8
2
+
3
+ require "rbconfig"
4
+ require "tempfile"
5
+ require "stringio"
6
+
7
+ module Minitest
8
+ ##
9
+ # Minitest Assertions. All assertion methods accept a +msg+ which is
10
+ # printed if the assertion fails.
11
+ #
12
+ # Protocol: Nearly everything here boils up to +assert+, which
13
+ # expects to be able to increment an instance accessor named
14
+ # +assertions+. This is not provided by Assertions and must be
15
+ # provided by the thing including Assertions. See Minitest::Runnable
16
+ # for an example.
17
+
18
+ module Assertions
19
+ UNDEFINED = Object.new # :nodoc:
20
+
21
+ def UNDEFINED.inspect # :nodoc:
22
+ "UNDEFINED" # again with the rdoc bugs... :(
23
+ end
24
+
25
+ ##
26
+ # Returns the diff command to use in #diff. Tries to intelligently
27
+ # figure out what diff to use.
28
+
29
+ def self.diff
30
+ return @diff if defined? @diff
31
+
32
+ @diff = if (RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ &&
33
+ system("diff.exe", __FILE__, __FILE__)) then
34
+ "diff.exe -u"
35
+ elsif system("gdiff", __FILE__, __FILE__)
36
+ "gdiff -u" # solaris and kin suck
37
+ elsif system("diff", __FILE__, __FILE__)
38
+ "diff -u"
39
+ else
40
+ nil
41
+ end
42
+ end
43
+
44
+ ##
45
+ # Set the diff command to use in #diff.
46
+
47
+ def self.diff= o
48
+ @diff = o
49
+ end
50
+
51
+ ##
52
+ # Returns a diff between +exp+ and +act+. If there is no known
53
+ # diff command or if it doesn't make sense to diff the output
54
+ # (single line, short output), then it simply returns a basic
55
+ # comparison between the two.
56
+ #
57
+ # See +things_to_diff+ for more info.
58
+
59
+ def diff exp, act
60
+ result = nil
61
+
62
+ expect, butwas = things_to_diff(exp, act)
63
+
64
+ return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
65
+ expect
66
+
67
+ Tempfile.open("expect") do |a|
68
+ a.puts expect
69
+ a.flush
70
+
71
+ Tempfile.open("butwas") do |b|
72
+ b.puts butwas
73
+ b.flush
74
+
75
+ result = `#{Minitest::Assertions.diff} #{a.path} #{b.path}`
76
+ result.sub!(/^\-\-\- .+/, "--- expected")
77
+ result.sub!(/^\+\+\+ .+/, "+++ actual")
78
+
79
+ if result.empty? then
80
+ klass = exp.class
81
+ result = [
82
+ "No visible difference in the #{klass}#inspect output.\n",
83
+ "You should look at the implementation of #== on ",
84
+ "#{klass} or its members.\n",
85
+ expect,
86
+ ].join
87
+ end
88
+ end
89
+ end
90
+
91
+ result
92
+ end
93
+
94
+ ##
95
+ # Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
96
+ #
97
+ # Criterion:
98
+ #
99
+ # 1. Strings include newlines or escaped newlines, but not both.
100
+ # 2. or: String lengths are > 30 characters.
101
+ # 3. or: Strings are equal to each other (but maybe different encodings?).
102
+ # 4. and: we found a diff executable.
103
+
104
+ def things_to_diff exp, act
105
+ expect = mu_pp_for_diff exp
106
+ butwas = mu_pp_for_diff act
107
+
108
+ e1, e2 = expect.include?("\n"), expect.include?("\\n")
109
+ b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
110
+
111
+ need_to_diff =
112
+ (e1 ^ e2 ||
113
+ b1 ^ b2 ||
114
+ expect.size > 30 ||
115
+ butwas.size > 30 ||
116
+ expect == butwas) &&
117
+ Minitest::Assertions.diff
118
+
119
+ need_to_diff && [expect, butwas]
120
+ end
121
+
122
+ ##
123
+ # This returns a human-readable version of +obj+. By default
124
+ # #inspect is called. You can override this to use #pretty_inspect
125
+ # if you want.
126
+ #
127
+ # See Minitest::Test.make_my_diffs_pretty!
128
+
129
+ def mu_pp obj
130
+ s = obj.inspect
131
+
132
+ if defined? Encoding then
133
+ s = s.encode Encoding.default_external
134
+
135
+ if String === obj && (obj.encoding != Encoding.default_external ||
136
+ !obj.valid_encoding?) then
137
+ enc = "# encoding: #{obj.encoding}"
138
+ val = "# valid: #{obj.valid_encoding?}"
139
+ s = "#{enc}\n#{val}\n#{s}"
140
+ end
141
+ end
142
+
143
+ s
144
+ end
145
+
146
+ ##
147
+ # This returns a diff-able more human-readable version of +obj+.
148
+ # This differs from the regular mu_pp because it expands escaped
149
+ # newlines and makes hex-values (like object_ids) generic. This
150
+ # uses mu_pp to do the first pass and then cleans it up.
151
+
152
+ def mu_pp_for_diff obj
153
+ str = mu_pp obj
154
+
155
+ # both '\n' & '\\n' (_after_ mu_pp (aka inspect))
156
+ single = !!str.match(/(?<!\\|^)\\n/)
157
+ double = !!str.match(/(?<=\\|^)\\n/)
158
+
159
+ process =
160
+ if single ^ double then
161
+ if single then
162
+ lambda { |s| s == "\\n" ? "\n" : s } # unescape
163
+ else
164
+ lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
165
+ end
166
+ else
167
+ :itself # leave it alone
168
+ end
169
+
170
+ str.
171
+ gsub(/\\?\\n/, &process).
172
+ gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
173
+ end
174
+
175
+ ##
176
+ # Fails unless +test+ is truthy.
177
+
178
+ def assert test, msg = nil
179
+ self.assertions += 1
180
+ unless test then
181
+ msg ||= "Expected #{mu_pp test} to be truthy."
182
+ msg = msg.call if Proc === msg
183
+ raise Minitest::Assertion, msg
184
+ end
185
+ true
186
+ end
187
+
188
+ def _synchronize # :nodoc:
189
+ yield
190
+ end
191
+
192
+ ##
193
+ # Fails unless +obj+ is empty.
194
+
195
+ def assert_empty obj, msg = nil
196
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" }
197
+ assert_respond_to obj, :empty?
198
+ assert obj.empty?, msg
199
+ end
200
+
201
+ E = "" # :nodoc:
202
+
203
+ ##
204
+ # Fails unless <tt>exp == act</tt> printing the difference between
205
+ # the two, if possible.
206
+ #
207
+ # If there is no visible difference but the assertion fails, you
208
+ # should suspect that your #== is buggy, or your inspect output is
209
+ # missing crucial details. For nicer structural diffing, set
210
+ # Minitest::Test.make_my_diffs_pretty!
211
+ #
212
+ # For floats use assert_in_delta.
213
+ #
214
+ # See also: Minitest::Assertions.diff
215
+
216
+ def assert_equal exp, act, msg = nil
217
+ msg = message(msg, E) { diff exp, act }
218
+ result = assert exp == act, msg
219
+
220
+ if nil == exp then
221
+ if Minitest::VERSION =~ /^6/ then
222
+ refute_nil exp, "Use assert_nil if expecting nil."
223
+ else
224
+ where = Minitest.filter_backtrace(caller).first
225
+ where = where.split(/:in /, 2).first # clean up noise
226
+
227
+ warn "DEPRECATED: Use assert_nil if expecting nil from #{where}. This will fail in Minitest 6."
228
+ end
229
+ end
230
+
231
+ result
232
+ end
233
+
234
+ ##
235
+ # For comparing Floats. Fails unless +exp+ and +act+ are within +delta+
236
+ # of each other.
237
+ #
238
+ # assert_in_delta Math::PI, (22.0 / 7.0), 0.01
239
+
240
+ def assert_in_delta exp, act, delta = 0.001, msg = nil
241
+ n = (exp - act).abs
242
+ msg = message(msg) {
243
+ "Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
244
+ }
245
+ assert delta >= n, msg
246
+ end
247
+
248
+ ##
249
+ # For comparing Floats. Fails unless +exp+ and +act+ have a relative
250
+ # error less than +epsilon+.
251
+
252
+ def assert_in_epsilon exp, act, epsilon = 0.001, msg = nil
253
+ assert_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
254
+ end
255
+
256
+ ##
257
+ # Fails unless +collection+ includes +obj+.
258
+
259
+ def assert_includes collection, obj, msg = nil
260
+ msg = message(msg) {
261
+ "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}"
262
+ }
263
+ assert_respond_to collection, :include?
264
+ assert collection.include?(obj), msg
265
+ end
266
+
267
+ ##
268
+ # Fails unless +obj+ is an instance of +cls+.
269
+
270
+ def assert_instance_of cls, obj, msg = nil
271
+ msg = message(msg) {
272
+ "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
273
+ }
274
+
275
+ assert obj.instance_of?(cls), msg
276
+ end
277
+
278
+ ##
279
+ # Fails unless +obj+ is a kind of +cls+.
280
+
281
+ def assert_kind_of cls, obj, msg = nil
282
+ msg = message(msg) {
283
+ "Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
284
+
285
+ assert obj.kind_of?(cls), msg
286
+ end
287
+
288
+ ##
289
+ # Fails unless +matcher+ <tt>=~</tt> +obj+.
290
+
291
+ def assert_match matcher, obj, msg = nil
292
+ msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
293
+ assert_respond_to matcher, :"=~"
294
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
295
+ assert matcher =~ obj, msg
296
+ end
297
+
298
+ ##
299
+ # Fails unless +obj+ is nil
300
+
301
+ def assert_nil obj, msg = nil
302
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be nil" }
303
+ assert obj.nil?, msg
304
+ end
305
+
306
+ ##
307
+ # For testing with binary operators. Eg:
308
+ #
309
+ # assert_operator 5, :<=, 4
310
+
311
+ def assert_operator o1, op, o2 = UNDEFINED, msg = nil
312
+ return assert_predicate o1, op, msg if UNDEFINED == o2
313
+ msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
314
+ assert o1.__send__(op, o2), msg
315
+ end
316
+
317
+ ##
318
+ # Fails if stdout or stderr do not output the expected results.
319
+ # Pass in nil if you don't care about that streams output. Pass in
320
+ # "" if you require it to be silent. Pass in a regexp if you want
321
+ # to pattern match.
322
+ #
323
+ # assert_output(/hey/) { method_with_output }
324
+ #
325
+ # NOTE: this uses #capture_io, not #capture_subprocess_io.
326
+ #
327
+ # See also: #assert_silent
328
+
329
+ def assert_output stdout = nil, stderr = nil
330
+ flunk "assert_output requires a block to capture output." unless
331
+ block_given?
332
+
333
+ out, err = capture_io do
334
+ yield
335
+ end
336
+
337
+ err_msg = Regexp === stderr ? :assert_match : :assert_equal if stderr
338
+ out_msg = Regexp === stdout ? :assert_match : :assert_equal if stdout
339
+
340
+ y = send err_msg, stderr, err, "In stderr" if err_msg
341
+ x = send out_msg, stdout, out, "In stdout" if out_msg
342
+
343
+ (!stdout || x) && (!stderr || y)
344
+ rescue Assertion
345
+ raise
346
+ rescue => e
347
+ raise UnexpectedError, e
348
+ end
349
+
350
+ ##
351
+ # Fails unless +path+ exists.
352
+
353
+ def assert_path_exists path, msg = nil
354
+ msg = message(msg) { "Expected path '#{path}' to exist" }
355
+ assert File.exist?(path), msg
356
+ end
357
+
358
+ ##
359
+ # For testing with predicates. Eg:
360
+ #
361
+ # assert_predicate str, :empty?
362
+ #
363
+ # This is really meant for specs and is front-ended by assert_operator:
364
+ #
365
+ # str.must_be :empty?
366
+
367
+ def assert_predicate o1, op, msg = nil
368
+ msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" }
369
+ assert o1.__send__(op), msg
370
+ end
371
+
372
+ ##
373
+ # Fails unless the block raises one of +exp+. Returns the
374
+ # exception matched so you can check the message, attributes, etc.
375
+ #
376
+ # +exp+ takes an optional message on the end to help explain
377
+ # failures and defaults to StandardError if no exception class is
378
+ # passed. Eg:
379
+ #
380
+ # assert_raises(CustomError) { method_with_custom_error }
381
+ #
382
+ # With custom error message:
383
+ #
384
+ # assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
385
+ #
386
+ # Using the returned object:
387
+ #
388
+ # error = assert_raises(CustomError) do
389
+ # raise CustomError, 'This is really bad'
390
+ # end
391
+ #
392
+ # assert_equal 'This is really bad', error.message
393
+
394
+ def assert_raises *exp
395
+ flunk "assert_raises requires a block to capture errors." unless
396
+ block_given?
397
+
398
+ msg = "#{exp.pop}.\n" if String === exp.last
399
+ exp << StandardError if exp.empty?
400
+
401
+ begin
402
+ yield
403
+ rescue *exp => e
404
+ pass # count assertion
405
+ return e
406
+ rescue Minitest::Assertion # incl Skip & UnexpectedError
407
+ # don't count assertion
408
+ raise
409
+ rescue SignalException, SystemExit
410
+ raise
411
+ rescue Exception => e
412
+ flunk proc {
413
+ exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
414
+ }
415
+ end
416
+
417
+ exp = exp.first if exp.size == 1
418
+
419
+ flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised."
420
+ end
421
+
422
+ ##
423
+ # Fails unless +obj+ responds to +meth+.
424
+
425
+ def assert_respond_to obj, meth, msg = nil
426
+ msg = message(msg) {
427
+ "Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
428
+ }
429
+ assert obj.respond_to?(meth), msg
430
+ end
431
+
432
+ ##
433
+ # Fails unless +exp+ and +act+ are #equal?
434
+
435
+ def assert_same exp, act, msg = nil
436
+ msg = message(msg) {
437
+ data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
438
+ "Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
439
+ }
440
+ assert exp.equal?(act), msg
441
+ end
442
+
443
+ ##
444
+ # +send_ary+ is a receiver, message and arguments.
445
+ #
446
+ # Fails unless the call returns a true value
447
+
448
+ def assert_send send_ary, m = nil
449
+ where = Minitest.filter_backtrace(caller).first
450
+ where = where.split(/:in /, 2).first # clean up noise
451
+ warn "DEPRECATED: assert_send. From #{where}"
452
+
453
+ recv, msg, *args = send_ary
454
+ m = message(m) {
455
+ "Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
456
+ assert recv.__send__(msg, *args), m
457
+ end
458
+
459
+ ##
460
+ # Fails if the block outputs anything to stderr or stdout.
461
+ #
462
+ # See also: #assert_output
463
+
464
+ def assert_silent
465
+ assert_output "", "" do
466
+ yield
467
+ end
468
+ end
469
+
470
+ ##
471
+ # Fails unless the block throws +sym+
472
+
473
+ def assert_throws sym, msg = nil
474
+ default = "Expected #{mu_pp(sym)} to have been thrown"
475
+ caught = true
476
+ catch(sym) do
477
+ begin
478
+ yield
479
+ rescue ThreadError => e # wtf?!? 1.8 + threads == suck
480
+ default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
481
+ rescue ArgumentError => e # 1.9 exception
482
+ raise e unless e.message.include?("uncaught throw")
483
+ default += ", not #{e.message.split(/ /).last}"
484
+ rescue NameError => e # 1.8 exception
485
+ raise e unless e.name == sym
486
+ default += ", not #{e.name.inspect}"
487
+ end
488
+ caught = false
489
+ end
490
+
491
+ assert caught, message(msg) { default }
492
+ rescue Assertion
493
+ raise
494
+ rescue => e
495
+ raise UnexpectedError, e
496
+ end
497
+
498
+ ##
499
+ # Captures $stdout and $stderr into strings:
500
+ #
501
+ # out, err = capture_io do
502
+ # puts "Some info"
503
+ # warn "You did a bad thing"
504
+ # end
505
+ #
506
+ # assert_match %r%info%, out
507
+ # assert_match %r%bad%, err
508
+ #
509
+ # NOTE: For efficiency, this method uses StringIO and does not
510
+ # capture IO for subprocesses. Use #capture_subprocess_io for
511
+ # that.
512
+
513
+ def capture_io
514
+ _synchronize do
515
+ begin
516
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
517
+
518
+ orig_stdout, orig_stderr = $stdout, $stderr
519
+ $stdout, $stderr = captured_stdout, captured_stderr
520
+
521
+ yield
522
+
523
+ return captured_stdout.string, captured_stderr.string
524
+ ensure
525
+ $stdout = orig_stdout
526
+ $stderr = orig_stderr
527
+ end
528
+ end
529
+ end
530
+
531
+ ##
532
+ # Captures $stdout and $stderr into strings, using Tempfile to
533
+ # ensure that subprocess IO is captured as well.
534
+ #
535
+ # out, err = capture_subprocess_io do
536
+ # system "echo Some info"
537
+ # system "echo You did a bad thing 1>&2"
538
+ # end
539
+ #
540
+ # assert_match %r%info%, out
541
+ # assert_match %r%bad%, err
542
+ #
543
+ # NOTE: This method is approximately 10x slower than #capture_io so
544
+ # only use it when you need to test the output of a subprocess.
545
+
546
+ def capture_subprocess_io
547
+ _synchronize do
548
+ begin
549
+ require "tempfile"
550
+
551
+ captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
552
+
553
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
554
+ $stdout.reopen captured_stdout
555
+ $stderr.reopen captured_stderr
556
+
557
+ yield
558
+
559
+ $stdout.rewind
560
+ $stderr.rewind
561
+
562
+ return captured_stdout.read, captured_stderr.read
563
+ ensure
564
+ captured_stdout.unlink
565
+ captured_stderr.unlink
566
+ $stdout.reopen orig_stdout
567
+ $stderr.reopen orig_stderr
568
+
569
+ orig_stdout.close
570
+ orig_stderr.close
571
+ captured_stdout.close
572
+ captured_stderr.close
573
+ end
574
+ end
575
+ end
576
+
577
+ ##
578
+ # Returns details for exception +e+
579
+
580
+ def exception_details e, msg
581
+ [
582
+ "#{msg}",
583
+ "Class: <#{e.class}>",
584
+ "Message: <#{e.message.inspect}>",
585
+ "---Backtrace---",
586
+ "#{Minitest.filter_backtrace(e.backtrace).join("\n")}",
587
+ "---------------",
588
+ ].join "\n"
589
+ end
590
+
591
+ ##
592
+ # Fails after a given date (in the local time zone). This allows
593
+ # you to put time-bombs in your tests if you need to keep
594
+ # something around until a later date lest you forget about it.
595
+
596
+ def fail_after y,m,d,msg
597
+ flunk msg if Time.now > Time.local(y, m, d)
598
+ end
599
+
600
+ ##
601
+ # Fails with +msg+.
602
+
603
+ def flunk msg = nil
604
+ msg ||= "Epic Fail!"
605
+ assert false, msg
606
+ end
607
+
608
+ ##
609
+ # Returns a proc that will output +msg+ along with the default message.
610
+
611
+ def message msg = nil, ending = nil, &default
612
+ proc {
613
+ msg = msg.call.chomp(".") if Proc === msg
614
+ custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
615
+ "#{custom_message}#{default.call}#{ending || "."}"
616
+ }
617
+ end
618
+
619
+ ##
620
+ # used for counting assertions
621
+
622
+ def pass _msg = nil
623
+ assert true
624
+ end
625
+
626
+ ##
627
+ # Fails if +test+ is truthy.
628
+
629
+ def refute test, msg = nil
630
+ msg ||= message { "Expected #{mu_pp(test)} to not be truthy" }
631
+ assert !test, msg
632
+ end
633
+
634
+ ##
635
+ # Fails if +obj+ is empty.
636
+
637
+ def refute_empty obj, msg = nil
638
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be empty" }
639
+ assert_respond_to obj, :empty?
640
+ refute obj.empty?, msg
641
+ end
642
+
643
+ ##
644
+ # Fails if <tt>exp == act</tt>.
645
+ #
646
+ # For floats use refute_in_delta.
647
+
648
+ def refute_equal exp, act, msg = nil
649
+ msg = message(msg) {
650
+ "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
651
+ }
652
+ refute exp == act, msg
653
+ end
654
+
655
+ ##
656
+ # For comparing Floats. Fails if +exp+ is within +delta+ of +act+.
657
+ #
658
+ # refute_in_delta Math::PI, (22.0 / 7.0)
659
+
660
+ def refute_in_delta exp, act, delta = 0.001, msg = nil
661
+ n = (exp - act).abs
662
+ msg = message(msg) {
663
+ "Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
664
+ }
665
+ refute delta >= n, msg
666
+ end
667
+
668
+ ##
669
+ # For comparing Floats. Fails if +exp+ and +act+ have a relative error
670
+ # less than +epsilon+.
671
+
672
+ def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
673
+ refute_in_delta a, b, a * epsilon, msg
674
+ end
675
+
676
+ ##
677
+ # Fails if +collection+ includes +obj+.
678
+
679
+ def refute_includes collection, obj, msg = nil
680
+ msg = message(msg) {
681
+ "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}"
682
+ }
683
+ assert_respond_to collection, :include?
684
+ refute collection.include?(obj), msg
685
+ end
686
+
687
+ ##
688
+ # Fails if +obj+ is an instance of +cls+.
689
+
690
+ def refute_instance_of cls, obj, msg = nil
691
+ msg = message(msg) {
692
+ "Expected #{mu_pp(obj)} to not be an instance of #{cls}"
693
+ }
694
+ refute obj.instance_of?(cls), msg
695
+ end
696
+
697
+ ##
698
+ # Fails if +obj+ is a kind of +cls+.
699
+
700
+ def refute_kind_of cls, obj, msg = nil
701
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
702
+ refute obj.kind_of?(cls), msg
703
+ end
704
+
705
+ ##
706
+ # Fails if +matcher+ <tt>=~</tt> +obj+.
707
+
708
+ def refute_match matcher, obj, msg = nil
709
+ msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
710
+ assert_respond_to matcher, :"=~"
711
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
712
+ refute matcher =~ obj, msg
713
+ end
714
+
715
+ ##
716
+ # Fails if +obj+ is nil.
717
+
718
+ def refute_nil obj, msg = nil
719
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be nil" }
720
+ refute obj.nil?, msg
721
+ end
722
+
723
+ ##
724
+ # Fails if +o1+ is not +op+ +o2+. Eg:
725
+ #
726
+ # refute_operator 1, :>, 2 #=> pass
727
+ # refute_operator 1, :<, 2 #=> fail
728
+
729
+ def refute_operator o1, op, o2 = UNDEFINED, msg = nil
730
+ return refute_predicate o1, op, msg if UNDEFINED == o2
731
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
732
+ refute o1.__send__(op, o2), msg
733
+ end
734
+
735
+ ##
736
+ # Fails if +path+ exists.
737
+
738
+ def refute_path_exists path, msg = nil
739
+ msg = message(msg) { "Expected path '#{path}' to not exist" }
740
+ refute File.exist?(path), msg
741
+ end
742
+
743
+ ##
744
+ # For testing with predicates.
745
+ #
746
+ # refute_predicate str, :empty?
747
+ #
748
+ # This is really meant for specs and is front-ended by refute_operator:
749
+ #
750
+ # str.wont_be :empty?
751
+
752
+ def refute_predicate o1, op, msg = nil
753
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" }
754
+ refute o1.__send__(op), msg
755
+ end
756
+
757
+ ##
758
+ # Fails if +obj+ responds to the message +meth+.
759
+
760
+ def refute_respond_to obj, meth, msg = nil
761
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
762
+
763
+ refute obj.respond_to?(meth), msg
764
+ end
765
+
766
+ ##
767
+ # Fails if +exp+ is the same (by object identity) as +act+.
768
+
769
+ def refute_same exp, act, msg = nil
770
+ msg = message(msg) {
771
+ data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
772
+ "Expected %s (oid=%d) to not be the same as %s (oid=%d)" % data
773
+ }
774
+ refute exp.equal?(act), msg
775
+ end
776
+
777
+ ##
778
+ # Skips the current run. If run in verbose-mode, the skipped run
779
+ # gets listed at the end of the run but doesn't cause a failure
780
+ # exit code.
781
+
782
+ def skip msg = nil, bt = caller
783
+ msg ||= "Skipped, no message given"
784
+ @skip = true
785
+ raise Minitest::Skip, msg, bt
786
+ end
787
+
788
+ ##
789
+ # Skips the current run until a given date (in the local time
790
+ # zone). This allows you to put some fixes on hold until a later
791
+ # date, but still holds you accountable and prevents you from
792
+ # forgetting it.
793
+
794
+ def skip_until y,m,d,msg
795
+ skip msg if Time.now < Time.local(y, m, d)
796
+ where = caller.first.split(/:/, 3).first(2).join ":"
797
+ warn "Stale skip_until %p at %s" % [msg, where]
798
+ end
799
+
800
+ ##
801
+ # Was this testcase skipped? Meant for #teardown.
802
+
803
+ def skipped?
804
+ defined?(@skip) and @skip
805
+ end
806
+ end
807
+ end