Test::Unit


#1

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 =~
    </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


#2

Helmut Hagemann wrote:

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

The question
Why all stdout announcement stored.
can I delete these announcements and only one message spend

I’m not sure what you are asking. If you want to know why it is failing,
it looks like it’s because of the extra ‘y’ in “okayy” on line 28.

If you want to get only the last line of the stdout, you could do
a.split("\n").last but I can’t think of a way to only get the last
‘message’.

Hope this helps at all

Dan


#3

Helmut Hagemann schrieb:

end
$stdout.flush
if str.size<=5
end
require “test/unit”
assert_equal(255,$?.exitstatus )
end

  1. Failure:
    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:

a.to_a.last # in testcase

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


#4

with the double y is specially over indicate permit like the data look
this is only one sample program around to be shown like the data to be
collected if to test the program to indicate much for the user has
becomes this data set difficult to understand

I seek to evaluate solution around only the last expenditure

example

</^check okay$/>