How to use check50 - 10 common examples

To help you get started, we’ve selected a few check50 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cs50 / check50 / tests / c_tests.py View on Github external
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()
github cs50 / check50 / tests / simple_tests.py View on Github external
- 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)
github cs50 / check50 / tests / simple_tests.py View on Github external
- 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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
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)
github cs50 / check50 / tests / simple_tests.py View on Github external
""")["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)
github cs50 / check50 / tests / c_tests.py View on Github external
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()
github cs50 / check50 / tests / c_tests.py View on Github external
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()
github cs50 / check50 / tests / c_tests.py View on Github external
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()
github cs50 / check50 / tests / c_tests.py View on Github external
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()