Hi,
I use for a while coderunner's questions with my own jobe server (jobeinabox), but only for python questions. It work well.
My students are now working with OCaml. How could I adapt the "new language" example for OCaml programs ? I already modified the Dockerfile to install ocaml and it seems to work (ocaml works when bash to the docker container)
Thanks for this beautiful work,
Yannick
Hi Yannick and Lilian
import subprocess
__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""
with open("prog.ml","w") as src :
print(__student_answer__,file=src)
SEPARATOR = "#<ab@17943918#@>#"
{% for TEST in TESTCASES %}
code = "#use \"prog.ml\";;"+"\n\n"+"""{{ TEST.testcode }}"""
with open("progtest.ml","w") as src :
print(code[:-1], file=src)
if True:
try:
output = subprocess.check_output("ocaml progtest.ml",shell=True,timeout=90)
print(output.decode())
except subprocess.CalledProcessError as e:
if e.returncode > 0:
# Ignore non-zero positive return codes
if e.output:
print("erreur")
print(e.output)
else:
# But negative return codes are signals - abort
if e.output:
print(e.output, file=sys.stderr)
if e.returncode < 0:
print("Task failed with signal", -e.returncode, file=sys.stderr)
print("** Further testing aborted **", file=sys.stderr)
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}
Hi Lilian
Thanks for the suggestion and it's interesting that OCaml is available as a JavaScript module. However, that doesn't really help in a CodeRunner context. It's true that you could have a CodeRunner question that ran OCaml in the browser but the architecture of CodeRunner requires that the actual program execution (i.e., the running of the question's template) takes place on the sandbox server (i.e. "Jobe").
Richard
Good to hear you've got it working Yannick. Except for the OCaml bit, which I don't understand because I don't know OCaml, it all looks fine. You could of course dispense with the "if True" and dedent its block. The timeout=90 probably doesn't achieve anything: Jobe has its own timeout and will kill the job before the subprocess timer anyway. If that happens, CodeRunner will re-run the job, one test case at a time, until a timeout occurs again. But you might want to check with a program that gets into an infinite loop on one of the test cases only.
Ok thanks for the precisions.
Of course I agree with the "if True" thing : it was just too late...
Thank you for all the Job, CodeRunner is really usefull.
Yannick
One more precision for ocaml users : replacing ocaml by utop allows to test the signature of a function by adding #typeof in the test cases.