Restructuring tests
This commit is contained in:
@@ -7,7 +7,7 @@ def checkOutput(output):
|
||||
Ensure hello world is in string.
|
||||
return: whether hello world is present
|
||||
"""
|
||||
return output == 'Hello world!\n'
|
||||
return output == 'Hello, World!\n'
|
||||
|
||||
def runCommand(command):
|
||||
"""
|
||||
@@ -16,12 +16,11 @@ def runCommand(command):
|
||||
return: Whether retcode is 0
|
||||
"""
|
||||
fh = os.popen(command, mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None
|
||||
return retcode == None
|
||||
|
||||
|
||||
def runCommandAndOutputCheck(command):
|
||||
def runCommandAndCheckOutput(command):
|
||||
"""
|
||||
Define a function to run a shell command and ensure output is correct
|
||||
param command: command
|
||||
@@ -30,4 +29,4 @@ def runCommandAndOutputCheck(command):
|
||||
fh = os.popen(command, mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
return retcode == None and checkOutput(output)
|
||||
|
6
tests/test_bash.py
Normal file
6
tests/test_bash.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_bash():
|
||||
runCommandAndCheckOutput("./HelloWorld.bash")
|
@@ -1,24 +1,6 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_compile_c():
|
||||
fh = os.popen("gcc -o HelloWorld ./HelloWorld.c", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None
|
||||
|
||||
|
||||
def test_c():
|
||||
fh = os.popen("./HelloWorld", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and checkOutput(output)
|
||||
|
||||
def test_c_cleanup():
|
||||
fh = os.popen("rm ./HelloWorld", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None
|
||||
runCommandAndCheckOutput("./HelloWorld")
|
||||
|
6
tests/test_cs.py
Normal file
6
tests/test_cs.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_cs():
|
||||
runCommandAndCheckOutput("mono ./HelloWorld.exe")
|
6
tests/test_java.py
Normal file
6
tests/test_java.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_java():
|
||||
runCommandAndCheckOutput("/usr/bin/java HelloWorld")
|
6
tests/test_php.py
Normal file
6
tests/test_php.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_php():
|
||||
runCommandAndCheckOutput("php ./HelloWorld.php")
|
6
tests/test_pl.py
Normal file
6
tests/test_pl.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_pl():
|
||||
runCommandAndCheckOutput("")
|
6
tests/test_py.py
Normal file
6
tests/test_py.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import shutil
|
||||
from tests.global_fns import *
|
||||
|
||||
def test_py():
|
||||
runCommandAndCheckOutput("./HelloWorld.py")
|
@@ -1,63 +0,0 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
def CheckOutput(output):
|
||||
return output == 'Hello world!\n'
|
||||
|
||||
def test_make():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("/bin/bash -c 'make compile'", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None
|
||||
|
||||
def test_c():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("./HelloWorld", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_cs():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("mono ./HelloWorld.exe", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_java():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("/usr/lib/jvm/java-19-openjdk/bin/java HelloWorld", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_bash():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("./HelloWorld.bash", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_perl():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("./HelloWorld.pl", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_php():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("php ./HelloWorld.php", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
||||
def test_python():
|
||||
print(os.getcwd())
|
||||
fh = os.popen("./HelloWorld.py", mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
||||
|
Reference in New Issue
Block a user