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()
- bar
stdout:
- baz
- qux
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdin("foo\\nbar", prompt=False).stdout("baz\\nqux", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
- run: python3 foo.py
stdout: |
Hello
World!
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdout("Hello\\nWorld!\\n", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
def test_missing_exit(self):
checks = yaml.safe_load(\
"""checks:
bar:
- run: python3 foo.py
""")["checks"]
result = _simple.compile(checks)
self.assertTrue(".exit()" in result)
bar:
- run: python3 foo.py
stdin: baz
stdout: baz
exit: 0
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").stdin("baz", prompt=False).stdout("baz", regex=False).exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
""")["checks"]
expectation = \
"""import check50
@check50.check()
def bar():
\"\"\"bar\"\"\"
check50.run("python3 foo.py").exit(0)
@check50.check()
def baz():
\"\"\"baz\"\"\"
check50.run("python3 foo.py").exit(0)"""
result = _simple.compile(checks)
self.assertEqual(result, expectation)
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_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_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()