Skip to content

Commit

Permalink
Added six new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyansPatell committed Oct 24, 2023
1 parent 2207cbf commit c5f49cb
Show file tree
Hide file tree
Showing 41 changed files with 206 additions and 42 deletions.
182 changes: 181 additions & 1 deletion executeTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
1 change: 0 additions & 1 deletion testcases/13.desc

This file was deleted.

1 change: 0 additions & 1 deletion testcases/13.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/14.desc

This file was deleted.

1 change: 0 additions & 1 deletion testcases/14.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/15.desc

This file was deleted.

3 changes: 0 additions & 3 deletions testcases/15.in

This file was deleted.

1 change: 0 additions & 1 deletion testcases/15.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/3.desc

This file was deleted.

2 changes: 0 additions & 2 deletions testcases/3.in

This file was deleted.

1 change: 0 additions & 1 deletion testcases/3.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/4.desc

This file was deleted.

5 changes: 0 additions & 5 deletions testcases/4.in

This file was deleted.

3 changes: 0 additions & 3 deletions testcases/4.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/5.desc

This file was deleted.

2 changes: 0 additions & 2 deletions testcases/5.in

This file was deleted.

1 change: 0 additions & 1 deletion testcases/5.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/6.desc

This file was deleted.

3 changes: 0 additions & 3 deletions testcases/6.in

This file was deleted.

1 change: 0 additions & 1 deletion testcases/6.out

This file was deleted.

1 change: 0 additions & 1 deletion testcases/7.desc

This file was deleted.

6 changes: 0 additions & 6 deletions testcases/7.in

This file was deleted.

3 changes: 0 additions & 3 deletions testcases/7.out

This file was deleted.

1 change: 1 addition & 0 deletions testcases/case10.desc
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
1 change: 1 addition & 0 deletions testcases/case10.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An error has occurred
1 change: 1 addition & 0 deletions testcases/case11.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests command with variable whitespace.
3 changes: 3 additions & 0 deletions testcases/case11.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

echo test variable whitespace!
exit
1 change: 1 addition & 0 deletions testcases/case11.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test variable whitespace!
1 change: 1 addition & 0 deletions testcases/case12.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests command with variable whitespace.
3 changes: 3 additions & 0 deletions testcases/case12.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

echo test variable whitespace!
exit
1 change: 1 addition & 0 deletions testcases/case12.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test variable whitespace!
1 change: 1 addition & 0 deletions testcases/case7.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Valid ls command. Program should give no errors.
2 changes: 2 additions & 0 deletions testcases/case7.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls test
exit
4 changes: 4 additions & 0 deletions testcases/case7.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test1
test2
test3
test4
1 change: 1 addition & 0 deletions testcases/case8.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid ls command. Program should an error.
2 changes: 2 additions & 0 deletions testcases/case8.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls does/not/exist/bad
exit
1 change: 1 addition & 0 deletions testcases/case8.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls: does/not/exist/bad: No such file or directory
1 change: 1 addition & 0 deletions testcases/case9.desc
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
1 change: 1 addition & 0 deletions testcases/case9.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An error has occurred

0 comments on commit c5f49cb

Please sign in to comment.