From: Justin Collins Date: 2010-02-12T02:48:03+09:00 Subject: Re: Test script Antoine Makhassak wrote: > Richard Conroy wrote: > >> What you are attempting to do here is an acceptance test, not a unit >> test. >> Test::Unit will facilitate both in this case. >> >> What you want to do is call your program from the shell, with all of the >> correct >> arguments, and assert that your program gives the correct output. >> >> THen do it again with random or incorrect arguments and verify that your >> program gives the correct error response or exit code. >> >> You will also need to verify the programs side effects. (Any files that >> it >> creates, >> deletes or touches), >> > > > > Yes I know, but I need to call my program with different arguments > "automatically" i.e. I do not want to manually launch my program for > each test. Can you tell me pls exactly what to enter in my .rb source > file or a shell script / batch file so that it automatically makes the > calls and outputs the results? > Thank you > You can use backticks (``) to call your program and return the output as a string. You can use $?.exitstatus to see if it exited with an error. You can also use string interpolation for arguments. For example: irb(main):001:0> `echo hello` => "hello\n" irb(main):002:0> $?.exitstatus => 0 irb(main):003:0> world = "world" => "world" irb(main):004:0> `echo #{world}` => "world\n" -Justin