Skip to content

Commit

Permalink
Merge 89d3446 into 92cfcb6
Browse files Browse the repository at this point in the history
  • Loading branch information
npasserini committed Mar 6, 2019
2 parents 92cfcb6 + 89d3446 commit c426453
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ import org.uqbar.project.wollok.wollokDsl.WFile
import org.uqbar.project.wollok.wollokDsl.WTest
import wollok.lib.AssertionException

import static extension org.uqbar.project.wollok.utils.XtendExtensions.*
import static extension org.uqbar.project.wollok.ui.utils.XTendUtilExtensions.*
import static extension org.uqbar.project.wollok.errorHandling.WollokExceptionExtensions.*
import static extension org.uqbar.project.wollok.lib.WollokSDKExtensions.*
import org.uqbar.project.wollok.interpreter.core.WollokObject

/**
* A test reporter that prints to console in JSON format.
* Used by mumuki, for example.
*
* @author jfernandes
* @author npasserini
*/
//TODO: it could be rendering the elapsed time for each test
// TODO: it could be rendering the elapsed time for each test
// TODO: This should be using our JSonWriter to simplify code and unify some conventions (e.g. stack trace formats).
class WollokJSONTestsReporter implements WollokTestsReporter {
var testPassed = 0
var testFailures = 0
Expand Down Expand Up @@ -81,13 +85,20 @@ class WollokJSONTestsReporter implements WollokTestsReporter {
name("message").value(assertionError.message)
name("file").value(resource.trimFragment.toString)
name("lineNumber").value(lineNumber)
name("stackTrace").value(assertionError.wollokException?.convertToString) // TODO: Test it and adjust it
name("stackTrace").beginArray
assertionError.wollokStackTrace.forEach [ element |
beginObject
name("contextDescription").value(element.call("contextDescription").asString)
name("location").value(element.call("location").asString)
endObject
]
endArray
endObject
endObject
]
testFailures++
}

