On Fri, January 15, 2010 1:11 am, Christopher Howard wrote:
> My bash skills are a little weak. Okay, they are pretty much
> non-existent past the common one-liners I use every day. So I would
> appreciate any general suggestions or code:
>
> Basic idea: I'm writing some tests for my Java class to make sure that,
> as I continue to develop the codebase, my methods are still giving the
> output I expect. So I want to write a bash script that executes a test
> class, and then compares STDOUT to the contents of a file (which
> contains the output I expect). If the two are exactly the same, then
> script moves on to the next test, otherwise echoes a failure message and
> dies with a bad return value.
>
> Like so
>
> #
> # ... compiles all the code ...
> # ... I can write that part ...
> #
>
> # execute java test program
> java -cp ".;../" TestMyClass
>
> # then compare STDOUT of previous cmd
> # to contents of file TestMyClass.dat
>
> # If contents are different then
> echo "TestMyClass failed!"
> # then die with bad return value
>
> # If contents are the same
> # continue script...
This is not difficult. First, redirect output to a file:
java -cp ".;../" TestMyClass >MyClass.out
Then, use diff(1) to do the comparison:
diff MyClass.expected MyClass.out
I won't spoil the fun by quoting the man page here. :)
-- Bryan Medsker bryanm@acsalaska.net --------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.Received on Fri Jan 15 02:51:16 2010
This archive was generated by hypermail 2.1.8 : Fri Jan 15 2010 - 02:51:16 AKST