Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_leak(self):
with open("leak.c", "w") as f:
src = '#include \n'\
'void leak() {malloc(sizeof(int));}\n'\
'int main() {\n'\
' leak();\n'\
'}'
f.write(src)
check50.c.compile("leak.c")
with self.assertRaises(check50.Failure):
with check50.internal.register:
check50.c.valgrind("./leak").exit()
def test_no_leak(self):
with open("foo.c", "w") as f:
src = 'int main() {}'
f.write(src)
check50.c.compile("foo.c")
with check50.internal.register:
check50.c.valgrind("./foo").exit()
def test_compile_hello_world(self):
with open("hello.c", "w") as f:
src = '#include \n'\
'int main() {\n'\
' printf("hello, world!\\n");\n'\
'}'
f.write(src)
check50.c.compile("hello.c")
self.assertTrue(os.path.isfile("hello"))
check50.run("./hello").stdout("hello, world!", regex=False)
def compiles():
"""hello.c compiles"""
check50.c.compile("hello.c")