Package org.renjin

Source Code of org.renjin.AbstractMicroTest

package org.renjin;

import org.junit.Before;
import org.junit.BeforeClass;
import org.renjin.eval.EvalException;
import org.renjin.primitives.Deparse;
import org.renjin.primitives.Identical;
import org.renjin.script.RenjinScriptEngine;
import org.renjin.script.RenjinScriptEngineFactory;
import org.renjin.sexp.SEXP;

import javax.script.ScriptEngine;
import javax.script.ScriptException;

public abstract class AbstractMicroTest {

  public static RenjinScriptEngine engine;

  @BeforeClass
  public static void setupScriptEngine() {
    engine = new RenjinScriptEngineFactory().getScriptEngine();
  }

  @Before
  public void cleanUpGlobalEnvironment() {
    engine.getSession().getGlobalEnvironment().clear();
  }

  protected final void assertIdentical(String x, String y) {
    SEXP xexp;
    try {
      xexp = (SEXP)engine.eval(x);
    } catch (ScriptException e) {
      throw new RuntimeException("Error evaluating: " + x, e);
    }

    SEXP yexp = null;
    try {
      yexp = (SEXP)engine.eval(y);
    } catch (ScriptException e) {
      throw new RuntimeException("Error evaluating: " + y, e);
    }

    if(!Identical.identical(xexp, yexp)) {
      throw new AssertionError("Expecting '" + y + "', got: '" +
        Deparse.deparse(engine.getTopLevelContext(), xexp, 80, false, 0, 0) + "'");
    }
  }

}
TOP

Related Classes of org.renjin.AbstractMicroTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.