# Test::Unit

**URL:** <https://www.ruby-forum.com/t/test-unit/109460>\
**Category:** Ruby\
**Created:** [July 15, 2007, 8:01am UTC](https://www.ruby-forum.com/t/test-unit/109460 "2007-07-15T08:01:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xml-dealer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/9dc877/32.png) [@xml-dealer](https://www.ruby-forum.com/u/xml-dealer)\
**Post date:** [July 15, 2007, 8:01am UTC](https://www.ruby-forum.com/t/test-unit/109460/1 "2007-07-15T08:01:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xml-dealer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/9dc877/32.png) [@xml-dealer](https://www.ruby-forum.com/u/xml-dealer)\
**Post date:** [July 15, 2007, 8:27am UTC](https://www.ruby-forum.com/t/test-unit/109460/2 "2007-07-15T08:27:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xml-dealer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/9dc877/32.png) [@xml-dealer](https://www.ruby-forum.com/u/xml-dealer)\
**Post date:** [July 15, 2007, 10:17am UTC](https://www.ruby-forum.com/t/test-unit/109460/3 "2007-07-15T10:17:15Z")

</div>

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:

1. 

a.to\_a.last # in testcase

1. 

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

---

<div class="post-metadata">

**Author:** ![xml-dealer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/9dc877/32.png) [@xml-dealer](https://www.ruby-forum.com/u/xml-dealer)\
**Post date:** [July 15, 2007, 10:20am UTC](https://www.ruby-forum.com/t/test-unit/109460/4 "2007-07-15T10:20:27Z")

</div>

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$/\>