override reportTestOk(WTest test) {
writer => [
beginObject
Expand Down Expand Up @@ -128,6 +139,14 @@ class WollokJSONTestsReporter implements WollokTestsReporter {
exception.wollokStackTrace
}

def getWollokStackTrace(AssertionException exception) {
// This is almost repeated in WollokServer and should be reviewed.
(exception.wollokException
.call("getStackTrace")
.asList.wrapped as List<WollokObject>)
.allButFirst
}

// ************************************************************************
// ** Accessors
// ************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.uqbar.project.wollok.WollokConstants
import org.uqbar.project.wollok.interpreter.WollokInterpreter
import org.uqbar.project.wollok.interpreter.core.WollokObject
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper
import org.uqbar.project.wollok.interpreter.debugger.XDebuggerOff
import org.uqbar.project.wollok.launch.Wollok
import org.uqbar.project.wollok.launch.WollokChecker
import org.uqbar.project.wollok.launch.WollokLauncherInterpreterEvaluator
Expand Down Expand Up @@ -117,7 +116,7 @@ class WollokServer extends AbstractHandler {
val String name = WollokConstants.SYNTHETIC_FILE
for (var i = 0; i < Integer.MAX_VALUE; i++) {
val syntheticUri = URI.createURI(name + i + "." + fileExtension)
if (resourceSet.getResource(syntheticUri, false) == null)
if (resourceSet.getResource(syntheticUri, false) === null)
return syntheticUri
}
throw new IllegalStateException()
Expand Down Expand Up @@ -146,19 +145,19 @@ class WollokServer extends AbstractHandler {
// ** Main
// ************************************************************************
def static void main(String[] args) {

var int port = 8080;
if(args.size() > 0){
try{

if (args.size() > 0) {
try {
println(args.get(0));
port = Integer.parseInt(args.get(0));
}catch(NumberFormatException e){
} catch (NumberFormatException e) {
port = 8080;
println("Using default port 8080");
}
}

new Server(port) => [
handler = new WollokServer
start
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.uqbar.project.wollok.adapter.mumuki

import org.uqbar.project.wollok.wollokDsl.WProgram

/**
* This adapter is enabled when running a mumuki program and disables the "void" expression validation.
* This is a hack and should be removed when we provide a better way of integration with external REPLs
* or query runners.
*/
class MumukiAdapter {
boolean enabled = false

def programStarted(WProgram it) {
if (name == "mumuki") enabled = true
}

def boolean ignoreVoidValidation() { enabled }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import org.eclipse.emf.common.util.EList
import org.eclipse.emf.ecore.EObject
import org.eclipse.osgi.util.NLS
import org.uqbar.project.wollok.Messages
import org.uqbar.project.wollok.adapter.mumuki.MumukiAdapter
import org.uqbar.project.wollok.interpreter.api.XInterpreterEvaluator
import org.uqbar.project.wollok.interpreter.context.EvaluationContext
import org.uqbar.project.wollok.interpreter.context.UnresolvableReference
import org.uqbar.project.wollok.interpreter.core.CallableSuper
import org.uqbar.project.wollok.interpreter.core.WCallable
import org.uqbar.project.wollok.interpreter.core.WollokObject
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper
import org.uqbar.project.wollok.interpreter.nativeobj.JavaWrapper
Expand Down Expand Up @@ -88,6 +90,7 @@ import static extension org.uqbar.project.wollok.utils.XTextExtensions.*
class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject> {
extension WollokBasicBinaryOperations = new WollokDeclarativeNativeBasicOperations
extension WollokBasicUnaryOperations = new WollokDeclarativeNativeUnaryOperations
extension MumukiAdapter = new MumukiAdapter

// caches
var Map<String, WeakReference<WollokObject>> numbersCache = newHashMap
Expand Down Expand Up @@ -136,7 +139,10 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>

def dispatch WollokObject evaluate(WPackage it) {}

def dispatch WollokObject evaluate(WProgram it) { elements.evalAll }
def dispatch WollokObject evaluate(WProgram it) {
programStarted
elements.evalAll
}

def dispatch WollokObject evaluate(WTest it) { elements.evalAll }

Expand Down Expand Up @@ -461,7 +467,8 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
throw newWollokExceptionAsJava(
NLS.bind(Messages.WollokDslValidator_REFERENCE_UNITIALIZED, memberTarget.sourceCode.trim))
}
if (target === getVoid(interpreter, call) && memberTarget !== null) {

if (target.isVoid(call) && memberTarget !== null && !ignoreVoidValidation) {
throw newWollokExceptionAsJava(
NLS.bind(Messages.WollokDslValidator_VOID_MESSAGES_CANNOT_BE_USED_AS_VALUES,
memberTarget.sourceCode.trim))
Expand All @@ -470,9 +477,9 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
parameters.forEach[param, i|param.validateVoidOperand(call.memberCallArguments.get(i))]
target.call(call.feature, parameters)
}

private def void validateVoidOperand(WollokObject o, WExpression expression) {
if (o !== null && o === getVoid(interpreter, o.behavior)) {
if (o !== null && o.isVoid(expression) && !ignoreVoidValidation) {
throw newWollokExceptionAsJava(
NLS.bind(Messages.WollokDslValidator_VOID_MESSAGES_CANNOT_BE_USED_AS_VALUES,
expression.sourceCode.trim))
Expand All @@ -496,7 +503,7 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
initializeReference
}
}

def dispatch void initializeReference(WNamedObject it) { createNamedObject(qualifiedName) }

def dispatch void initializeReference(WVariable it) { eContainer.eval }
Expand Down Expand Up @@ -533,7 +540,7 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
}

// ********************************************************************************************
// ** HELPER FOR message sends
// ** Helpers
// ********************************************************************************************
def dispatch evaluateTarget(WFeatureCall call) { throw new UnsupportedOperationException("Should not happen") }

Expand All @@ -548,5 +555,8 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
createNamedObject(classFinder.getCachedObject(context, qualifiedName), qualifiedName)
}
}

def dispatch isVoid(WollokObject object, EObject context) { object === getVoid(interpreter, context) }
def dispatch isVoid(CallableSuper call, EObject context) { false }
}

Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ class XtendExtensions {
get(index)
}

/**
* Returns a copy of the list with the first element removed,
* or an empty list if the received list is empty.
*/
static def <T> allButFirst(List<T> list) {
list.subList(1.min(list.size), list.size)
}

/**
* Returns a copy of the list with the last element removed,
* or an empty list if the received list is empty.
Expand Down

0 comments on commit c426453

Please sign in to comment.