Files
klayout/testdata/vendor/ruby/test/unit/util/output.rb
T
Matthias Koefferlein 585d0941bb RBA Unit test enhancements
- Include a copy of the unit test framework so we're no longer
  depending on incompatible versions for Ruby 1 and 2.
- Avoid duplication of path entries in unit tests
2017-07-23 23:03:21 +02:00

32 lines
741 B
Ruby

module Test
module Unit
module Util
module Output
##
# Returns output for standard output and standard
# error as string.
#
# Example:
# capture_output do
# puts("stdout")
# warn("stderr")
# end # -> ["stdout\n", "stderr\n"]
def capture_output
require 'stringio'
output = StringIO.new
error = StringIO.new
stdout_save, stderr_save = $stdout, $stderr
$stdout, $stderr = output, error
begin
yield
[output.string, error.string]
ensure
$stdout, $stderr = stdout_save, stderr_save
end
end
end
end
end
end