======================= CST8129 Lab Exercise #9 (Week 12) ======================= -IAN! idallen@ncf.ca Due: demo in lab period only - no hand in Marks: 3% Late penalty: 100% after last lab on Friday this week. Purpose: - review some of the work done so far (Chapter 2,3) Demo procedure: When you are ready to demonstrate your work, put your name on the board at the front of the room under the column "first demo; section 01x". If there is time, I will see re-demos of the same work. Put your name on the board under "second demo". (Note: There may not be time for a second demo; make the first demo good.) Priority is given to people who are registered in a given lab section. If you are trying to give a demo in a section that is not your registered lab section, you must wait until after all the registered students have done their demos and have had their questions answered. Put your name on the board under "other sections demo". -------------------------------------------------------------------------- Instructions for your demo: Copy the script template "tester.sh" from the Notes area of the course home page. This script is partially written for you. The "tester" script expects one argument that is the name of another script to execute. The argument script should be a script similar to the 12_optional_arguments_demo.sh script you wrote for Lab Exercise #6. The "tester" script will automatically execute the argument script and test each output to make sure it is correct, using regular expressions in "egrep" to look for correct patterns in the output. If the correct output cannot be found, the "tester" script will tell you. When you finish modifying the "tester" script, it will call the argument script with zero, one, two, and three arguments, and make sure that the correct output is generated for all these inputs. Read the comments in this "tester.sh" script. Locate the "FIXME" places that need fixing, and do what is required to make the script perform all four tests on 12_optional_arguments_demo.sh. (The first test is already written for you - you only have to finish the other three.) Demo: When you have finished modifying the "tester" script, call over your instructor to demonstrate it working. You might try using the "tester" script on your own copy of 12_optional_arguments_demo.sh and on the copy here: ~alleni/cst/notes/12_optional_arguments_demo.sh.txt $ ./tester.sh ./12_optional_arguments_demo.sh ...your output here... $ ./tester.sh ~alleni/cst/notes/12_optional_arguments_demo.sh.txt ...your output here... Note: You may need to put "./" in front of a script name argument if it is in the current directory, unless your PATH statement inside tester.sh lets the shell look for commands in the current directory. (You could also have the script automatically test for a script name argument that was in the current directory and add the "./" to the start of the pathname.) ################################################################## # BONUS SECTION - to do after completing Tests 1-4 ################################################################## Test 5: Execute the script with four arguments. Your code to test the script with four arguments cannot use the ExpectGoodOutput function, because to call 12_optional_arguments_demo.sh with four arguments must generate an error message on standard error. (The ExpectGoodOutput function only does tests for valid standard output.) To earn bonus points, you must write another function "ExpectBadOutput" that looks for the correct error message on standard error (redirected into the standard error file), and validates it. To be valid, the error message on standard error must contain: 1. the name of the script generating the error 2. the text of the four invalid arguments the user gave to the script 3. the number "3" or the word "three" indicating that the error message is telling the user how many arguments are allowed 4. the number "4" indicating that the error message is telling the user how many arguments were incorrectly entered For bonus marks, write the ExpectBadOutput function, and then call it. Note: You don't know in which order the above four pieces of text will appear in the error message. Your new function will have to make several separate tests on the standard error output file. You may make all four tests and return non-zero if any test failed; or, you may print a message and return non-zero from the function on the first test that fails. Return zero only if all four pieces of text are present in the stderr output file. Make your error messages useful and helpful. Note: When you are told to find a number, that means the number cannot be part of a larger number. If you are looking for the number '0', the string "Year 2002" does not contain it. The string "0 days" does. Note: The word "three" is not present in the string "a threesome". Make sure you find the word "three", not the string "three". ################################################################# # END OF BONUS SECTION #################################################################