# -*- coding: utf-8 -*-
# $Id: HaskellExt.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.
################################################################################
# Changelog #
################################################################################
#
# 30.04.2009, chbauman:
# replaced re.sub with replace whereever possible.
import logging
# local imports
"""module ${MODULE} where
${SOURCE}
main = ${testData}
"""
wrapperTemplate = \
"""module Main where
import Model
import Student
${testFunction}
o1 = Model.main
o2 = Student.main
main = putStr(\"isEqual=\" ++ show(haskell_backend_internal_equality_test (o1) (o2)) ++ \";;expected=\" ++ show(o1) ++ \";;received=\" ++ show(o2))
"""
# use inputSchema of backend Haskel and modify it
# use testSchema of backend Haskell and modify it
"""
An alternative backend to the Haskell backend.
The test calls will be written to the model and student's modules. The
result of calling main for model and student's module than will be
compared in wrapper code.
We do this to bypass the problem that a function with the same
name is definied in the model as well as in the student's module.
"""
"""
"""
"""
This method checks the semantic of a Haskell program. Ovrrides method
_process_checkSemantics in class Haskell.
@return: a tuple 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)" % model
"Semantic check requires valid 'student solution' (%s)" % submission
#model = TEMPLATE_DEFAULT_MODULE % ('Model', model)
#submission = TEMPLATE_DEFAULT_MODULE % ('Student', submission)
#model = re.sub('\$\{SOURCE}', model, HaskellExtConf.semanticCheckTemplate)
#model = re.sub('\$\{MODULE}', 'Model', model)
#
#submission = re.sub('\$\{SOURCE}', submission, HaskellExtConf.semanticCheckTemplate)
#submission = re.sub('\$\{MODULE}', 'Student', submission)
# define return values
# run selected test specifications
if not solved: break
# set the interpreter
# set wrapper code
# get the values for all other input fields which are defined in the
# schema - unless the according data are available in the job object
#wrapper = re.sub('\$\{%s\}' % field.getName(),
# repl, wrapper)
# set test function in wrapper code
#wrapper = re.sub('\$\{testFunction\}', test.test, wrapper)
# remove all remaining placeholders
# run with all test data
for t in testdata:
# set testdata in model and students' code
#modelSrc = re.sub('\$\{%s\}' % repeatField.getName(), t,
# model)
#studentSrc = re.sub('\$\{%s\}' % repeatField.getName(), t,
# submission)
try:
# 1st write model solution
# 2nd write students' solution
# at least write the wrapper and execute
#log.debug('xxx: %s' % os.path.dirname(wrapperModule['file']))
#result = re.sub(HaskellExtConf.runhugsRegEx, '', result)
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' \
# in case of one failed testcase we will
# return right now
break
# end inner for loop
#end out for loop
if solved:
# TODO: i18n
feedback = '\nYour submission passed all tests.'