# -*- coding: utf-8 -*-
# $Id: HaskellQC.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 #
################################################################################
#
# 20.03.2009, chbauman:
# version 1.1
# using self.srcFileSuffix instead of hard-coded '.hs'
# preventing multiple result output
# 24.03.2009, chbauman:
# refactored variable 't' to 'propertyTest'
# using HaskellQCConf.FAILED_TEST_MESSAGE and PASSED_ALL_TESTS_MESSAGE
# improved feedback (corporate design)
import logging
# local imports
# regex to get all property names
# regex to substitute 'prop_' placeholder with the property name
# regex to identify failed tests
# template for Haskell module containing all QuickCheck properties
PROPS_TEMPLATE = \
"""
module Properties where
import QuickCheck -- e.g. for conditional properties
import Student
%s
"""
# template for wrapper code
WRAPPER_TEMPLATE = \
"""
module Main where
import QuickCheck
import Properties
main :: IO ()
--main = quickCheck ${prop_}
main = verboseCheck ${prop_}
"""
# input schema
'properties',
'(cf. <http://www.cs.chalmers.se/~rjmh/QuickCheck/>).',
),
))
# test environments
'default',
#test = '',
),
))
"""
Backend for testing Haskell programs using QuickCheck.
"""
"""
"""
"""
Post process QuickCheck result messages.
@param: test:
@param: message:
"""
return result
"""
@return: a BackendResult object with result code and value
"""
# test for available test specs
msg = 'No test specification selected.'
# get student's submission and QuickCheck properties
#assert properties and type(properties) in StringTypes, \
# "Semantic check requires valid 'properties' (%s)" % properties
"Semantic check requires valid 'student solution' (%s)" % submission
testdata = None
if properties:
# If a student submitted a function declaration additionally to its
# definition, testdata will contain multiple occurrences of the same
# function name, which causes this backend to output the results
# multiple times, too. By 'setifying' testdata we'll get an array
# of unique entries.
msg = 'No QuickCheck propeties defined.'
# define return values
# run selected test specifications
if not solved: break
# get the interpreter
# write submission and propeties to files
# run with all test data
for propertyTest in testdata:
# add property name
# execute wrapper code in haskell interpreter
try:
# write module for wrapper
# execute
# remove all special characters written by runhugs
except Exception, e:
msg = 'Internal error during semantic check: %s: %s' % \
# an error occured
# FIXME: os.EX_OK is available only for Macintosh and Unix!
result = "\nYour submission failed. Test " \
"case was: '%s' (%s)" \
"\n\n Received result: %s"\
# has the students' solution passed this test?
else:
#LOG.debug(result)
#passed = PASSED_RE.search(result)
# only consider errornous submissions
if failed:
# store the reason
break # means: end testing right now
# end elif
#end else
# end inner for loop
#end out for loop
# does student's submission have all teacher-defined properties?
if solved:
# Yes -> Show that all tests were passed.
else:
# No -> Show that submission failed.
feedback = \
# TODO: i18n
# -- do some testing ----------------------------------------------------------
if __name__ == "__main__":
"""
"""
import socket
jobdata = {
'backend':'haskellqc',
'submission':'square x = x * x',
'properties': 'prop_square x = (square x) == (x * x)\n where types= x::Int',
'tests': ['default'],
}
print result.getMessage()