Updating standards
This commit is contained in:
33
tests/global_fns.py
Normal file
33
tests/global_fns.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
def checkOutput(output):
|
||||
"""
|
||||
Ensure hello world is in string.
|
||||
return: whether hello world is present
|
||||
"""
|
||||
return output == 'Hello world!\n'
|
||||
|
||||
def runCommand(command):
|
||||
"""
|
||||
Define a function to run a shell commmand and return the output
|
||||
param command: command to run
|
||||
return: Whether retcode is 0
|
||||
"""
|
||||
fh = os.popen(command, mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None
|
||||
|
||||
|
||||
def runCommandAndOutputCheck(command):
|
||||
"""
|
||||
Define a function to run a shell command and ensure output is correct
|
||||
param command: command
|
||||
return: Whether retcode is 0 && output matches test.
|
||||
"""
|
||||
fh = os.popen(command, mode='r', buffering=-1)
|
||||
output = fh.read()
|
||||
retcode = fh.close()
|
||||
assert retcode == None and CheckOutput(output)
|
24
tests/test_c.py
Normal file
24
tests/test_c.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
Reference in New Issue
Block a user