diff --git a/executeTests.py b/executeTests.py index 808acad..c149a9f 100644 --- a/executeTests.py +++ b/executeTests.py @@ -51,6 +51,12 @@ TEST_CASE_4 = "Test Case 4: Inbuilt Command in Batch Mode -> cd" TEST_CASE_5 = "Test Case 5: Inbuilt Command in Interactive Mode -> exit" TEST_CASE_6 = "Test Case 6: Inbuilt Command in Batch Mode -> exit" +TEST_CASE_7 = "Test Case 7: Valid ls command in Interactive Mode" +TEST_CASE_8 = "Test Case 8: Invalid ls commmand in Interactive Mode" +TEST_CASE_9 = "Test Case 9: Start Batch Mode with a file that does not exist" +TEST_CASE_10 = "Test Case 10: Start Batch Mode with two valid files" +TEST_CASE_11 = "Test Case 11: Test echo command with variable whitespaces in Interactive Mode" +TEST_CASE_12 = "Test Case 12: Test echo command with variable whitespaces in Batch Mode" # Global variables totalScore = 0 @@ -292,6 +298,174 @@ def testCase6(): print(f"{GREEN}"+TEST_CASE_6+f" - PASSED{RESET}") testResults[TEST_CASE_6] = PASSED_STRING return TEST_CASE_POINTS + +# TEST_CASE_7 +def testCase7(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_7+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash < {TEST_CASES_PATH+'case'+'7.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_7+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_7] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(output, TEST_CASES_PATH+'case'+'7.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_7+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_7] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_7+f" - PASSED{RESET}") + testResults[TEST_CASE_7] = PASSED_STRING + return TEST_CASE_POINTS + +# TEST_CASE_8 +def testCase8(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_8+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash < {TEST_CASES_PATH+'case'+'8.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_8+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_8] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(error, TEST_CASES_PATH+'case'+'8.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_8+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_8] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_8+f" - PASSED{RESET}") + testResults[TEST_CASE_8] = PASSED_STRING + return TEST_CASE_POINTS + +# TEST_CASE_9 +def testCase9(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_9+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash {TEST_CASES_PATH+'case'+'does_not_exist.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_9+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_9] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(error, TEST_CASES_PATH+'case'+'9.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_9+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_9] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_9+f" - PASSED{RESET}") + testResults[TEST_CASE_9] = PASSED_STRING + return TEST_CASE_POINTS + +# TEST_CASE_10 +def testCase10(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_10+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash {TEST_CASES_PATH+'case'+'10.in'} {TEST_CASES_PATH+'case'+'10.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_10+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_10] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(error, TEST_CASES_PATH+'case'+'10.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_10+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_10] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_10+f" - PASSED{RESET}") + testResults[TEST_CASE_10] = PASSED_STRING + return TEST_CASE_POINTS + +# TEST_CASE_11 +def testCase11(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_11+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash < {TEST_CASES_PATH+'case'+'11.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_11+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_11] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(output, TEST_CASES_PATH+'case'+'11.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_11+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_11] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_11+f" - PASSED{RESET}") + testResults[TEST_CASE_11] = PASSED_STRING + return TEST_CASE_POINTS + +# TEST_CASE_12 +def testCase12(): + global testResults + print(f"\n\n{PURPLE}"+TEST_CASE_12+f" ({TEST_CASE_POINTS} points){RESET}") + command = f"./tash {TEST_CASES_PATH+'case'+'12.in'}" + returnCode, output, error = runCommandWithTimeout(command, timeout=10) + + if returnCode == -1: + print(f"{RED}"+TEST_CASE_12+f" - FAILED (Time exceeded){RESET}") + testResults[TEST_CASE_12] = FAILED_TLE_STRING + return FAILURE_POINTS + + result, expectedOutput = compareOutput(output, TEST_CASES_PATH+'case'+'12.out') + + if result == 0: + print(f"{RED}"+TEST_CASE_12+f" - FAILED{RESET}") + print("Your Output:") + print(output) + print("Expected Output:") + print(expectedOutput) + testResults[TEST_CASE_12] = FAILED_STRING + return FAILURE_POINTS + + else: + print(f"{GREEN}"+TEST_CASE_12+f" - PASSED{RESET}") + testResults[TEST_CASE_12] = PASSED_STRING + return TEST_CASE_POINTS # Main program # Create support folder and files @@ -307,12 +481,18 @@ def testCase6(): totalScore = totalScore + testCase4() # TEST_CASE_4 totalScore = totalScore + testCase5() # TEST_CASE_5 totalScore = totalScore + testCase6() # TEST_CASE_6 +totalScore = totalScore + testCase7() # TEST_CASE_7 +totalScore = totalScore + testCase8() # TEST_CASE_8 +totalScore = totalScore + testCase9() # TEST_CASE_9 +totalScore = totalScore + testCase10() # TEST_CASE_10 +totalScore = totalScore + testCase11() # TEST_CASE_11 +totalScore = totalScore + testCase12() # TEST_CASE_12 # Print test results printResults(totalScore) # Cleaning -cleanUpTestFolder() +# cleanUpTestFolder() # Close the log file when you're done # logFile.close() \ No newline at end of file diff --git a/testcases/13.desc b/testcases/13.desc deleted file mode 100644 index 15c67f7..0000000 --- a/testcases/13.desc +++ /dev/null @@ -1 +0,0 @@ -Input file is valid and empty. But shell is invoked in batch mode with 2 files (with same file 13.in used twice) diff --git a/testcases/13.out b/testcases/13.out deleted file mode 100644 index 3f18372..0000000 --- a/testcases/13.out +++ /dev/null @@ -1 +0,0 @@ -An error has occurred diff --git a/testcases/14.desc b/testcases/14.desc deleted file mode 100644 index 7f99b70..0000000 --- a/testcases/14.desc +++ /dev/null @@ -1 +0,0 @@ -Shell is invoked with a bad batch file. diff --git a/testcases/14.out b/testcases/14.out deleted file mode 100644 index 3f18372..0000000 --- a/testcases/14.out +++ /dev/null @@ -1 +0,0 @@ -An error has occurred diff --git a/testcases/15.desc b/testcases/15.desc deleted file mode 100644 index d449c89..0000000 --- a/testcases/15.desc +++ /dev/null @@ -1 +0,0 @@ -Tests command with variable whitespace. diff --git a/testcases/15.in b/testcases/15.in deleted file mode 100644 index 08a539b..0000000 --- a/testcases/15.in +++ /dev/null @@ -1,3 +0,0 @@ - - echo test variable whitespace! -exit diff --git a/testcases/15.out b/testcases/15.out deleted file mode 100644 index d8da9e8..0000000 --- a/testcases/15.out +++ /dev/null @@ -1 +0,0 @@ -test variable whitespace! diff --git a/testcases/3.desc b/testcases/3.desc deleted file mode 100644 index 4949d74..0000000 --- a/testcases/3.desc +++ /dev/null @@ -1 +0,0 @@ -ls with a bad directory name. \ No newline at end of file diff --git a/testcases/3.in b/testcases/3.in deleted file mode 100644 index 8606e64..0000000 --- a/testcases/3.in +++ /dev/null @@ -1,2 +0,0 @@ -ls /u/c/s/cs537-1/tests/tests-wish/bad_ls/bad -exit \ No newline at end of file diff --git a/testcases/3.out b/testcases/3.out deleted file mode 100644 index c236d8f..0000000 --- a/testcases/3.out +++ /dev/null @@ -1 +0,0 @@ -ls: cannot access /u/c/s/cs537-1/tests/tests-wish/bad_ls/bad: No such file or directory \ No newline at end of file diff --git a/testcases/4.desc b/testcases/4.desc deleted file mode 100644 index 91a33ff..0000000 --- a/testcases/4.desc +++ /dev/null @@ -1 +0,0 @@ -Input to run misc. commands. \ No newline at end of file diff --git a/testcases/4.in b/testcases/4.in deleted file mode 100644 index 7c682a5..0000000 --- a/testcases/4.in +++ /dev/null @@ -1,5 +0,0 @@ -cd test -pwd -ls -uname -exit \ No newline at end of file diff --git a/testcases/4.out b/testcases/4.out deleted file mode 100644 index 2d09fef..0000000 --- a/testcases/4.out +++ /dev/null @@ -1,3 +0,0 @@ -/test -test1 test2 test3 test4 -Linux \ No newline at end of file diff --git a/testcases/5.desc b/testcases/5.desc deleted file mode 100644 index b19c8d9..0000000 --- a/testcases/5.desc +++ /dev/null @@ -1 +0,0 @@ -Tries to exit with an argument. Should throw an error. diff --git a/testcases/5.in b/testcases/5.in deleted file mode 100644 index 3459a63..0000000 --- a/testcases/5.in +++ /dev/null @@ -1,2 +0,0 @@ -exit bad -exit diff --git a/testcases/5.out b/testcases/5.out deleted file mode 100644 index 3f18372..0000000 --- a/testcases/5.out +++ /dev/null @@ -1 +0,0 @@ -An error has occurred diff --git a/testcases/6.desc b/testcases/6.desc deleted file mode 100644 index 8844f2b..0000000 --- a/testcases/6.desc +++ /dev/null @@ -1 +0,0 @@ -Try running a shell script without setting path. diff --git a/testcases/6.in b/testcases/6.in deleted file mode 100644 index aa1df54..0000000 --- a/testcases/6.in +++ /dev/null @@ -1,3 +0,0 @@ -cd test -myls -exit diff --git a/testcases/6.out b/testcases/6.out deleted file mode 100644 index 3f18372..0000000 --- a/testcases/6.out +++ /dev/null @@ -1 +0,0 @@ -An error has occurred diff --git a/testcases/7.desc b/testcases/7.desc deleted file mode 100644 index 3a5dabf..0000000 --- a/testcases/7.desc +++ /dev/null @@ -1 +0,0 @@ -Set path, run a shell script. Overwrite path and then try running the script again. diff --git a/testcases/7.in b/testcases/7.in deleted file mode 100644 index 3c4165f..0000000 --- a/testcases/7.in +++ /dev/null @@ -1,6 +0,0 @@ -path /P1/ -myls -path -myls -ls -exit diff --git a/testcases/7.out b/testcases/7.out deleted file mode 100644 index f0a36c3..0000000 --- a/testcases/7.out +++ /dev/null @@ -1,3 +0,0 @@ -test1 test2 test3 test4 -An error has occurred -An error has occurred diff --git a/testcases/case10.desc b/testcases/case10.desc new file mode 100644 index 0000000..a041ee0 --- /dev/null +++ b/testcases/case10.desc @@ -0,0 +1 @@ +Trying to execute Batch Mode with two files. This should not be allowed as per project requirements. case10.in is to be disregarded since it is not in use. Program should give an error. \ No newline at end of file diff --git a/testcases/13.in b/testcases/case10.in similarity index 100% rename from testcases/13.in rename to testcases/case10.in diff --git a/testcases/case10.out b/testcases/case10.out new file mode 100644 index 0000000..2aaf152 --- /dev/null +++ b/testcases/case10.out @@ -0,0 +1 @@ +An error has occurred \ No newline at end of file diff --git a/testcases/case11.desc b/testcases/case11.desc new file mode 100644 index 0000000..67ef867 --- /dev/null +++ b/testcases/case11.desc @@ -0,0 +1 @@ +Tests command with variable whitespace. \ No newline at end of file diff --git a/testcases/case11.in b/testcases/case11.in new file mode 100644 index 0000000..a4c4bbd --- /dev/null +++ b/testcases/case11.in @@ -0,0 +1,3 @@ + + echo test variable whitespace! +exit \ No newline at end of file diff --git a/testcases/case11.out b/testcases/case11.out new file mode 100644 index 0000000..7f166c0 --- /dev/null +++ b/testcases/case11.out @@ -0,0 +1 @@ +test variable whitespace! \ No newline at end of file diff --git a/testcases/case12.desc b/testcases/case12.desc new file mode 100644 index 0000000..67ef867 --- /dev/null +++ b/testcases/case12.desc @@ -0,0 +1 @@ +Tests command with variable whitespace. \ No newline at end of file diff --git a/testcases/case12.in b/testcases/case12.in new file mode 100644 index 0000000..a4c4bbd --- /dev/null +++ b/testcases/case12.in @@ -0,0 +1,3 @@ + + echo test variable whitespace! +exit \ No newline at end of file diff --git a/testcases/case12.out b/testcases/case12.out new file mode 100644 index 0000000..7f166c0 --- /dev/null +++ b/testcases/case12.out @@ -0,0 +1 @@ +test variable whitespace! \ No newline at end of file diff --git a/testcases/case7.desc b/testcases/case7.desc new file mode 100644 index 0000000..af11f7a --- /dev/null +++ b/testcases/case7.desc @@ -0,0 +1 @@ +Valid ls command. Program should give no errors. \ No newline at end of file diff --git a/testcases/case7.in b/testcases/case7.in new file mode 100644 index 0000000..d2dc847 --- /dev/null +++ b/testcases/case7.in @@ -0,0 +1,2 @@ +ls test +exit \ No newline at end of file diff --git a/testcases/case7.out b/testcases/case7.out new file mode 100644 index 0000000..dff34e0 --- /dev/null +++ b/testcases/case7.out @@ -0,0 +1,4 @@ +test1 +test2 +test3 +test4 \ No newline at end of file diff --git a/testcases/case8.desc b/testcases/case8.desc new file mode 100644 index 0000000..8a8f11d --- /dev/null +++ b/testcases/case8.desc @@ -0,0 +1 @@ +Invalid ls command. Program should an error. \ No newline at end of file diff --git a/testcases/case8.in b/testcases/case8.in new file mode 100644 index 0000000..aaddd92 --- /dev/null +++ b/testcases/case8.in @@ -0,0 +1,2 @@ +ls does/not/exist/bad +exit \ No newline at end of file diff --git a/testcases/case8.out b/testcases/case8.out new file mode 100644 index 0000000..cffb77a --- /dev/null +++ b/testcases/case8.out @@ -0,0 +1 @@ +ls: does/not/exist/bad: No such file or directory \ No newline at end of file diff --git a/testcases/case9.desc b/testcases/case9.desc new file mode 100644 index 0000000..0e6973a --- /dev/null +++ b/testcases/case9.desc @@ -0,0 +1 @@ +Trying to execute Batch Mode with a file that does not exist. case9.in is to be disregarded since it is not in use. Program should give an error. \ No newline at end of file diff --git a/testcases/14.in b/testcases/case9.in similarity index 100% rename from testcases/14.in rename to testcases/case9.in diff --git a/testcases/case9.out b/testcases/case9.out new file mode 100644 index 0000000..2aaf152 --- /dev/null +++ b/testcases/case9.out @@ -0,0 +1 @@ +An error has occurred \ No newline at end of file