require 'test/unit' require 'rscm/tempdir' require 'rscm/command_line' module RSCM class DifftoolTest < Test::Unit::TestCase def setup @dir = RSCM.new_temp_dir("test_should_write_to_stdout") @stdout = "#{@dir}/stdout" @stderr = "#{@dir}/stderr" @prompt = "#{File.expand_path(@dir)} #{Platform.user}$" File.delete @stdout if File.exist? @stdout File.delete @stderr if File.exist? @stderr end def test_should_write_to_both_when_both_streams_specified_and_no_block CommandLine.execute("echo \" @dir, :stdout => @stdout, :stderr => @stderr}) assert_equal("#{@prompt} echo \" @dir, :stderr => @stderr}) assert(!File.exist?(@stdout)) assert_equal("#{@prompt} echo hello\n", File.open(@stderr).read) end def test_should_only_write_command_to_stdout_when_block_specified CommandLine.execute("echo hello", {:dir => @dir, :stdout => @stdout, :stderr => @stderr}) do |io| assert_equal("hello\n", io.read) end assert_equal("#{@prompt} echo hello\n[output captured and therefore not logged]\n", File.open(@stdout).read) assert_equal("#{@prompt} echo hello\n", File.open(@stderr).read) end end end