Skip to content

Commit

Permalink
extension of multilanguage for Perl,PHP,Ruby,JavaScript,C#,Golang (#179)
Browse files Browse the repository at this point in the history
* extension of multilange for Perl,PHP,Ruby,JavaScript,C#,Golang

support for more languages has been added via python wrapper. Pls note
individual language support needs to be installed / available in the
jobe server.

* incremented version number to 2023101500

---------

Co-authored-by: Rajesh Mallah <[email protected]>
  • Loading branch information
rmallah and redgrapetech authored Oct 26, 2023
1 parent ff99617 commit 7ba87a1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
44 changes: 40 additions & 4 deletions db/builtin_PROTOTYPES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,28 @@ print(SEPARATOR)
<useace>1</useace>
<resultcolumns></resultcolumns>
<template><![CDATA["""The template for a "write a program" question type that accepts answers
in C, C++, Java or Python3 according to the value in the language select
in C, C++, Java,Python3,Perl,PHP,Ruby,JavaScript,C# or Golang according to the value in the language select
dropdown menu.
"""
import subprocess
import re
student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
language = """{{ ANSWER_LANGUAGE | e('py') }}""".lower()
language_extension_map = {'c':'c', 'cpp':'cpp', 'java':'java', 'python3':'py'}
language_extension_map = {
'c':'c'
, 'cpp':'cpp'
, 'java':'java'
, 'python3':'py'
, 'perl':'pl'
, 'php':'php'
, 'ruby':'rb'
, 'javascript':'js'
, 'c#':'cs'
, 'golang':'go'
}
if language not in language_extension_map.keys():
raise Exception('Error in question. Unknown/unexpected language ({})'.format(language))
Expand All @@ -1145,6 +1158,8 @@ if language == 'java':
raise Exception("Unable to determine class name. Does the file include 'public class name'?")
classname = match.group(1)
filename = classname + '.java'
elif language == 'golang':
filename = 'tester.' + language_extension_map[language]
else:
filename = '__tester__.' + language_extension_map[language]
Expand All @@ -1171,6 +1186,27 @@ elif language == 'java':
if return_code != 0:
raise Exception("** Compilation failed. Testing aborted **")
exec_command = ["java", "-Xss16m", "-Xmx500m", classname]
elif language == 'perl':
exec_command = ["perl", "-w", "./__tester__.pl" ]
elif language == 'ruby':
exec_command = ["ruby", "-w", "./__tester__.rb" ]
elif language == 'php':
exec_command = ["php", "./__tester__.php" ]
elif language == 'javascript':
exec_command = ["node", "./__tester__.js" ]
elif language == 'golang':
go_env = {}
go_env["GOCACHE"]="/tmp/.go-cache"
completedProc = subprocess.run([ "go", "build", "-o", "tester.exe", filename ],env=go_env )
if completedProc.returncode != 0:
raise Exception("** Golang Compilation failed. Testing aborted **")
exec_command = ["./tester.exe"]
elif language == 'c#':
cs_env = {}
completedProc = subprocess.run([ "mcs", "-out:tester.exe", filename ],env=cs_env )
if completedProc.returncode != 0:
raise Exception("** C# Compilation failed. Testing aborted **")
exec_command = ["./tester.exe"]
else: # Python doesn't need a compile phase
exec_command = ["python3", "./__tester__.py"]
Expand Down Expand Up @@ -1199,7 +1235,7 @@ except subprocess.CalledProcessError as e:
<validateonsave>0</validateonsave>
<testsplitterre></testsplitterre>
<language>python3</language>
<acelang>c,cpp,java,python3</acelang>
<acelang>c,cpp,java,python3,perl,php,ruby,javascript,c#,golang</acelang>
<sandbox></sandbox>
<grader>EqualityGrader</grader>
<cputimelimitsecs></cputimelimitsecs>
Expand All @@ -1213,4 +1249,4 @@ except subprocess.CalledProcessError as e:
</testcases>
</question>

</quiz>
</quiz>
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023091800;
$plugin->version = 2023101500;
$plugin->requires = 2022041900;
$plugin->cron = 0;
$plugin->component = 'qtype_coderunner';
Expand Down

0 comments on commit 7ba87a1

Please sign in to comment.