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.
- 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 =~
</check okayy$/>.
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