Skip to content

Commit

Permalink
Adding test cases and initial testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyansPatell committed Oct 23, 2023
1 parent 62ce2d4 commit 9a50971
Show file tree
Hide file tree
Showing 69 changed files with 199 additions and 5 deletions.
5 changes: 0 additions & 5 deletions batch_mode_test_1.txt

This file was deleted.

59 changes: 59 additions & 0 deletions executeTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import shutil

# Program Name. Update this according to the program name each semester
PROGRAM_NAME = "tash.c"

# Define ANSI color codes
BLUE = '\033[1;34m'
GREEN = '\033[1;32m'
RED = '\033[1;31m'
RESET = '\033[0m'

# Program and binary name
INPUT_CODE = PROGRAM_NAME
OUTPUT_BINARY = PROGRAM_NAME[:4]

# Add your required flags here
compilationFlags = ["-Wall -Werror -O" , "-Wall -Werror -O -std=c99", "-O -std=c99", "-std=c99", ""]

# Total score
totalScore = 0

# Function definitions
def compileProgram(sourceFile, outputBinary, compilationFlags):
print(f"\n\n{BLUE}Test: Compilation (10 points){RESET}")
for compilationFlagsToAdd in compilationFlags:
compileCommand = "gcc " + sourceFile + " -o " + outputBinary + " " + compilationFlagsToAdd
print(f"\n\n{BLUE}Compiling with: {compileCommand}{RESET}\n\n")
compilationResult = os.system(compileCommand)

if compilationResult == 0:
print(f"{GREEN}Test: Compilation - PASSED{RESET}")
totalScore += 10
return

print(f"\n\n{RED}Test: Compilation - FAILED{RESET}")

def createTestFolderAndFiles():
print(f"\n\n{BLUE}Creating test files{RESET}")
# Create a directory named 'test'
os.makedirs('test', exist_ok=True)

# Create 4 empty files inside the 'test' folder
for i in range(1, 5):
filePath = os.path.join('test', f'test{i}')
open(filePath, 'w').close()

def cleanUpTestFolder():
print(f"\n{BLUE}Cleaning test files{RESET}\n")
# Remove the 'test' folder and its contents
shutil.rmtree('test', ignore_errors=True)

# Main program
# Compilation
compileProgram(INPUT_CODE, OUTPUT_BINARY, compilationFlags)

# Create support folder and files
createTestFolderAndFiles()
cleanUpTestFolder()
Binary file added tash
Binary file not shown.
1 change: 1 addition & 0 deletions testcases/1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Input to check bad cd. No arguments are passed to cd.
2 changes: 2 additions & 0 deletions testcases/1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd
exit
1 change: 1 addition & 0 deletions testcases/1.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/10.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirection with multiple '>'
2 changes: 2 additions & 0 deletions testcases/10.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls > output.9 > output.10
exit
1 change: 1 addition & 0 deletions testcases/10.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/11.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Normal redirection.
4 changes: 4 additions & 0 deletions testcases/11.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ls test>output11
cat output11
rm -rf output11
exit
4 changes: 4 additions & 0 deletions testcases/11.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/12.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Input to check bad redirection. Contains no command before '>'.
2 changes: 2 additions & 0 deletions testcases/12.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> output.12
exit
1 change: 1 addition & 0 deletions testcases/12.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/13.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Input file is valid and empty. But shell is invoked in batch mode with 2 files (with same file 13.in used twice)
Empty file added testcases/13.in
Empty file.
1 change: 1 addition & 0 deletions testcases/13.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/14.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shell is invoked with a bad batch file.
Empty file added testcases/14.in
Empty file.
1 change: 1 addition & 0 deletions testcases/14.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/15.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/15.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/15.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test variable whitespace!
1 change: 1 addition & 0 deletions testcases/16.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Command only contains &
2 changes: 2 additions & 0 deletions testcases/16.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
&
exit
1 change: 1 addition & 0 deletions testcases/16.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/17.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parallel command contains & at the end
3 changes: 3 additions & 0 deletions testcases/17.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path <path to P1>/P1/ /usr/bin/
cd test & myls & pwd &
exit
6 changes: 6 additions & 0 deletions testcases/17.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<path to test>/test
test1 test2 test3 test4



