Search in sources :

Example 1 with BPjsCodeEvaluationException

use of il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException in project BPjs by bThink-BGU.

the class EngineExceptionTest method testInvalidBSyncCall.

@Test
public void testInvalidBSyncCall() throws InterruptedException {
    BProgram sut = new BProgram("bad") {

        @Override
        protected void setupProgramScope(Scriptable scope) {
            evaluate("var i=0;\n var j=42;\n var k=5; bsync({request:bp.Event(\"A\")});", "hardcoded");
        }
    };
    try {
        new BProgramRunner(sut).run();
        fail("System should have thrown an error due to bsync called outside of a BThread.");
    } catch (BPjsCodeEvaluationException exp) {
        assertEquals(3, exp.getLineNumber());
        assertEquals("hardcoded", exp.getSourceName());
        assertTrue(exp.getMessage().contains("bsync"));
        // make sure this is the friendly message
        assertTrue(exp.getMessage().contains("Did you forget"));
        assertEquals(1, exp.getScriptStackTrace().size());
    }
}
Also used : BPjsCodeEvaluationException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) Scriptable(org.mozilla.javascript.Scriptable) Test(org.junit.Test)

Example 2 with BPjsCodeEvaluationException

use of il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException in project BPjs by bThink-BGU.

the class EngineExceptionTest method testInvalidJavascript.

@Test
public void testInvalidJavascript() throws InterruptedException {
    BProgram sut = new BProgram("bad") {

        @Override
        protected void setupProgramScope(Scriptable scope) {
            evaluate("var j=9\n" + "#This isn't a javascript line.\n" + "var o=0;", "hardcoded");
        }
    };
    try {
        new BProgramRunner(sut).run();
        fail("System should have thrown an error due to uncompilable Javascript code.");
    } catch (BPjsCodeEvaluationException exp) {
        assertEquals(2, exp.getLineNumber());
        assertEquals(1, exp.getColumnNumber());
        assertEquals("#This isn't a javascript line.", exp.getLineSource());
    }
}
Also used : BPjsCodeEvaluationException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) Scriptable(org.mozilla.javascript.Scriptable) Test(org.junit.Test)

Aggregations

BPjsCodeEvaluationException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException)2 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)2 Test (org.junit.Test)2 Scriptable (org.mozilla.javascript.Scriptable)2