Updating standards

This commit is contained in:
2022-08-29 00:10:10 -05:00
parent f7049cdd15
commit 334a900c95
6 changed files with 66 additions and 5 deletions

33
tests/global_fns.py Normal file
View 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
View 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