# -*- coding: utf-8 -*-
# $Id: Erlang.py 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
import logging
# local imports
# load source for simple testing
try:
# load source for testing permutations
try:
# wrapper code (TEMPLATE_SEMANTIC)
WRAPPER_TEMPLATE = \
"""-module(wrapper).
-export([start/0]).
${helpFunctions}
${testFunction}
o1() -> model:${testData}.
o2() -> student:${testData}.
start() -> io:fwrite("isEqual=~w;;expected=~w;;received=~w", [test(o1(), o2()), o1(), o2()]).
"""
# input schema
'modelSolution',
),
'helpFunctions',
),
'testData',
#accessor = # must return a list; default is one element per line
'A function call consists of the ' +
'function name (given in the exercise directives) ' +
'and test data as parameters of this funtion. '+
'Each function call must be written in a single line.',
),
))
# testSchema
'simple',
#lineNumberOffset = 2,
),
'permutation',
#lineNumberOffset = 2,
),
))
"""
A simple checker class for checking Haskell programs by comparing
student and model solution on given test data.
"""
"""
This constructor is needed to reset the logging environment.
"""
# -- check syntax ---------------------------------------------------------
"""
Replace module name in students' submission.
@see: ProgrammingBackend._preProcessCheckSyntax
@return: modified source code and new module name
"""
src)
return result, 'student'
"""
@see: AbtractSimpleBackend._postProcessCheckSyntax
"""
# replace path and filename
'line: \g<1>',
# -- check semantics ------------------------------------------------------
"""
Pre process student's submissions and semantic check wrapper code.
Override this method if you need to reformat the wrapper code or
the student's submission.
"""
return src
"""
Runs sematic test on a Erlang program.
Remenber: Before we can run the wrapper code we have to compile it!!
@return: a BackendResult object with result code and value
"""
# test for available test specs
msg = 'No test specification selected.'
# test for defined repeat fields in the schema definition
assert repeatFields, 'No RepeatField found.'
# test for available test data
msg = 'No test data defined.'
# get model solution and student's submission
"Semantic check requires valid 'model solution' (%s)" % \
"Semantic check requires valid 'student solution' (%s)" % \
# define return values
# run selected test specifications
if not solved: break
# get the compiler
try:
# FIXME: move the 're.sub' code to _preProcessCheckSyntax
# replace module name in model solution
# write model solution to a file
# compile model solution
# replace module name in student solution
# write student's solution to a file
# run compiler with students' submission
except AssertionError, err:
msg = 'Internal error during semantic check: %s: %s' % \
# get the interpreter
# 4.1. set wrapper source
# 4.2. get values for all other input fields from schema which are
# available in the job data
# 4.3 set test function
# 4.4. run with all test data
for t in testdata:
# and now add repeatable data values
# remove all remaining placeholders
# compile and execute wrapper
try:
# write module for wrapper
# compile the wrapper
'Error in wrapper code for semantic check: %s' % result
# run the wrapper
'wrapper')
except Exception, e:
msg = 'Internal error during semantic check: %s: %s' % \
# an error occured
result = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
"\n\n Received result: %s"\
# has the students' solution passed this tests?
else:
#log.debug(result)
# TODO: i18n
feedback = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
feedback += '\n\n Expected result: %s\n ' \
'Received result: %s' \
break # means: end testing right now
# end inner for loop
#end out for loop
if solved:
# TODO: i18n
feedback = '\nYour submission passed all tests.'