Beginner Help

I need to write a script to test a nsort c program. I have written 8 .txt files with different cases. Also 8 .txt files with expected outcome. The shell I have written always "test pass" for the first case but always "fail" for the rest... Here is a portion of my code (as I still don't know how to cut more than what's on the screen :frowning:

#!/bin/sh

#
# test whether the nsort program is working alright
#
echo "Testing NSort..."
# run the output of our program
./nsort t1.txt > /tmp/test-A.$$

if
        # use the diff(1) program to compare and see if
        # there are any problems
        diff -q /tmp/test-A.$$ t1a.txt
then
        echo "TESTCASE: t1a - PASS"
else
        echo "TESTCASE: T1A - FAIL"
fi

rm -f /tmp/test-A.$$

# run the output of our program
./nsort t2.txt > /tmp/test-B.$$

if
        # use the diff(1) program to compare and see if
        # there are any problems
        diff -q /tmp/test-B.$$ t2a.txt
then
        echo "TESTCASE: t2a - PASS"
else
        echo "TESTCASE: t2a - FAIL"
fi

rm -f /tmp/test-B.$$

# run the output of our program
./nsort t3.txt > /tmp/test-C.$$

if
        # use the diff(1) program to compare and see if
        # there are any problems
        diff -q /tmp/test-C.$$ t3a.txt
then
        echo "TESTCASE: t3a - PASS"

BLA BLA BLA................. this continues til test 8...

Am I doing something wrong?

Yes, you repeat yourself 8 times :wink:
Write only one function and call that function for each file. Basically should look like:

#!/bin/sh -x
#---------------
my_function()
{
    echo $1
}
#---------------
for i in a b c d
do
    my_function $i
done

Good point... but the fact is that the function returns a fail when it should pass... could you look at the code to see if something's wrong in the actual function?

Is this homework? Other than that, did you verify that, in fact, the program output and your verification file do not differ?

Yes it is homework...

I did verify the program output and the expected output file... the tests should all pass but the only one that does is the first one... does it have something to do with the tmp file that i make and delete? I know it may seem simple but this is my first time programming in c or shell... i've only done 1 yr in java...

---------- Post updated at 06:02 PM ---------- Previous update was at 05:55 PM ----------

I just tried switching the first and second tests so now my first test passes and second fail so it has nothing to do with the tmp files... the test that passes has no items to sort if that helps you...

I'm sorry, but I'll have to close this thread down. There is a special forum for posting homework, as well as special rules.