# -*- coding: utf-8 -*-
# $Id: config.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 #
################################################################################
#
# 04.03.2009, chbauman:
# NS_STUDENT starts with lowercase letter
# renewed CLASS_NAME_RE
# deleted CONSTRUCTOR_ATTRIBUTES_RE -> no longer needed
# corrected TestEnvironment
# 16.03.2009, chbauman:
# new RE 'IMPORT_NAME_NOT_JAVA_RE'
# corrected comments
# corrected 'CLASSPATH_SETTINGS'
# some beauty-changes 'in wrapperTemplate', including new error message
# 24.03.2009, chbauman:
# reverted changes in TestEnvironment
# 06.04.2009, chbauman:
# new Regular Expression 'FAILURE_TRACE_RE'
# wrapperTemplate now prints the trace of a Failure
# 07.04.2009, chbauman:
# extended wrapperTemplate: possibility to exclude certain classes from
# Failure trace printing
# shorter, propably more general RE for FAILURE_TRACE_RE
# 28.05.2010, chbauman:
# Formatted Java code in wrapper template.
# Properties used by backend JUnit.
#compiler = join(abspath(dirname(__file__)), 'javac')
#interpreter = join(abspath(dirname(__file__)), 'java+systrace')
"""
trc = os.getenv('EC_TRACE')
comp = 'javac.sh'
if trc == 'bsd': comp = 'javac'
compiler = join(abspath(dirname(__file__)), comp)
intp = 'java.sh'
if trc == 'bsd': intp = 'java+systrace'
interpreter = join(abspath(dirname(__file__)), intp)
"""
# The packages that the model and student solution will be put in
# The name of the wrapper class that performs the semantic check
# Due to a NoSuchMethodException it is possible that all tests are displayed to the student.
# This RE will shorten the output and hide the tests from students.
# Library directory name:
# absolute path to junit dir
# Library path
# Library content
# Platformdependent classpath separator
# Known archive types
# Define classpath settings:
# Scans JUNIT_LIBS directory and adds all archives to CLASSPATH_SETTINGS
# CLASSPATH_SETTINGS will be passed to _runInterpreter as options
if libExtension in ARCHIVES:
# Messages displayed to the student
# Wrapper Template used to test the submission
wrapperTemplate = \
'''import java.util.ArrayList;
import java.util.List;
//imports for Unit testing
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.*;
import org.junit.internal.ArrayComparisonFailure;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
//organize teacher's additional imports
${imports}
//import submission:
import %s.*;
public class %s {
private static final int NO_FAILURES = 0;
// Used to filter out traces:
private static List<Class> excludedTraceClasses = new ArrayList<Class>();
// Initialize excludedTraceClasses via static constructor.
// Insert Throwables, whose traces are undesired to output:
static{
excludedTraceClasses.add(AssertionError.class);
excludedTraceClasses.add(ComparisonFailure.class);
}
//teacher's help functions:
${helpFunctions}
//teacher's unit tests:
${unitTests}
public static void main(String[] args) {
Result result = JUnitCore.runClasses(%s.class);
if(result.getFailureCount() == NO_FAILURES){
System.out.println("%s");
System.exit(0);
}else{
Failure failure = result.getFailures().get(0);
System.out.println(failure.toString());
// Filter out AssertionErrors and ComparisonFailures,
// print all traces of other exceptions:
Throwable throwable = failure.getException();
if(!excludedTraceClasses.contains(throwable.getClass())){
System.out.println(failure.getTrace());
}
System.exit(1);
}
}
}
# Input Schema
'imports',
description = 'Enter additional imports, like java '\
'libraries.',
),
'helpFunctions',
),
'unitTests',
description = 'Enter one or more JUnit tests. '\
'If you have to reference the class of the submission '\
'use variable "${CLASS}". [e.g. ${CLASS} myClass = new ${CLASS}(); or '\
'${CLASS}.method()]',
),
))
# Test Schema
'default',
),
))