This is an extension for the CS50 automarker check50 that provides convenient wrappers around check50.run
for directly compiling and interpreting Java source/byte code.
See also check50_junit and check50_checkstyle for related utilities that make writing check50 checks for java less painful.
All examples below assume that you're importing check50
and check50_java
.
@check50.check()
def someclass_compiles():
check50_java.compile("SomeClass.java"
classpaths=['your/classpaths',
'relative/to/the',
'pset/directory.jar']
)
The classpaths argument defaults to None
~ '.'
.
@check50.check(someclass_compiles)
def someclass_main_exists():
"""SomeClass is application class"""
check50_java.checks.is_application_class("SomeClass")
@check50.check(someclass_main_exists)
def someclass_main_output():
"""SomeClass.main() output"""
expected = "X"
actual = check50_java.run("SomeClass").stdout()
help_msg = "did you introduce training newline or whitespace characters?"
if actual != expected:
raise check50.Mismatch(expected, actual, help=help_msg)