Test::Unit

H

Helmut Hagemann

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
 
D

Daniel Lucraft

Helmut said:
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
 
F

Florian Aßmann

Helmut said:
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
=20
#!/usr/bin/env ruby
=20
class MYAPPException < Exception
end
class MYAPPGood < Exception
end
=20
=20
class Test
def initialize( arg)
begin
$stdout.print "\nProgram 1 check Argument size from #{arg}"=
check(arg)
=20
rescue MYAPPException =3D>str
$stdout.print "\nException output"
$stdout.flush
$stdout.print "\nError : #{arg} ",$!
=20
exit(-1)
else
=20
exit(0)
end
end
def check(str)
$stdout.print "\nin check Method #{str.to_s.size} #{str.class}"=
if str.size<=3D5
$stdout.print "\ncheck to short"
raise MYAPPException,"Input to short"
end
if str.size >=3D10
$stdout.print "\ncheck to long"
raise MYAPPException,"Input to long"
end
$stdout.print "\nresult : ",str
$stdout.print "\ncheck okay"
end
end
if __FILE__ =3D=3D $0
t=3DTest.new(ARGV[0])
end
=20
=20
In the case I have to indicate specially an error to 4
=20
#!/usr/bin/env ruby
#require "program1.rb"
=20
require "test/unit"
=20
class Cmdline_Tests < Test::Unit::TestCase
=20
def test_Progam1
#No.1
a =3D %x[ruby Program1.rb 123]
assert_equal(255,$?.exitstatus )
assert_match(/Input to short$/,a)
#No.2
a =3D %x[ruby Program1.rb 1234567890]
assert_equal(255,$?.exitstatus )
assert_match(/Input to long$/,a)
#No.3
a =3D %x[ruby Program1.rb 1234567]
assert_equal(0,$?.exitstatus )
assert_match(/check okay$/,a)
#No.4
a =3D %x[ruby Program1.rb 1234567]
assert_equal(0,$?.exitstatus )
assert_match(/check okayy$/,a)
end
end
=20
inserted around my question clearly
=20
=20
G:\edi>ruby TestProgram1.rb
Loaded suite TestProgram1
Started
F
Finished in 0.469 seconds.
=20
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 =3D~
</check okayy$/>.
=20
1 tests, 8 assertions, 1 failures, 0 errors
=20
=20
=20
The question
Why all stdout announcement stored.
can I delete these announcements and only one message spend
=20

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 =3D ['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
 
H

Helmut Hagemann

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top