(Order of the two lines may be swapped)
1 change: 1 addition & 0 deletions testcases/18.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Basic test of running parallel commands.
3 changes: 3 additions & 0 deletions testcases/18.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path <path to P1>/P1/ /usr/bin
cd test & myls & pwd & uname
exit
6 changes: 6 additions & 0 deletions testcases/18.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Linux
<path to test>/test
test1 test2 test3 test4


(Order of lines may be swapped)
1 change: 1 addition & 0 deletions testcases/19.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parallel commands with no space between command and '&'
3 changes: 3 additions & 0 deletions testcases/19.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path <path to P1>/P1 /usr/bin
cd test&myls&pwd& uname
exit
6 changes: 6 additions & 0 deletions testcases/19.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Linux
<path to test>/test
test1 test2 test3 test4


(Order of lines may be swapped)
1 change: 1 addition & 0 deletions testcases/2.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 arguments are passed to cd.
2 changes: 2 additions & 0 deletions testcases/2.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd /media /misc
exit
1 change: 1 addition & 0 deletions testcases/2.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/20.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirection and Parallel commands combined
9 changes: 9 additions & 0 deletions testcases/20.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
path /bin <path to P1>/P1
cd test & myls > output201 & pwd > output202 & uname > output203
cat output201
cat output202
cat output203
rm -rf output201
rm -rf output202
rm -rf output203
exit
9 changes: 9 additions & 0 deletions testcases/20.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output201
output202
output203
test1
test2
test3
test4
<path to test>/test
Linux
1 change: 1 addition & 0 deletions testcases/21.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Empty commands
6 changes: 6 additions & 0 deletions testcases/21.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@





exit
Empty file added testcases/21.out
Empty file.
1 change: 1 addition & 0 deletions testcases/22.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test to check that commands are not executed serially
3 changes: 3 additions & 0 deletions testcases/22.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
path /bin <path to P1>/P1
cd test & myhello & myls
exit
2 changes: 2 additions & 0 deletions testcases/22.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test1 test2 test3 test4
hello world
1 change: 1 addition & 0 deletions testcases/3.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls with a bad directory name.
2 changes: 2 additions & 0 deletions testcases/3.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls /u/c/s/cs537-1/tests/tests-wish/bad_ls/bad
exit
1 change: 1 addition & 0 deletions testcases/3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ls: cannot access /u/c/s/cs537-1/tests/tests-wish/bad_ls/bad: No such file or directory
1 change: 1 addition & 0 deletions testcases/4.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Input to run misc. commands.
5 changes: 5 additions & 0 deletions testcases/4.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd test
pwd
ls
uname
exit
3 changes: 3 additions & 0 deletions testcases/4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<path to test>/test
test1 test2 test3 test4
Linux
1 change: 1 addition & 0 deletions testcases/5.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tries to exit with an argument. Should throw an error.
2 changes: 2 additions & 0 deletions testcases/5.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exit bad
exit
1 change: 1 addition & 0 deletions testcases/5.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/6.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Try running a shell script without setting path.
3 changes: 3 additions & 0 deletions testcases/6.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd test
myls
exit
1 change: 1 addition & 0 deletions testcases/6.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/7.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set path, run a shell script. Overwrite path and then try running the script again.
6 changes: 6 additions & 0 deletions testcases/7.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
path <path to P1>/P1/
myls
path
myls
ls
exit
3 changes: 3 additions & 0 deletions testcases/7.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test1 test2 test3 test4
An error has occurred
An error has occurred
1 change: 1 addition & 0 deletions testcases/8.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirection with no output file specified.
2 changes: 2 additions & 0 deletions testcases/8.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls >
exit
1 change: 1 addition & 0 deletions testcases/8.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/9.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirection with multiple output files.
2 changes: 2 additions & 0 deletions testcases/9.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ls > output.9 output.10
exit
1 change: 1 addition & 0 deletions testcases/9.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An error has occurred

0 comments on commit 9a50971

Please sign in to comment.