From: "Florian Aßmann" Date: 2007-07-15T17:16:44+09:00 Subject: Re: Test::Unit Helmut Hagemann schrieb: > Hello Ruby fan > That is first time which I into forum > A question places a test environment for a program must provide > Here is program now test the program > > #!/usr/bin/env ruby > > class MYAPPException < Exception > end > class MYAPPGood < Exception > end > > > class Test > def initialize( arg) > begin > $stdout.print "\nProgram 1 check Argument size from #{arg}" > check(arg) > > rescue MYAPPException =>str > $stdout.print "\nException output" > $stdout.flush > $stdout.print "\nError : #{arg} ",$! > > exit(-1) > else > > exit(0) > end > end > def check(str) > $stdout.print "\nin check Method #{str.to_s.size} #{str.class}" > if str.size<=5 > $stdout.print "\ncheck to short" > raise MYAPPException,"Input to short" > end > if str.size >=10 > $stdout.print "\ncheck to long" > raise MYAPPException,"Input to long" > end > $stdout.print "\nresult : ",str > $stdout.print "\ncheck okay" > end > end > if __FILE__ == $0 > t=Test.new(ARGV[0]) > end > > > In the case I have to indicate specially an error to 4 > > #!/usr/bin/env ruby > #require "program1.rb" > > require "test/unit" > > class Cmdline_Tests < Test::Unit::TestCase > > def test_Progam1 > #No.1 > a = %x[ruby Program1.rb 123] > assert_equal(255,$?.exitstatus ) > assert_match(/Input to short$/,a) > #No.2 > a = %x[ruby Program1.rb 1234567890] > assert_equal(255,$?.exitstatus ) > assert_match(/Input to long$/,a) > #No.3 > a = %x[ruby Program1.rb 1234567] > assert_equal(0,$?.exitstatus ) > assert_match(/check okay$/,a) > #No.4 > a = %x[ruby Program1.rb 1234567] > assert_equal(0,$?.exitstatus ) > assert_match(/check okayy$/,a) > end > end > > inserted around my question clearly > > > G:\edi>ruby TestProgram1.rb > Loaded suite TestProgram1 > Started > F > Finished in 0.469 seconds. > > 1) Failure: > test_Progam1(Cmdline_Tests) [TestProgram1.rb:28]: > <"\nProgram 1 check Argument size from 1234567\nin check Method 7 > String\nresult > : 1234567\ncheck okay"> expected to be =~ > . > > 1 tests, 8 assertions, 1 failures, 0 errors > > > > The question > Why all stdout announcement stored. > can I delete these announcements and only one message spend > Hi Helmut, I have several ways to accomplish this in mind: 1. a.to_a.last # in testcase 2. use popen and test the complete output, that would fit better in this case, imho: asserts = ['Integer'] IO.popen "ruby -e 'puts Integer.name; exit 0'" do |pipe| assert_equal(asserts.shift, pipe.readline.chomp) until asserts.empty? end assert($?.success?) Regards Florian