Question: Create a Bash script called runSuite.sh that is invoked as follows: ./runSuite.sh suite-file program The argument suite-file is the name of a file containing a

Create a Bash script called runSuite.sh that is invoked as follows:
./runSuite.sh suite-file program
The argument suite-file is the name of a file containing a list of filename stems and the argument program is the name of the program to be run. It is assumed that both arguments represent valid readable files and that the second argument is a program that is executable. If an incorrect number of arguments is provided, the script responds with an appropriate error message on the error stream and exits with a non-zero exit code.
In summary, the runSuite.sh script runs program on each test in the test suite (as specified by suite-file) and reports on any tests whose output does not match the expected output. No output is generated for tests that pass.
The file suite-file contains a list of stems, from which we construct the names of files containing the command line arguments, input and expected output of each test. Stems will not contain spaces. For example, suppose our suite file is called suite.txt and contains the following entries:
test1 test2
reallyBigTest
Then our test suite consists of three tests. The first one (test1) will use the optional file test1.args to hold its command line arguments, the optional file test1.in to hold input to be read from stdin and the required file test1.expect to hold its expected output. The second one (test2) will use the optional file test2.args to hold its command line arguments, the optional file test2.in to hold input to be read from stdin and the required file test2.expect to hold its expected output. The last one (reallyBigTest) will use the optional file reallyBigTest.args to hold its command line arguments, the optional file reallyBigTest.in to hold input to be read from stdin and the required file reallyBigTest.expect to hold its expected output.
A sample run of runSuite.sh would be as follows:
./runSuite.sh suite.txt ./myprogram
The script will then run ./myprogram three times, once for each test specified in suite.txt:
The first time, it will run ./myprogram with command line arguments provided to the program from test1.args and input redirected from test1.in. The results, captured from standard output, will be directed to a temporary file and then compared with test1.expect.
The second time, it will run ./myprogram with command line arguments provided to the program from test2.args and input redirected from test2.in. The results, captured from standard output, will be directed to a temporary file and then compared with test2.expect.
The third time, it will run ./myprogram with command line arguments provided to the program from reallyBigTest.args and input redirected from reallyBigTest.in. The results, captured from standard output, will be directed to a temporary file and then compared with reallyBigTest.expect.
Recall that for any test, the args and in files are optional. If the test suite contains a stem but a corresponding args file does not exist or is not readable, then that test is run without any command line arguments. If the test suite contains a stem but a corresponding in file does not exist or is not readable, then that test is run without any input redirected from stdin. If the test suite contains a stem but corresponding args and in files do not exist or are not readable, then that test is run without any command line arguments or any input redirected from stdin.
When the script is about to run a test but the required expect file does not exist or is not readable, the script should produce an appropriate error message on the error stream and exit with a non-zero exit code
If the output of a given test case differs from the expected output, print the following to standard output (assuming test test2 failed):
Test failed: test2
Args:
(contents of test2.args, if it exists and is readable)
Input:
(contents of test2.in, if it exists and is readable)
Expected:
(contents of test2.expect)
Actual:
(contents of the actual program output)
with the (contents ...) lines replaced with actual file contents, as described. The literal output Args: and Input: should appear, even if the corresponding files do not exist. For further clarity, the following output would be produced if test2.args and test2.in did not exist or were unreadable:
Test failed: test2
Args:
Input:
Expected:
(contents of test2.expect)
Actual:
(contents of the actual program output)
Follow these output specifications very carefully. You will fail most tests if your output does not match the specification.
Note 1: To create a temporary file, you must use the mktemp command to avoid filename duplication. Use the following code:
TEMPFILE=$(mktemp)
After the above command runs, $TEMPFILE contains the name of a file that you can use. In the Linux Student Environment, the mktemp command defaults to creating the temporary file at the absolute path /tmp/ which is great because then the file will not clutter our working directory. You must still ensure that you delete any temporary files that you might have created:
rm $TEMPFILE
Note 2: Do not attempt to compare outputs by storing them in shell variable and then using string comparisons. This does not scale well to programs that produce large outputs. Instead, use the diff command to determine if there are differences between the expected and actual output. When two files are compared with diff the status code is 0 if no differences are found and non-zero if there are differences.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!