lib/minitest/silence_plugin.rb in minitest-silence-0.1.0 vs lib/minitest/silence_plugin.rb in minitest-silence-0.2.0
- old
+ new
@@ -13,24 +13,33 @@
module ResultOutputPatch
attr_accessor :output
end
module RunOneMethodPatch
+ attr_reader :original_stdin, :original_stdout, :original_stderr
+
+ def __run(*)
+ @original_stdin = $stdin.dup
+ @original_stdout = $stdout.dup
+ @original_stderr = $stderr.dup
+ super
+ end
+
def run_one_method(klass, method_name)
output_reader, output_writer = IO.pipe
output_thread = Thread.new { output_reader.read }
- old_stdout = $stdout.dup
- old_stderr = $stderr.dup
-
result = begin
$stdout.reopen(output_writer)
$stderr.reopen(output_writer)
+ $stdin.reopen(File::NULL)
+
super
ensure
- $stdout.reopen(old_stdout)
- $stderr.reopen(old_stderr)
+ $stdout.reopen(original_stdout)
+ $stderr.reopen(original_stderr)
+ $stdin.reopen(original_stdin)
output_writer.close
end
result.output = output_thread.value
result
@@ -46,24 +55,29 @@
end
end
class << self
def plugin_silence_options(opts, options)
+ opts.on('--disable-silence', "Do not rebind standard IO") do
+ options[:disable_silence] = true
+ end
opts.on('--fail-on-output', "Fail a test when it writes to STDOUT or STDERR") do
options[:fail_on_output] = true
end
end
def plugin_silence_init(options)
- Minitest::Result.prepend(Minitest::Silence::ResultOutputPatch)
- Minitest.singleton_class.prepend(Minitest::Silence::RunOneMethodPatch)
+ unless options[:disable_silence]
+ Minitest::Result.prepend(Minitest::Silence::ResultOutputPatch)
+ Minitest.singleton_class.prepend(Minitest::Silence::RunOneMethodPatch)
- if options[:fail_on_output]
- # We have to make sure this reporter runs as the first reporter, so it can still adjust
- # the result and other reporters will take the change into account.
- reporter.reporters.unshift(Minitest::Silence::FailOnOutputReporter.new(options[:io], options))
- elsif options[:verbose]
- reporter << Minitest::Silence::BoxedOutputReporter.new(options[:io], options)
+ if options[:fail_on_output]
+ # We have to make sure this reporter runs as the first reporter, so it can still adjust
+ # the result and other reporters will take the change into account.
+ reporter.reporters.unshift(Minitest::Silence::FailOnOutputReporter.new(options[:io], options))
+ elsif options[:verbose]
+ reporter << Minitest::Silence::BoxedOutputReporter.new(options[:io], options)
+ end
end
end
end
end