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.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/colorcode_convert_rgb.gemspec +30 -0
- data/exe/colorcode_convert_rgb +4 -0
- data/lib/colorcode_convert_rgb.rb +7 -0
- data/lib/colorcode_convert_rgb/cli.rb +13 -0
- data/lib/colorcode_convert_rgb/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
- data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
- data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
- data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
- data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
- metadata +214 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
require "minitest" unless defined? Minitest::Runnable
|
2
|
+
|
3
|
+
module Minitest
|
4
|
+
##
|
5
|
+
# Subclass Test to create your own tests. Typically you'll want a
|
6
|
+
# Test subclass per implementation class.
|
7
|
+
#
|
8
|
+
# See Minitest::Assertions
|
9
|
+
|
10
|
+
class Test < Runnable
|
11
|
+
require "minitest/assertions"
|
12
|
+
include Minitest::Assertions
|
13
|
+
include Minitest::Reportable
|
14
|
+
|
15
|
+
def class_name # :nodoc:
|
16
|
+
self.class.name # for Minitest::Reportable
|
17
|
+
end
|
18
|
+
|
19
|
+
PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, SystemExit] # :nodoc:
|
20
|
+
|
21
|
+
# :stopdoc:
|
22
|
+
class << self; attr_accessor :io_lock; end
|
23
|
+
self.io_lock = Mutex.new
|
24
|
+
# :startdoc:
|
25
|
+
|
26
|
+
##
|
27
|
+
# Call this at the top of your tests when you absolutely
|
28
|
+
# positively need to have ordered tests. In doing so, you're
|
29
|
+
# admitting that you suck and your tests are weak.
|
30
|
+
|
31
|
+
def self.i_suck_and_my_tests_are_order_dependent!
|
32
|
+
class << self
|
33
|
+
undef_method :test_order if method_defined? :test_order
|
34
|
+
define_method :test_order do :alpha end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Make diffs for this Test use #pretty_inspect so that diff
|
40
|
+
# in assert_equal can have more details. NOTE: this is much slower
|
41
|
+
# than the regular inspect but much more usable for complex
|
42
|
+
# objects.
|
43
|
+
|
44
|
+
def self.make_my_diffs_pretty!
|
45
|
+
require "pp"
|
46
|
+
|
47
|
+
define_method :mu_pp, &:pretty_inspect
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Call this at the top of your tests when you want to run your
|
52
|
+
# tests in parallel. In doing so, you're admitting that you rule
|
53
|
+
# and your tests are awesome.
|
54
|
+
|
55
|
+
def self.parallelize_me!
|
56
|
+
include Minitest::Parallel::Test
|
57
|
+
extend Minitest::Parallel::Test::ClassMethods
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Returns all instance methods starting with "test_". Based on
|
62
|
+
# #test_order, the methods are either sorted, randomized
|
63
|
+
# (default), or run in parallel.
|
64
|
+
|
65
|
+
def self.runnable_methods
|
66
|
+
methods = methods_matching(/^test_/)
|
67
|
+
|
68
|
+
case self.test_order
|
69
|
+
when :random, :parallel then
|
70
|
+
max = methods.size
|
71
|
+
methods.sort.sort_by { rand max }
|
72
|
+
when :alpha, :sorted then
|
73
|
+
methods.sort
|
74
|
+
else
|
75
|
+
raise "Unknown test_order: #{self.test_order.inspect}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Defines the order to run tests (:random by default). Override
|
81
|
+
# this or use a convenience method to change it for your tests.
|
82
|
+
|
83
|
+
def self.test_order
|
84
|
+
:random
|
85
|
+
end
|
86
|
+
|
87
|
+
TEARDOWN_METHODS = %w[ before_teardown teardown after_teardown ] # :nodoc:
|
88
|
+
|
89
|
+
##
|
90
|
+
# Runs a single test with setup/teardown hooks.
|
91
|
+
|
92
|
+
def run
|
93
|
+
with_info_handler do
|
94
|
+
time_it do
|
95
|
+
capture_exceptions do
|
96
|
+
before_setup; setup; after_setup
|
97
|
+
|
98
|
+
self.send self.name
|
99
|
+
end
|
100
|
+
|
101
|
+
TEARDOWN_METHODS.each do |hook|
|
102
|
+
capture_exceptions do
|
103
|
+
self.send hook
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
Result.from self # per contract
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Provides before/after hooks for setup and teardown. These are
|
114
|
+
# meant for library writers, NOT for regular test authors. See
|
115
|
+
# #before_setup for an example.
|
116
|
+
|
117
|
+
module LifecycleHooks
|
118
|
+
|
119
|
+
##
|
120
|
+
# Runs before every test, before setup. This hook is meant for
|
121
|
+
# libraries to extend minitest. It is not meant to be used by
|
122
|
+
# test developers.
|
123
|
+
#
|
124
|
+
# As a simplistic example:
|
125
|
+
#
|
126
|
+
# module MyMinitestPlugin
|
127
|
+
# def before_setup
|
128
|
+
# super
|
129
|
+
# # ... stuff to do before setup is run
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
# def after_setup
|
133
|
+
# # ... stuff to do after setup is run
|
134
|
+
# super
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# def before_teardown
|
138
|
+
# super
|
139
|
+
# # ... stuff to do before teardown is run
|
140
|
+
# end
|
141
|
+
#
|
142
|
+
# def after_teardown
|
143
|
+
# # ... stuff to do after teardown is run
|
144
|
+
# super
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# class MiniTest::Test
|
149
|
+
# include MyMinitestPlugin
|
150
|
+
# end
|
151
|
+
|
152
|
+
def before_setup; end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Runs before every test. Use this to set up before each test
|
156
|
+
# run.
|
157
|
+
|
158
|
+
def setup; end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Runs before every test, after setup. This hook is meant for
|
162
|
+
# libraries to extend minitest. It is not meant to be used by
|
163
|
+
# test developers.
|
164
|
+
#
|
165
|
+
# See #before_setup for an example.
|
166
|
+
|
167
|
+
def after_setup; end
|
168
|
+
|
169
|
+
##
|
170
|
+
# Runs after every test, before teardown. This hook is meant for
|
171
|
+
# libraries to extend minitest. It is not meant to be used by
|
172
|
+
# test developers.
|
173
|
+
#
|
174
|
+
# See #before_setup for an example.
|
175
|
+
|
176
|
+
def before_teardown; end
|
177
|
+
|
178
|
+
##
|
179
|
+
# Runs after every test. Use this to clean up after each test
|
180
|
+
# run.
|
181
|
+
|
182
|
+
def teardown; end
|
183
|
+
|
184
|
+
##
|
185
|
+
# Runs after every test, after teardown. This hook is meant for
|
186
|
+
# libraries to extend minitest. It is not meant to be used by
|
187
|
+
# test developers.
|
188
|
+
#
|
189
|
+
# See #before_setup for an example.
|
190
|
+
|
191
|
+
def after_teardown; end
|
192
|
+
end # LifecycleHooks
|
193
|
+
|
194
|
+
def capture_exceptions # :nodoc:
|
195
|
+
yield
|
196
|
+
rescue *PASSTHROUGH_EXCEPTIONS
|
197
|
+
raise
|
198
|
+
rescue Assertion => e
|
199
|
+
self.failures << e
|
200
|
+
rescue Exception => e
|
201
|
+
self.failures << UnexpectedError.new(e)
|
202
|
+
end
|
203
|
+
|
204
|
+
def with_info_handler &block # :nodoc:
|
205
|
+
t0 = Minitest.clock_time
|
206
|
+
|
207
|
+
handler = lambda do
|
208
|
+
warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0]
|
209
|
+
end
|
210
|
+
|
211
|
+
self.class.on_signal ::Minitest.info_signal, handler, &block
|
212
|
+
end
|
213
|
+
|
214
|
+
include LifecycleHooks
|
215
|
+
include Guard
|
216
|
+
extend Guard
|
217
|
+
end # Test
|
218
|
+
end
|
219
|
+
|
220
|
+
require "minitest/unit" unless defined?(MiniTest) # compatibility layer only
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
|
3
|
+
unless defined?(Minitest) then
|
4
|
+
# all of this crap is just to avoid circular requires and is only
|
5
|
+
# needed if a user requires "minitest/unit" directly instead of
|
6
|
+
# "minitest/autorun", so we also warn
|
7
|
+
|
8
|
+
from = caller.reject { |s| s =~ /rubygems/ }.join("\n ")
|
9
|
+
warn "Warning: you should require 'minitest/autorun' instead."
|
10
|
+
warn %(Warning: or add 'gem "minitest"' before 'require "minitest/autorun"')
|
11
|
+
warn "From:\n #{from}"
|
12
|
+
|
13
|
+
module Minitest; end
|
14
|
+
MiniTest = Minitest # prevents minitest.rb from requiring back to us
|
15
|
+
require "minitest"
|
16
|
+
end
|
17
|
+
|
18
|
+
MiniTest = Minitest unless defined?(MiniTest)
|
19
|
+
|
20
|
+
module Minitest
|
21
|
+
class Unit
|
22
|
+
VERSION = Minitest::VERSION
|
23
|
+
class TestCase < Minitest::Test
|
24
|
+
def self.inherited klass # :nodoc:
|
25
|
+
from = caller.first
|
26
|
+
warn "MiniTest::Unit::TestCase is now Minitest::Test. From #{from}"
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.autorun # :nodoc:
|
32
|
+
from = caller.first
|
33
|
+
warn "MiniTest::Unit.autorun is now Minitest.autorun. From #{from}"
|
34
|
+
Minitest.autorun
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.after_tests &b # :nodoc:
|
38
|
+
from = caller.first
|
39
|
+
warn "MiniTest::Unit.after_tests is now Minitest.after_run. From #{from}"
|
40
|
+
Minitest.after_run(&b)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# :startdoc:
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
require "stringio"
|
3
|
+
require "minitest/autorun"
|
4
|
+
|
5
|
+
class Minitest::Test
|
6
|
+
def clean s
|
7
|
+
s.gsub(/^ {6}/, "")
|
8
|
+
end
|
9
|
+
|
10
|
+
def with_empty_backtrace_filter
|
11
|
+
original = Minitest.backtrace_filter
|
12
|
+
|
13
|
+
obj = Minitest::BacktraceFilter.new
|
14
|
+
def obj.filter _bt
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
|
18
|
+
Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
|
19
|
+
begin
|
20
|
+
Minitest.backtrace_filter = obj
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
Minitest.backtrace_filter = original
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class FakeNamedTest < Minitest::Test
|
31
|
+
@@count = 0
|
32
|
+
|
33
|
+
def self.name
|
34
|
+
@fake_name ||= begin
|
35
|
+
@@count += 1
|
36
|
+
"FakeNamedTest%02d" % @@count
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module MyModule; end
|
42
|
+
class AnError < StandardError; include MyModule; end
|
43
|
+
|
44
|
+
class MetaMetaMetaTestCase < Minitest::Test
|
45
|
+
attr_accessor :reporter, :output, :tu
|
46
|
+
|
47
|
+
def with_stderr err
|
48
|
+
old = $stderr
|
49
|
+
$stderr = err
|
50
|
+
yield
|
51
|
+
ensure
|
52
|
+
$stderr = old
|
53
|
+
end
|
54
|
+
|
55
|
+
def run_tu_with_fresh_reporter flags = %w[--seed 42]
|
56
|
+
options = Minitest.process_args flags
|
57
|
+
|
58
|
+
@output = StringIO.new("".encode('UTF-8'))
|
59
|
+
|
60
|
+
self.reporter = Minitest::CompositeReporter.new
|
61
|
+
reporter << Minitest::SummaryReporter.new(@output, options)
|
62
|
+
reporter << Minitest::ProgressReporter.new(@output, options)
|
63
|
+
|
64
|
+
with_stderr @output do
|
65
|
+
reporter.start
|
66
|
+
|
67
|
+
yield(reporter) if block_given?
|
68
|
+
|
69
|
+
@tus ||= [@tu]
|
70
|
+
@tus.each do |tu|
|
71
|
+
Minitest::Runnable.runnables.delete tu
|
72
|
+
|
73
|
+
tu.run reporter, options
|
74
|
+
end
|
75
|
+
|
76
|
+
reporter.report
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def first_reporter
|
81
|
+
reporter.reporters.first
|
82
|
+
end
|
83
|
+
|
84
|
+
def assert_report expected, flags = %w[--seed 42], &block
|
85
|
+
header = clean <<-EOM
|
86
|
+
Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}
|
87
|
+
|
88
|
+
# Running:
|
89
|
+
|
90
|
+
EOM
|
91
|
+
|
92
|
+
run_tu_with_fresh_reporter flags, &block
|
93
|
+
|
94
|
+
output = normalize_output @output.string.dup
|
95
|
+
|
96
|
+
assert_equal header + expected, output
|
97
|
+
end
|
98
|
+
|
99
|
+
def normalize_output output
|
100
|
+
output.sub!(/Finished in .*/, "Finished in 0.00")
|
101
|
+
output.sub!(/Loaded suite .*/, "Loaded suite blah")
|
102
|
+
|
103
|
+
output.gsub!(/FakeNamedTest\d+/, "FakeNamedTestXX")
|
104
|
+
output.gsub!(/ = \d+.\d\d s = /, " = 0.00 s = ")
|
105
|
+
output.gsub!(/0x[A-Fa-f0-9]+/, "0xXXX")
|
106
|
+
output.gsub!(/ +$/, "")
|
107
|
+
|
108
|
+
if windows? then
|
109
|
+
output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, "[FILE:LINE]")
|
110
|
+
output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
|
111
|
+
else
|
112
|
+
output.gsub!(/\[[^\]:]+:\d+\]/, "[FILE:LINE]")
|
113
|
+
output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
|
114
|
+
end
|
115
|
+
|
116
|
+
output.gsub!(/( at )[^:]+:\d+/, '\1[FILE:LINE]')
|
117
|
+
|
118
|
+
output
|
119
|
+
end
|
120
|
+
|
121
|
+
def restore_env
|
122
|
+
old_value = ENV["MT_NO_SKIP_MSG"]
|
123
|
+
ENV.delete "MT_NO_SKIP_MSG"
|
124
|
+
|
125
|
+
yield
|
126
|
+
ensure
|
127
|
+
ENV["MT_NO_SKIP_MSG"] = old_value
|
128
|
+
end
|
129
|
+
|
130
|
+
def setup
|
131
|
+
super
|
132
|
+
srand 42
|
133
|
+
Minitest::Test.reset
|
134
|
+
@tu = nil
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,1575 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "minitest/autorun"
|
4
|
+
|
5
|
+
if defined? Encoding then
|
6
|
+
e = Encoding.default_external
|
7
|
+
if e != Encoding::UTF_8 then
|
8
|
+
warn ""
|
9
|
+
warn ""
|
10
|
+
warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
|
11
|
+
warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
|
12
|
+
warn ""
|
13
|
+
warn ""
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
SomeError = Class.new Exception
|
18
|
+
|
19
|
+
unless defined? MyModule then
|
20
|
+
module MyModule; end
|
21
|
+
class AnError < StandardError; include MyModule; end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TestMinitestAssertions < Minitest::Test
|
25
|
+
# do not call parallelize_me! - teardown accesses @tc._assertions
|
26
|
+
# which is not threadsafe. Nearly every method in here is an
|
27
|
+
# assertion test so it isn't worth splitting it out further.
|
28
|
+
|
29
|
+
RUBY18 = !defined? Encoding
|
30
|
+
|
31
|
+
class DummyTest
|
32
|
+
include Minitest::Assertions
|
33
|
+
# include Minitest::Reportable # TODO: why do I really need this?
|
34
|
+
|
35
|
+
attr_accessor :assertions, :failure
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
self.assertions = 0
|
39
|
+
self.failure = nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup
|
44
|
+
super
|
45
|
+
|
46
|
+
Minitest::Test.reset
|
47
|
+
|
48
|
+
@tc = DummyTest.new
|
49
|
+
@zomg = "zomg ponies!" # TODO: const
|
50
|
+
@assertion_count = 1
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
assert_equal(@assertion_count, @tc.assertions,
|
55
|
+
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}")
|
56
|
+
end
|
57
|
+
|
58
|
+
def assert_deprecated name
|
59
|
+
dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
|
60
|
+
dep = "" if $-w.nil?
|
61
|
+
|
62
|
+
assert_output nil, dep do
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def assert_triggered expected, klass = Minitest::Assertion
|
68
|
+
e = assert_raises klass do
|
69
|
+
yield
|
70
|
+
end
|
71
|
+
|
72
|
+
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
73
|
+
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
|
74
|
+
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
75
|
+
|
76
|
+
assert_msg = Regexp === expected ? :assert_match : :assert_equal
|
77
|
+
self.send assert_msg, expected, msg
|
78
|
+
end
|
79
|
+
|
80
|
+
def assert_unexpected expected
|
81
|
+
expected = Regexp.new expected if String === expected
|
82
|
+
|
83
|
+
assert_triggered expected, Minitest::UnexpectedError do
|
84
|
+
yield
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def clean s
|
89
|
+
s.gsub(/^ {6,10}/, "")
|
90
|
+
end
|
91
|
+
|
92
|
+
def non_verbose
|
93
|
+
orig_verbose = $VERBOSE
|
94
|
+
$VERBOSE = false
|
95
|
+
|
96
|
+
yield
|
97
|
+
ensure
|
98
|
+
$VERBOSE = orig_verbose
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_assert
|
102
|
+
@assertion_count = 2
|
103
|
+
|
104
|
+
@tc.assert_equal true, @tc.assert(true), "returns true on success"
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_assert__triggered
|
108
|
+
assert_triggered "Expected false to be truthy." do
|
109
|
+
@tc.assert false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_assert__triggered_message
|
114
|
+
assert_triggered @zomg do
|
115
|
+
@tc.assert false, @zomg
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_assert__triggered_lambda
|
120
|
+
assert_triggered "whoops" do
|
121
|
+
@tc.assert false, lambda { "whoops" }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_assert_empty
|
126
|
+
@assertion_count = 2
|
127
|
+
|
128
|
+
@tc.assert_empty []
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_assert_empty_triggered
|
132
|
+
@assertion_count = 2
|
133
|
+
|
134
|
+
assert_triggered "Expected [1] to be empty." do
|
135
|
+
@tc.assert_empty [1]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_assert_equal
|
140
|
+
@tc.assert_equal 1, 1
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_assert_equal_different_collection_array_hex_invisible
|
144
|
+
object1 = Object.new
|
145
|
+
object2 = Object.new
|
146
|
+
msg = "No visible difference in the Array#inspect output.
|
147
|
+
You should look at the implementation of #== on Array or its members.
|
148
|
+
[#<Object:0xXXXXXX>]".gsub(/^ +/, "")
|
149
|
+
assert_triggered msg do
|
150
|
+
@tc.assert_equal [object1], [object2]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_assert_equal_different_collection_hash_hex_invisible
|
155
|
+
h1, h2 = {}, {}
|
156
|
+
h1[1] = Object.new
|
157
|
+
h2[1] = Object.new
|
158
|
+
msg = "No visible difference in the Hash#inspect output.
|
159
|
+
You should look at the implementation of #== on Hash or its members.
|
160
|
+
{1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
|
161
|
+
|
162
|
+
assert_triggered msg do
|
163
|
+
@tc.assert_equal h1, h2
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_assert_equal_different_diff_deactivated
|
168
|
+
without_diff do
|
169
|
+
assert_triggered util_msg("haha" * 10, "blah" * 10) do
|
170
|
+
o1 = "haha" * 10
|
171
|
+
o2 = "blah" * 10
|
172
|
+
|
173
|
+
@tc.assert_equal o1, o2
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_assert_equal_different_message
|
179
|
+
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
180
|
+
@tc.assert_equal 1, 2, message { "whoops" }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_assert_equal_different_lambda
|
185
|
+
assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
|
186
|
+
@tc.assert_equal 1, 2, lambda { "whoops" }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_assert_equal_different_hex
|
191
|
+
c = Class.new do
|
192
|
+
def initialize s; @name = s; end
|
193
|
+
end
|
194
|
+
|
195
|
+
o1 = c.new "a"
|
196
|
+
o2 = c.new "b"
|
197
|
+
msg = clean <<-EOS
|
198
|
+
--- expected
|
199
|
+
+++ actual
|
200
|
+
@@ -1 +1 @@
|
201
|
+
-#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
|
202
|
+
+#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
|
203
|
+
EOS
|
204
|
+
|
205
|
+
assert_triggered msg do
|
206
|
+
@tc.assert_equal o1, o2
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_assert_equal_different_hex_invisible
|
211
|
+
o1 = Object.new
|
212
|
+
o2 = Object.new
|
213
|
+
|
214
|
+
msg = "No visible difference in the Object#inspect output.
|
215
|
+
You should look at the implementation of #== on Object or its members.
|
216
|
+
#<Object:0xXXXXXX>".gsub(/^ +/, "")
|
217
|
+
|
218
|
+
assert_triggered msg do
|
219
|
+
@tc.assert_equal o1, o2
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_assert_equal_different_long
|
224
|
+
msg = "--- expected
|
225
|
+
+++ actual
|
226
|
+
@@ -1 +1 @@
|
227
|
+
-\"hahahahahahahahahahahahahahahahahahahaha\"
|
228
|
+
+\"blahblahblahblahblahblahblahblahblahblah\"
|
229
|
+
".gsub(/^ +/, "")
|
230
|
+
|
231
|
+
assert_triggered msg do
|
232
|
+
o1 = "haha" * 10
|
233
|
+
o2 = "blah" * 10
|
234
|
+
|
235
|
+
@tc.assert_equal o1, o2
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_assert_equal_different_long_invisible
|
240
|
+
msg = "No visible difference in the String#inspect output.
|
241
|
+
You should look at the implementation of #== on String or its members.
|
242
|
+
\"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
|
243
|
+
|
244
|
+
assert_triggered msg do
|
245
|
+
o1 = "blah" * 10
|
246
|
+
o2 = "blah" * 10
|
247
|
+
def o1.== _
|
248
|
+
false
|
249
|
+
end
|
250
|
+
@tc.assert_equal o1, o2
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_assert_equal_different_long_msg
|
255
|
+
msg = "message.
|
256
|
+
--- expected
|
257
|
+
+++ actual
|
258
|
+
@@ -1 +1 @@
|
259
|
+
-\"hahahahahahahahahahahahahahahahahahahaha\"
|
260
|
+
+\"blahblahblahblahblahblahblahblahblahblah\"
|
261
|
+
".gsub(/^ +/, "")
|
262
|
+
|
263
|
+
assert_triggered msg do
|
264
|
+
o1 = "haha" * 10
|
265
|
+
o2 = "blah" * 10
|
266
|
+
@tc.assert_equal o1, o2, "message"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_assert_equal_different_short
|
271
|
+
assert_triggered util_msg(1, 2) do
|
272
|
+
@tc.assert_equal 1, 2
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_assert_equal_different_short_msg
|
277
|
+
assert_triggered util_msg(1, 2, "message") do
|
278
|
+
@tc.assert_equal 1, 2, "message"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_assert_equal_different_short_multiline
|
283
|
+
msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n"
|
284
|
+
assert_triggered msg do
|
285
|
+
@tc.assert_equal "a\nb", "a\nc"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_assert_equal_does_not_allow_lhs_nil
|
290
|
+
if Minitest::VERSION =~ /^6/ then
|
291
|
+
warn "Time to strip the MT5 test"
|
292
|
+
|
293
|
+
@assertion_count += 1
|
294
|
+
assert_triggered(/Use assert_nil if expecting nil/) do
|
295
|
+
@tc.assert_equal nil, nil
|
296
|
+
end
|
297
|
+
else
|
298
|
+
err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/
|
299
|
+
err_re = "" if $-w.nil?
|
300
|
+
|
301
|
+
assert_output "", err_re do
|
302
|
+
@tc.assert_equal nil, nil
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_assert_equal_does_not_allow_lhs_nil_triggered
|
308
|
+
assert_triggered "Expected: nil\n Actual: false" do
|
309
|
+
@tc.assert_equal nil, false
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_assert_equal_string_bug791
|
314
|
+
exp = <<-'EOF'.gsub(/^ {10}/, "") # note single quotes
|
315
|
+
--- expected
|
316
|
+
+++ actual
|
317
|
+
@@ -1,2 +1 @@
|
318
|
+
-"\\n
|
319
|
+
-"
|
320
|
+
+"\\\"
|
321
|
+
EOF
|
322
|
+
|
323
|
+
exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\""
|
324
|
+
assert_triggered exp do
|
325
|
+
@tc.assert_equal "\\n", "\\"
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_assert_equal_string_both_escaped_unescaped_newlines
|
330
|
+
msg = <<-EOM.gsub(/^ {10}/, "")
|
331
|
+
--- expected
|
332
|
+
+++ actual
|
333
|
+
@@ -1,2 +1 @@
|
334
|
+
-\"A\\n
|
335
|
+
-B\"
|
336
|
+
+\"A\\n\\\\nB\"
|
337
|
+
EOM
|
338
|
+
|
339
|
+
assert_triggered msg do
|
340
|
+
exp = "A\\nB"
|
341
|
+
act = "A\n\\nB"
|
342
|
+
|
343
|
+
@tc.assert_equal exp, act
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_assert_equal_string_encodings
|
348
|
+
msg = <<-EOM.gsub(/^ {10}/, "")
|
349
|
+
--- expected
|
350
|
+
+++ actual
|
351
|
+
@@ -1,3 +1,3 @@
|
352
|
+
-# encoding: UTF-8
|
353
|
+
-# valid: false
|
354
|
+
+# encoding: ASCII-8BIT
|
355
|
+
+# valid: true
|
356
|
+
"bad-utf8-\\xF1.txt"
|
357
|
+
EOM
|
358
|
+
|
359
|
+
assert_triggered msg do
|
360
|
+
x = "bad-utf8-\xF1.txt"
|
361
|
+
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
362
|
+
@tc.assert_equal x, y
|
363
|
+
end
|
364
|
+
end unless RUBY18
|
365
|
+
|
366
|
+
def test_assert_equal_string_encodings_both_different
|
367
|
+
msg = <<-EOM.gsub(/^ {10}/, "")
|
368
|
+
--- expected
|
369
|
+
+++ actual
|
370
|
+
@@ -1,3 +1,3 @@
|
371
|
+
-# encoding: US-ASCII
|
372
|
+
-# valid: false
|
373
|
+
+# encoding: ASCII-8BIT
|
374
|
+
+# valid: true
|
375
|
+
"bad-utf8-\\xF1.txt"
|
376
|
+
EOM
|
377
|
+
|
378
|
+
assert_triggered msg do
|
379
|
+
x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
|
380
|
+
y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
|
381
|
+
@tc.assert_equal x, y
|
382
|
+
end
|
383
|
+
end unless RUBY18
|
384
|
+
|
385
|
+
def test_assert_equal_unescape_newlines
|
386
|
+
msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
|
387
|
+
--- expected
|
388
|
+
+++ actual
|
389
|
+
@@ -1,2 +1,2 @@
|
390
|
+
-"hello
|
391
|
+
+"hello\n
|
392
|
+
world"
|
393
|
+
EOM
|
394
|
+
|
395
|
+
assert_triggered msg do
|
396
|
+
exp = "hello\nworld"
|
397
|
+
act = 'hello\nworld' # notice single quotes
|
398
|
+
|
399
|
+
@tc.assert_equal exp, act
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_assert_in_delta
|
404
|
+
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_assert_in_delta_triggered
|
408
|
+
x = "1.0e-06"
|
409
|
+
assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
410
|
+
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_assert_in_epsilon
|
415
|
+
@assertion_count = 10
|
416
|
+
|
417
|
+
@tc.assert_in_epsilon 10_000, 9991
|
418
|
+
@tc.assert_in_epsilon 9991, 10_000
|
419
|
+
@tc.assert_in_epsilon 1.0, 1.001
|
420
|
+
@tc.assert_in_epsilon 1.001, 1.0
|
421
|
+
|
422
|
+
@tc.assert_in_epsilon 10_000, 9999.1, 0.0001
|
423
|
+
@tc.assert_in_epsilon 9999.1, 10_000, 0.0001
|
424
|
+
@tc.assert_in_epsilon 1.0, 1.0001, 0.0001
|
425
|
+
@tc.assert_in_epsilon 1.0001, 1.0, 0.0001
|
426
|
+
|
427
|
+
@tc.assert_in_epsilon(-1, -1)
|
428
|
+
@tc.assert_in_epsilon(-10_000, -9991)
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_assert_in_epsilon_triggered
|
432
|
+
assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do
|
433
|
+
@tc.assert_in_epsilon 10_000, 9990
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_assert_in_epsilon_triggered_negative_case
|
438
|
+
x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
|
439
|
+
y = "0.1"
|
440
|
+
assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
|
441
|
+
@tc.assert_in_epsilon(-1.1, -1, 0.1)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_assert_includes
|
446
|
+
@assertion_count = 2
|
447
|
+
|
448
|
+
@tc.assert_includes [true], true
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_assert_includes_triggered
|
452
|
+
@assertion_count = 3
|
453
|
+
|
454
|
+
e = @tc.assert_raises Minitest::Assertion do
|
455
|
+
@tc.assert_includes [true], false
|
456
|
+
end
|
457
|
+
|
458
|
+
expected = "Expected [true] to include false."
|
459
|
+
assert_equal expected, e.message
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_assert_instance_of
|
463
|
+
@tc.assert_instance_of String, "blah"
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_assert_instance_of_triggered
|
467
|
+
assert_triggered 'Expected "blah" to be an instance of Array, not String.' do
|
468
|
+
@tc.assert_instance_of Array, "blah"
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_assert_kind_of
|
473
|
+
@tc.assert_kind_of String, "blah"
|
474
|
+
end
|
475
|
+
|
476
|
+
def test_assert_kind_of_triggered
|
477
|
+
assert_triggered 'Expected "blah" to be a kind of Array, not String.' do
|
478
|
+
@tc.assert_kind_of Array, "blah"
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
def test_assert_match
|
483
|
+
@assertion_count = 2
|
484
|
+
@tc.assert_match(/\w+/, "blah blah blah")
|
485
|
+
end
|
486
|
+
|
487
|
+
def test_assert_match_matchee_to_str
|
488
|
+
@assertion_count = 2
|
489
|
+
|
490
|
+
obj = Object.new
|
491
|
+
def obj.to_str; "blah" end
|
492
|
+
|
493
|
+
@tc.assert_match "blah", obj
|
494
|
+
end
|
495
|
+
|
496
|
+
def test_assert_match_matcher_object
|
497
|
+
@assertion_count = 2
|
498
|
+
|
499
|
+
pattern = Object.new
|
500
|
+
def pattern.=~ _; true end
|
501
|
+
|
502
|
+
@tc.assert_match pattern, 5
|
503
|
+
end
|
504
|
+
|
505
|
+
def test_assert_match_object_triggered
|
506
|
+
@assertion_count = 2
|
507
|
+
|
508
|
+
pattern = Object.new
|
509
|
+
def pattern.=~ _; false end
|
510
|
+
def pattern.inspect; "[Object]" end
|
511
|
+
|
512
|
+
assert_triggered "Expected [Object] to match 5." do
|
513
|
+
@tc.assert_match pattern, 5
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_assert_match_triggered
|
518
|
+
@assertion_count = 2
|
519
|
+
assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
|
520
|
+
@tc.assert_match(/\d+/, "blah blah blah")
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
def test_assert_nil
|
525
|
+
@tc.assert_nil nil
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_assert_nil_triggered
|
529
|
+
assert_triggered "Expected 42 to be nil." do
|
530
|
+
@tc.assert_nil 42
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
def test_assert_operator
|
535
|
+
@tc.assert_operator 2, :>, 1
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_assert_operator_bad_object
|
539
|
+
bad = Object.new
|
540
|
+
def bad.== _; true end
|
541
|
+
|
542
|
+
@tc.assert_operator bad, :equal?, bad
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_assert_operator_triggered
|
546
|
+
assert_triggered "Expected 2 to be < 1." do
|
547
|
+
@tc.assert_operator 2, :<, 1
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
def test_assert_output_both
|
552
|
+
@assertion_count = 2
|
553
|
+
|
554
|
+
@tc.assert_output "yay", "blah" do
|
555
|
+
print "yay"
|
556
|
+
$stderr.print "blah"
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
def test_assert_output_both_regexps
|
561
|
+
@assertion_count = 4
|
562
|
+
|
563
|
+
@tc.assert_output(/y.y/, /bl.h/) do
|
564
|
+
print "yay"
|
565
|
+
$stderr.print "blah"
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_assert_output_err
|
570
|
+
@tc.assert_output nil, "blah" do
|
571
|
+
$stderr.print "blah"
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
def test_assert_output_neither
|
576
|
+
@assertion_count = 0
|
577
|
+
|
578
|
+
@tc.assert_output do
|
579
|
+
# do nothing
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_assert_output_out
|
584
|
+
@tc.assert_output "blah" do
|
585
|
+
print "blah"
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_assert_output_triggered_both
|
590
|
+
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
591
|
+
@tc.assert_output "yay", "blah" do
|
592
|
+
print "boo"
|
593
|
+
$stderr.print "blah blah"
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
def test_assert_output_triggered_err
|
599
|
+
assert_triggered util_msg("blah", "blah blah", "In stderr") do
|
600
|
+
@tc.assert_output nil, "blah" do
|
601
|
+
$stderr.print "blah blah"
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
def test_assert_output_triggered_out
|
607
|
+
assert_triggered util_msg("blah", "blah blah", "In stdout") do
|
608
|
+
@tc.assert_output "blah" do
|
609
|
+
print "blah blah"
|
610
|
+
end
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
def test_assert_output_no_block
|
615
|
+
assert_triggered "assert_output requires a block to capture output." do
|
616
|
+
@tc.assert_output "blah"
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
def test_assert_output_nested_assert_uncaught
|
621
|
+
@assertion_count = 1
|
622
|
+
|
623
|
+
assert_triggered "Epic Fail!" do
|
624
|
+
@tc.assert_output "blah\n" do
|
625
|
+
puts "blah"
|
626
|
+
@tc.flunk
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
def test_assert_output_nested_raise
|
632
|
+
@assertion_count = 2
|
633
|
+
|
634
|
+
@tc.assert_output "blah\n" do
|
635
|
+
@tc.assert_raises RuntimeError do
|
636
|
+
puts "blah"
|
637
|
+
raise "boom!"
|
638
|
+
end
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
642
|
+
def test_assert_output_nested_raise_bad
|
643
|
+
@assertion_count = 0
|
644
|
+
|
645
|
+
assert_unexpected "boom!" do
|
646
|
+
@tc.assert_raises do # 2) bypassed via UnexpectedError
|
647
|
+
@tc.assert_output "blah\n" do # 1) captures and raises UnexpectedError
|
648
|
+
puts "not_blah"
|
649
|
+
raise "boom!"
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_assert_output_nested_raise_mismatch
|
656
|
+
# this test is redundant, but illustrative
|
657
|
+
@assertion_count = 0
|
658
|
+
|
659
|
+
assert_unexpected "boom!" do
|
660
|
+
@tc.assert_raises RuntimeError do # 2) bypassed via UnexpectedError
|
661
|
+
@tc.assert_output "blah\n" do # 1) captures and raises UnexpectedError
|
662
|
+
puts "not_blah"
|
663
|
+
raise ArgumentError, "boom!"
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
end
|
668
|
+
|
669
|
+
def test_assert_output_nested_throw_caught
|
670
|
+
@assertion_count = 2
|
671
|
+
|
672
|
+
@tc.assert_output "blah\n" do
|
673
|
+
@tc.assert_throws :boom! do
|
674
|
+
puts "blah"
|
675
|
+
throw :boom!
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
def test_assert_output_nested_throw_caught_bad
|
681
|
+
@assertion_count = 1 # want 0; can't prevent throw from escaping :(
|
682
|
+
|
683
|
+
@tc.assert_throws :boom! do # 2) captured via catch
|
684
|
+
@tc.assert_output "blah\n" do # 1) bypassed via throw
|
685
|
+
puts "not_blah"
|
686
|
+
throw :boom!
|
687
|
+
end
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
def test_assert_output_nested_throw_mismatch
|
692
|
+
@assertion_count = 0
|
693
|
+
|
694
|
+
assert_unexpected "uncaught throw :boom!" do
|
695
|
+
@tc.assert_throws :not_boom! do # 2) captured via assert_throws+rescue
|
696
|
+
@tc.assert_output "blah\n" do # 1) bypassed via throw
|
697
|
+
puts "not_blah"
|
698
|
+
throw :boom!
|
699
|
+
end
|
700
|
+
end
|
701
|
+
end
|
702
|
+
end
|
703
|
+
|
704
|
+
def test_assert_output_uncaught_raise
|
705
|
+
@assertion_count = 0
|
706
|
+
|
707
|
+
assert_unexpected "RuntimeError: boom!" do
|
708
|
+
@tc.assert_output "blah\n" do
|
709
|
+
puts "not_blah"
|
710
|
+
raise "boom!"
|
711
|
+
end
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
def test_assert_output_uncaught_throw
|
716
|
+
@assertion_count = 0
|
717
|
+
|
718
|
+
assert_unexpected "uncaught throw :boom!" do
|
719
|
+
@tc.assert_output "blah\n" do
|
720
|
+
puts "not_blah"
|
721
|
+
throw :boom!
|
722
|
+
end
|
723
|
+
end
|
724
|
+
end
|
725
|
+
def test_assert_predicate
|
726
|
+
@tc.assert_predicate "", :empty?
|
727
|
+
end
|
728
|
+
|
729
|
+
def test_assert_predicate_triggered
|
730
|
+
assert_triggered 'Expected "blah" to be empty?.' do
|
731
|
+
@tc.assert_predicate "blah", :empty?
|
732
|
+
end
|
733
|
+
end
|
734
|
+
|
735
|
+
def test_assert_raises
|
736
|
+
@tc.assert_raises RuntimeError do
|
737
|
+
raise "blah"
|
738
|
+
end
|
739
|
+
end
|
740
|
+
|
741
|
+
def test_assert_raises_default
|
742
|
+
@tc.assert_raises do
|
743
|
+
raise StandardError, "blah"
|
744
|
+
end
|
745
|
+
end
|
746
|
+
|
747
|
+
def test_assert_raises_default_triggered
|
748
|
+
e = assert_raises Minitest::Assertion do
|
749
|
+
@tc.assert_raises do
|
750
|
+
raise SomeError, "blah"
|
751
|
+
end
|
752
|
+
end
|
753
|
+
|
754
|
+
expected = clean <<-EOM.chomp
|
755
|
+
[StandardError] exception expected, not
|
756
|
+
Class: <SomeError>
|
757
|
+
Message: <\"blah\">
|
758
|
+
---Backtrace---
|
759
|
+
FILE:LINE:in \`test_assert_raises_default_triggered\'
|
760
|
+
---------------
|
761
|
+
EOM
|
762
|
+
|
763
|
+
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
764
|
+
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
765
|
+
|
766
|
+
assert_equal expected, actual
|
767
|
+
end
|
768
|
+
|
769
|
+
def test_assert_raises_exit
|
770
|
+
@tc.assert_raises SystemExit do
|
771
|
+
exit 1
|
772
|
+
end
|
773
|
+
end
|
774
|
+
|
775
|
+
def test_assert_raises_module
|
776
|
+
@tc.assert_raises MyModule do
|
777
|
+
raise AnError
|
778
|
+
end
|
779
|
+
end
|
780
|
+
|
781
|
+
def test_assert_raises_signals
|
782
|
+
@tc.assert_raises SignalException do
|
783
|
+
raise SignalException, :INT
|
784
|
+
end
|
785
|
+
end
|
786
|
+
|
787
|
+
def test_assert_raises_throw_nested_bad
|
788
|
+
@assertion_count = 0
|
789
|
+
|
790
|
+
assert_unexpected "RuntimeError: boom!" do
|
791
|
+
@tc.assert_raises do
|
792
|
+
@tc.assert_throws :blah do
|
793
|
+
raise "boom!"
|
794
|
+
throw :not_blah
|
795
|
+
end
|
796
|
+
end
|
797
|
+
end
|
798
|
+
end
|
799
|
+
|
800
|
+
##
|
801
|
+
# *sigh* This is quite an odd scenario, but it is from real (albeit
|
802
|
+
# ugly) test code in ruby-core:
|
803
|
+
|
804
|
+
# http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
|
805
|
+
|
806
|
+
def test_assert_raises_skip
|
807
|
+
@assertion_count = 0
|
808
|
+
|
809
|
+
assert_triggered "skipped", Minitest::Skip do
|
810
|
+
@tc.assert_raises ArgumentError do
|
811
|
+
begin
|
812
|
+
raise "blah"
|
813
|
+
rescue
|
814
|
+
skip "skipped"
|
815
|
+
end
|
816
|
+
end
|
817
|
+
end
|
818
|
+
end
|
819
|
+
|
820
|
+
def test_assert_raises_subclass
|
821
|
+
@tc.assert_raises StandardError do
|
822
|
+
raise AnError
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
def test_assert_raises_subclass_triggered
|
827
|
+
e = assert_raises Minitest::Assertion do
|
828
|
+
@tc.assert_raises SomeError do
|
829
|
+
raise AnError, "some message"
|
830
|
+
end
|
831
|
+
end
|
832
|
+
|
833
|
+
expected = clean <<-EOM
|
834
|
+
[SomeError] exception expected, not
|
835
|
+
Class: <AnError>
|
836
|
+
Message: <\"some message\">
|
837
|
+
---Backtrace---
|
838
|
+
FILE:LINE:in \`test_assert_raises_subclass_triggered\'
|
839
|
+
---------------
|
840
|
+
EOM
|
841
|
+
|
842
|
+
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
843
|
+
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
844
|
+
|
845
|
+
assert_equal expected.chomp, actual
|
846
|
+
end
|
847
|
+
|
848
|
+
def test_assert_raises_triggered_different
|
849
|
+
e = assert_raises Minitest::Assertion do
|
850
|
+
@tc.assert_raises RuntimeError do
|
851
|
+
raise SyntaxError, "icky"
|
852
|
+
end
|
853
|
+
end
|
854
|
+
|
855
|
+
expected = clean <<-EOM.chomp
|
856
|
+
[RuntimeError] exception expected, not
|
857
|
+
Class: <SyntaxError>
|
858
|
+
Message: <\"icky\">
|
859
|
+
---Backtrace---
|
860
|
+
FILE:LINE:in \`test_assert_raises_triggered_different\'
|
861
|
+
---------------
|
862
|
+
EOM
|
863
|
+
|
864
|
+
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
865
|
+
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
866
|
+
|
867
|
+
assert_equal expected, actual
|
868
|
+
end
|
869
|
+
|
870
|
+
def test_assert_raises_triggered_different_msg
|
871
|
+
e = assert_raises Minitest::Assertion do
|
872
|
+
@tc.assert_raises RuntimeError, "XXX" do
|
873
|
+
raise SyntaxError, "icky"
|
874
|
+
end
|
875
|
+
end
|
876
|
+
|
877
|
+
expected = clean <<-EOM
|
878
|
+
XXX.
|
879
|
+
[RuntimeError] exception expected, not
|
880
|
+
Class: <SyntaxError>
|
881
|
+
Message: <\"icky\">
|
882
|
+
---Backtrace---
|
883
|
+
FILE:LINE:in \`test_assert_raises_triggered_different_msg\'
|
884
|
+
---------------
|
885
|
+
EOM
|
886
|
+
|
887
|
+
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
888
|
+
actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
|
889
|
+
|
890
|
+
assert_equal expected.chomp, actual
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_assert_raises_triggered_none
|
894
|
+
e = assert_raises Minitest::Assertion do
|
895
|
+
@tc.assert_raises Minitest::Assertion do
|
896
|
+
# do nothing
|
897
|
+
end
|
898
|
+
end
|
899
|
+
|
900
|
+
expected = "Minitest::Assertion expected but nothing was raised."
|
901
|
+
|
902
|
+
assert_equal expected, e.message
|
903
|
+
end
|
904
|
+
|
905
|
+
def test_assert_raises_triggered_none_msg
|
906
|
+
e = assert_raises Minitest::Assertion do
|
907
|
+
@tc.assert_raises Minitest::Assertion, "XXX" do
|
908
|
+
# do nothing
|
909
|
+
end
|
910
|
+
end
|
911
|
+
|
912
|
+
expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
|
913
|
+
|
914
|
+
assert_equal expected, e.message
|
915
|
+
end
|
916
|
+
|
917
|
+
def test_assert_raises_without_block
|
918
|
+
assert_triggered "assert_raises requires a block to capture errors." do
|
919
|
+
@tc.assert_raises StandardError
|
920
|
+
end
|
921
|
+
end
|
922
|
+
|
923
|
+
def test_assert_respond_to
|
924
|
+
@tc.assert_respond_to "blah", :empty?
|
925
|
+
end
|
926
|
+
|
927
|
+
def test_assert_respond_to_triggered
|
928
|
+
assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do
|
929
|
+
@tc.assert_respond_to "blah", :rawr!
|
930
|
+
end
|
931
|
+
end
|
932
|
+
|
933
|
+
def test_assert_same
|
934
|
+
@assertion_count = 3
|
935
|
+
|
936
|
+
o = "blah"
|
937
|
+
@tc.assert_same 1, 1
|
938
|
+
@tc.assert_same :blah, :blah
|
939
|
+
@tc.assert_same o, o
|
940
|
+
end
|
941
|
+
|
942
|
+
def test_assert_same_triggered
|
943
|
+
@assertion_count = 2
|
944
|
+
|
945
|
+
assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do
|
946
|
+
@tc.assert_same 1, 2
|
947
|
+
end
|
948
|
+
|
949
|
+
s1 = "blah"
|
950
|
+
s2 = "blah"
|
951
|
+
|
952
|
+
assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
|
953
|
+
@tc.assert_same s1, s2
|
954
|
+
end
|
955
|
+
end
|
956
|
+
|
957
|
+
def test_assert_send
|
958
|
+
assert_deprecated :assert_send do
|
959
|
+
@tc.assert_send [1, :<, 2]
|
960
|
+
end
|
961
|
+
end
|
962
|
+
|
963
|
+
def test_assert_send_bad
|
964
|
+
assert_deprecated :assert_send do
|
965
|
+
assert_triggered "Expected 1.>(*[2]) to return true." do
|
966
|
+
@tc.assert_send [1, :>, 2]
|
967
|
+
end
|
968
|
+
end
|
969
|
+
end
|
970
|
+
|
971
|
+
def test_assert_silent
|
972
|
+
@assertion_count = 2
|
973
|
+
|
974
|
+
@tc.assert_silent do
|
975
|
+
# do nothing
|
976
|
+
end
|
977
|
+
end
|
978
|
+
|
979
|
+
def test_assert_silent_triggered_err
|
980
|
+
assert_triggered util_msg("", "blah blah", "In stderr") do
|
981
|
+
@tc.assert_silent do
|
982
|
+
$stderr.print "blah blah"
|
983
|
+
end
|
984
|
+
end
|
985
|
+
end
|
986
|
+
|
987
|
+
def test_assert_silent_triggered_out
|
988
|
+
@assertion_count = 2
|
989
|
+
|
990
|
+
assert_triggered util_msg("", "blah blah", "In stdout") do
|
991
|
+
@tc.assert_silent do
|
992
|
+
print "blah blah"
|
993
|
+
end
|
994
|
+
end
|
995
|
+
end
|
996
|
+
|
997
|
+
def test_assert_throws
|
998
|
+
@tc.assert_throws :blah do
|
999
|
+
throw :blah
|
1000
|
+
end
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def test_assert_throws_argument_exception
|
1004
|
+
@assertion_count = 0
|
1005
|
+
|
1006
|
+
assert_unexpected "ArgumentError" do
|
1007
|
+
@tc.assert_throws :blah do
|
1008
|
+
raise ArgumentError
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def test_assert_throws_different
|
1014
|
+
assert_triggered "Expected :blah to have been thrown, not :not_blah." do
|
1015
|
+
@tc.assert_throws :blah do
|
1016
|
+
throw :not_blah
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
def test_assert_throws_name_error
|
1022
|
+
@assertion_count = 0
|
1023
|
+
|
1024
|
+
assert_unexpected "NameError" do
|
1025
|
+
@tc.assert_throws :blah do
|
1026
|
+
raise NameError
|
1027
|
+
end
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def test_assert_throws_unthrown
|
1032
|
+
assert_triggered "Expected :blah to have been thrown." do
|
1033
|
+
@tc.assert_throws :blah do
|
1034
|
+
# do nothing
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def test_assert_path_exists
|
1040
|
+
@tc.assert_path_exists __FILE__
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
def test_assert_path_exists_triggered
|
1044
|
+
assert_triggered "Expected path 'blah' to exist." do
|
1045
|
+
@tc.assert_path_exists "blah"
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def test_capture_io
|
1050
|
+
@assertion_count = 0
|
1051
|
+
|
1052
|
+
non_verbose do
|
1053
|
+
out, err = capture_io do
|
1054
|
+
puts "hi"
|
1055
|
+
$stderr.puts "bye!"
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
assert_equal "hi\n", out
|
1059
|
+
assert_equal "bye!\n", err
|
1060
|
+
end
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
def test_capture_subprocess_io
|
1064
|
+
@assertion_count = 0
|
1065
|
+
|
1066
|
+
non_verbose do
|
1067
|
+
out, err = capture_subprocess_io do
|
1068
|
+
system("echo hi")
|
1069
|
+
system("echo bye! 1>&2")
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
assert_equal "hi\n", out
|
1073
|
+
assert_equal "bye!", err.strip
|
1074
|
+
end
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
def test_class_asserts_match_refutes
|
1078
|
+
@assertion_count = 0
|
1079
|
+
|
1080
|
+
methods = Minitest::Assertions.public_instance_methods
|
1081
|
+
methods.map!(&:to_s) if Symbol === methods.first
|
1082
|
+
|
1083
|
+
# These don't have corresponding refutes _on purpose_. They're
|
1084
|
+
# useless and will never be added, so don't bother.
|
1085
|
+
ignores = %w[assert_output assert_raises assert_send
|
1086
|
+
assert_silent assert_throws assert_mock]
|
1087
|
+
|
1088
|
+
# These are test/unit methods. I'm not actually sure why they're still here
|
1089
|
+
ignores += %w[assert_no_match assert_not_equal assert_not_nil
|
1090
|
+
assert_not_same assert_nothing_raised
|
1091
|
+
assert_nothing_thrown assert_raise]
|
1092
|
+
|
1093
|
+
asserts = methods.grep(/^assert/).sort - ignores
|
1094
|
+
refutes = methods.grep(/^refute/).sort - ignores
|
1095
|
+
|
1096
|
+
assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts
|
1097
|
+
assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
def test_delta_consistency
|
1101
|
+
@assertion_count = 2
|
1102
|
+
|
1103
|
+
@tc.assert_in_delta 0, 1, 1
|
1104
|
+
|
1105
|
+
assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
|
1106
|
+
@tc.refute_in_delta 0, 1, 1
|
1107
|
+
end
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
def test_epsilon_consistency
|
1111
|
+
@assertion_count = 2
|
1112
|
+
|
1113
|
+
@tc.assert_in_epsilon 1.0, 1.001
|
1114
|
+
|
1115
|
+
msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
|
1116
|
+
assert_triggered msg do
|
1117
|
+
@tc.refute_in_epsilon 1.0, 1.001
|
1118
|
+
end
|
1119
|
+
end
|
1120
|
+
|
1121
|
+
def assert_fail_after t
|
1122
|
+
@tc.fail_after t.year, t.month, t.day, "remove the deprecations"
|
1123
|
+
end
|
1124
|
+
|
1125
|
+
def test_fail_after
|
1126
|
+
d0 = Time.now
|
1127
|
+
d1 = d0 + 86_400 # I am an idiot
|
1128
|
+
|
1129
|
+
assert_silent do
|
1130
|
+
assert_fail_after d1
|
1131
|
+
end
|
1132
|
+
|
1133
|
+
assert_triggered "remove the deprecations" do
|
1134
|
+
assert_fail_after d0
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
def test_flunk
|
1139
|
+
assert_triggered "Epic Fail!" do
|
1140
|
+
@tc.flunk
|
1141
|
+
end
|
1142
|
+
end
|
1143
|
+
|
1144
|
+
def test_flunk_message
|
1145
|
+
assert_triggered @zomg do
|
1146
|
+
@tc.flunk @zomg
|
1147
|
+
end
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
def test_pass
|
1151
|
+
@tc.pass
|
1152
|
+
end
|
1153
|
+
|
1154
|
+
def test_refute
|
1155
|
+
@assertion_count = 2
|
1156
|
+
|
1157
|
+
@tc.assert_equal true, @tc.refute(false), "returns true on success"
|
1158
|
+
end
|
1159
|
+
|
1160
|
+
def test_refute_empty
|
1161
|
+
@assertion_count = 2
|
1162
|
+
|
1163
|
+
@tc.refute_empty [1]
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
def test_refute_empty_triggered
|
1167
|
+
@assertion_count = 2
|
1168
|
+
|
1169
|
+
assert_triggered "Expected [] to not be empty." do
|
1170
|
+
@tc.refute_empty []
|
1171
|
+
end
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
def test_refute_equal
|
1175
|
+
@tc.refute_equal "blah", "yay"
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
def test_refute_equal_triggered
|
1179
|
+
assert_triggered 'Expected "blah" to not be equal to "blah".' do
|
1180
|
+
@tc.refute_equal "blah", "blah"
|
1181
|
+
end
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
def test_refute_in_delta
|
1185
|
+
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
def test_refute_in_delta_triggered
|
1189
|
+
x = "0.1"
|
1190
|
+
assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
|
1191
|
+
@tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
|
1192
|
+
end
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
def test_refute_in_epsilon
|
1196
|
+
@tc.refute_in_epsilon 10_000, 9990-1
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def test_refute_in_epsilon_triggered
|
1200
|
+
assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do
|
1201
|
+
@tc.refute_in_epsilon 10_000, 9990
|
1202
|
+
flunk
|
1203
|
+
end
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
def test_refute_includes
|
1207
|
+
@assertion_count = 2
|
1208
|
+
|
1209
|
+
@tc.refute_includes [true], false
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
def test_refute_includes_triggered
|
1213
|
+
@assertion_count = 3
|
1214
|
+
|
1215
|
+
e = @tc.assert_raises Minitest::Assertion do
|
1216
|
+
@tc.refute_includes [true], true
|
1217
|
+
end
|
1218
|
+
|
1219
|
+
expected = "Expected [true] to not include true."
|
1220
|
+
assert_equal expected, e.message
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
def test_refute_instance_of
|
1224
|
+
@tc.refute_instance_of Array, "blah"
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
def test_refute_instance_of_triggered
|
1228
|
+
assert_triggered 'Expected "blah" to not be an instance of String.' do
|
1229
|
+
@tc.refute_instance_of String, "blah"
|
1230
|
+
end
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
def test_refute_kind_of
|
1234
|
+
@tc.refute_kind_of Array, "blah"
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
def test_refute_kind_of_triggered
|
1238
|
+
assert_triggered 'Expected "blah" to not be a kind of String.' do
|
1239
|
+
@tc.refute_kind_of String, "blah"
|
1240
|
+
end
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
def test_refute_match
|
1244
|
+
@assertion_count = 2
|
1245
|
+
@tc.refute_match(/\d+/, "blah blah blah")
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
def test_refute_match_matcher_object
|
1249
|
+
@assertion_count = 2
|
1250
|
+
pattern = Object.new
|
1251
|
+
def pattern.=~ _; false end
|
1252
|
+
@tc.refute_match pattern, 5
|
1253
|
+
end
|
1254
|
+
|
1255
|
+
def test_refute_match_object_triggered
|
1256
|
+
@assertion_count = 2
|
1257
|
+
|
1258
|
+
pattern = Object.new
|
1259
|
+
def pattern.=~ _; true end
|
1260
|
+
def pattern.inspect; "[Object]" end
|
1261
|
+
|
1262
|
+
assert_triggered "Expected [Object] to not match 5." do
|
1263
|
+
@tc.refute_match pattern, 5
|
1264
|
+
end
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
def test_refute_match_triggered
|
1268
|
+
@assertion_count = 2
|
1269
|
+
assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
|
1270
|
+
@tc.refute_match(/\w+/, "blah blah blah")
|
1271
|
+
end
|
1272
|
+
end
|
1273
|
+
|
1274
|
+
def test_refute_nil
|
1275
|
+
@tc.refute_nil 42
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
def test_refute_nil_triggered
|
1279
|
+
assert_triggered "Expected nil to not be nil." do
|
1280
|
+
@tc.refute_nil nil
|
1281
|
+
end
|
1282
|
+
end
|
1283
|
+
|
1284
|
+
def test_refute_operator
|
1285
|
+
@tc.refute_operator 2, :<, 1
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
def test_refute_operator_bad_object
|
1289
|
+
bad = Object.new
|
1290
|
+
def bad.== _; true end
|
1291
|
+
|
1292
|
+
@tc.refute_operator true, :equal?, bad
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
def test_refute_operator_triggered
|
1296
|
+
assert_triggered "Expected 2 to not be > 1." do
|
1297
|
+
@tc.refute_operator 2, :>, 1
|
1298
|
+
end
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
def test_refute_predicate
|
1302
|
+
@tc.refute_predicate "42", :empty?
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
def test_refute_predicate_triggered
|
1306
|
+
assert_triggered 'Expected "" to not be empty?.' do
|
1307
|
+
@tc.refute_predicate "", :empty?
|
1308
|
+
end
|
1309
|
+
end
|
1310
|
+
|
1311
|
+
def test_refute_respond_to
|
1312
|
+
@tc.refute_respond_to "blah", :rawr!
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
def test_refute_respond_to_triggered
|
1316
|
+
assert_triggered 'Expected "blah" to not respond to empty?.' do
|
1317
|
+
@tc.refute_respond_to "blah", :empty?
|
1318
|
+
end
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
def test_refute_same
|
1322
|
+
@tc.refute_same 1, 2
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
def test_refute_same_triggered
|
1326
|
+
assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
1327
|
+
@tc.refute_same 1, 1
|
1328
|
+
end
|
1329
|
+
end
|
1330
|
+
|
1331
|
+
def test_refute_path_exists
|
1332
|
+
@tc.refute_path_exists "blah"
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
def test_refute_path_exists_triggered
|
1336
|
+
assert_triggered "Expected path '#{__FILE__}' to not exist." do
|
1337
|
+
@tc.refute_path_exists __FILE__
|
1338
|
+
end
|
1339
|
+
end
|
1340
|
+
|
1341
|
+
def test_skip
|
1342
|
+
@assertion_count = 0
|
1343
|
+
|
1344
|
+
assert_triggered "haha!", Minitest::Skip do
|
1345
|
+
@tc.skip "haha!"
|
1346
|
+
end
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
def assert_skip_until t, msg
|
1350
|
+
@tc.skip_until t.year, t.month, t.day, msg
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
def test_skip_until
|
1354
|
+
@assertion_count = 0
|
1355
|
+
|
1356
|
+
d0 = Time.now
|
1357
|
+
d1 = d0 + 86_400 # I am an idiot
|
1358
|
+
|
1359
|
+
assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
|
1360
|
+
assert_skip_until d0, "not yet"
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
assert_triggered "not ready yet", Minitest::Skip do
|
1364
|
+
assert_skip_until d1, "not ready yet"
|
1365
|
+
end
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
def util_msg exp, act, msg = nil
|
1369
|
+
s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
|
1370
|
+
s = "#{msg}.\n#{s}" if msg
|
1371
|
+
s
|
1372
|
+
end
|
1373
|
+
|
1374
|
+
def without_diff
|
1375
|
+
old_diff = Minitest::Assertions.diff
|
1376
|
+
Minitest::Assertions.diff = nil
|
1377
|
+
|
1378
|
+
yield
|
1379
|
+
ensure
|
1380
|
+
Minitest::Assertions.diff = old_diff
|
1381
|
+
end
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
class TestMinitestAssertionHelpers < Minitest::Test
|
1385
|
+
def assert_mu_pp exp, input, raw = false
|
1386
|
+
act = mu_pp input
|
1387
|
+
|
1388
|
+
if String === input && !raw then
|
1389
|
+
assert_equal "\"#{exp}\"", act
|
1390
|
+
else
|
1391
|
+
assert_equal exp, act
|
1392
|
+
end
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
def assert_mu_pp_for_diff exp, input, raw = false
|
1396
|
+
act = mu_pp_for_diff input
|
1397
|
+
|
1398
|
+
if String === input && !raw then
|
1399
|
+
assert_equal "\"#{exp}\"", act
|
1400
|
+
else
|
1401
|
+
assert_equal exp, act
|
1402
|
+
end
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
def test_diff_equal
|
1406
|
+
msg = "No visible difference in the String#inspect output.
|
1407
|
+
You should look at the implementation of #== on String or its members.
|
1408
|
+
\"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
|
1409
|
+
|
1410
|
+
o1 = "blah" * 10
|
1411
|
+
o2 = "blah" * 10
|
1412
|
+
def o1.== _
|
1413
|
+
false
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
assert_equal msg, diff(o1, o2)
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
def test_diff_str_mixed
|
1420
|
+
msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
|
1421
|
+
--- expected
|
1422
|
+
+++ actual
|
1423
|
+
@@ -1 +1 @@
|
1424
|
+
-"A\\n\nB"
|
1425
|
+
+"A\n\\nB"
|
1426
|
+
EOM
|
1427
|
+
|
1428
|
+
exp = "A\\n\nB"
|
1429
|
+
act = "A\n\\nB"
|
1430
|
+
|
1431
|
+
assert_equal msg, diff(exp, act)
|
1432
|
+
end
|
1433
|
+
|
1434
|
+
def test_diff_str_multiline
|
1435
|
+
msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
|
1436
|
+
--- expected
|
1437
|
+
+++ actual
|
1438
|
+
@@ -1,2 +1,2 @@
|
1439
|
+
"A
|
1440
|
+
-B"
|
1441
|
+
+C"
|
1442
|
+
EOM
|
1443
|
+
|
1444
|
+
exp = "A\nB"
|
1445
|
+
act = "A\nC"
|
1446
|
+
|
1447
|
+
assert_equal msg, diff(exp, act)
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
def test_diff_str_simple
|
1451
|
+
msg = <<-'EOM'.gsub(/^ {10}/, "").chomp # NOTE single quotes on heredoc
|
1452
|
+
Expected: "A"
|
1453
|
+
Actual: "B"
|
1454
|
+
EOM
|
1455
|
+
|
1456
|
+
exp = "A"
|
1457
|
+
act = "B"
|
1458
|
+
|
1459
|
+
assert_equal msg, diff(exp, act)
|
1460
|
+
end
|
1461
|
+
|
1462
|
+
def test_message
|
1463
|
+
assert_equal "blah2.", message { "blah2" }.call
|
1464
|
+
assert_equal "blah2.", message("") { "blah2" }.call
|
1465
|
+
assert_equal "blah1.\nblah2.", message(:blah1) { "blah2" }.call
|
1466
|
+
assert_equal "blah1.\nblah2.", message("blah1") { "blah2" }.call
|
1467
|
+
|
1468
|
+
message = proc { "blah1" }
|
1469
|
+
assert_equal "blah1.\nblah2.", message(message) { "blah2" }.call
|
1470
|
+
|
1471
|
+
message = message { "blah1" }
|
1472
|
+
assert_equal "blah1.\nblah2.", message(message) { "blah2" }.call
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
def test_message_deferred
|
1476
|
+
var = nil
|
1477
|
+
|
1478
|
+
msg = message { var = "blah" }
|
1479
|
+
|
1480
|
+
assert_nil var
|
1481
|
+
|
1482
|
+
msg.call
|
1483
|
+
|
1484
|
+
assert_equal "blah", var
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
def test_mu_pp
|
1488
|
+
assert_mu_pp 42.inspect, 42
|
1489
|
+
assert_mu_pp %w[a b c].inspect, %w[a b c]
|
1490
|
+
assert_mu_pp "A B", "A B"
|
1491
|
+
assert_mu_pp "A\\nB", "A\nB"
|
1492
|
+
assert_mu_pp "A\\\\nB", 'A\nB' # notice single quotes
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
def test_mu_pp_for_diff
|
1496
|
+
assert_mu_pp_for_diff "#<Object:0xXXXXXX>", Object.new
|
1497
|
+
assert_mu_pp_for_diff "A B", "A B"
|
1498
|
+
assert_mu_pp_for_diff [1, 2, 3].inspect, [1, 2, 3]
|
1499
|
+
assert_mu_pp_for_diff "A\nB", "A\nB"
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
def test_mu_pp_for_diff_str_bad_encoding
|
1503
|
+
str = "\666".force_encoding Encoding::UTF_8
|
1504
|
+
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
1505
|
+
|
1506
|
+
assert_mu_pp_for_diff exp, str, :raw
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
def test_mu_pp_for_diff_str_bad_encoding_both
|
1510
|
+
str = "\666A\\n\nB".force_encoding Encoding::UTF_8
|
1511
|
+
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
|
1512
|
+
|
1513
|
+
assert_mu_pp_for_diff exp, str, :raw
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
def test_mu_pp_for_diff_str_encoding
|
1517
|
+
str = "A\nB".b
|
1518
|
+
exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\nB\""
|
1519
|
+
|
1520
|
+
assert_mu_pp_for_diff exp, str, :raw
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
def test_mu_pp_for_diff_str_encoding_both
|
1524
|
+
str = "A\\n\nB".b
|
1525
|
+
exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\\\\n\\nB\""
|
1526
|
+
|
1527
|
+
assert_mu_pp_for_diff exp, str, :raw
|
1528
|
+
end
|
1529
|
+
|
1530
|
+
def test_mu_pp_for_diff_str_nerd
|
1531
|
+
assert_mu_pp_for_diff "A\\nB\\\\nC", "A\nB\\nC"
|
1532
|
+
assert_mu_pp_for_diff "\\nB\\\\nC", "\nB\\nC"
|
1533
|
+
assert_mu_pp_for_diff "\\nB\\\\n", "\nB\\n"
|
1534
|
+
assert_mu_pp_for_diff "\\n\\\\n", "\n\\n"
|
1535
|
+
assert_mu_pp_for_diff "\\\\n\\n", "\\n\n"
|
1536
|
+
assert_mu_pp_for_diff "\\\\nB\\n", "\\nB\n"
|
1537
|
+
assert_mu_pp_for_diff "\\\\nB\\nC", "\\nB\nC"
|
1538
|
+
assert_mu_pp_for_diff "A\\\\n\\nB", "A\\n\nB"
|
1539
|
+
assert_mu_pp_for_diff "A\\n\\\\nB", "A\n\\nB"
|
1540
|
+
assert_mu_pp_for_diff "\\\\n\\n", "\\n\n"
|
1541
|
+
assert_mu_pp_for_diff "\\n\\\\n", "\n\\n"
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
def test_mu_pp_for_diff_str_normal
|
1545
|
+
assert_mu_pp_for_diff "", ""
|
1546
|
+
assert_mu_pp_for_diff "A\\n\n", "A\\n"
|
1547
|
+
assert_mu_pp_for_diff "A\\n\nB", "A\\nB"
|
1548
|
+
assert_mu_pp_for_diff "A\n", "A\n"
|
1549
|
+
assert_mu_pp_for_diff "A\nB", "A\nB"
|
1550
|
+
assert_mu_pp_for_diff "\\n\n", "\\n"
|
1551
|
+
assert_mu_pp_for_diff "\n", "\n"
|
1552
|
+
assert_mu_pp_for_diff "\\n\nA", "\\nA"
|
1553
|
+
assert_mu_pp_for_diff "\nA", "\nA"
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
def test_mu_pp_str_bad_encoding
|
1557
|
+
str = "\666".force_encoding Encoding::UTF_8
|
1558
|
+
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
1559
|
+
|
1560
|
+
assert_mu_pp exp, str, :raw
|
1561
|
+
end
|
1562
|
+
|
1563
|
+
def test_mu_pp_str_encoding
|
1564
|
+
str = "A\nB".b
|
1565
|
+
exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\\nB\""
|
1566
|
+
|
1567
|
+
assert_mu_pp exp, str, :raw
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
def test_mu_pp_str_immutable
|
1571
|
+
printer = Class.new { extend Minitest::Assertions }
|
1572
|
+
str = "test".freeze
|
1573
|
+
assert_equal '"test"', printer.mu_pp(str)
|
1574
|
+
end
|
1575
|
+
end
|