Search in sources :

Example 26 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapWhileCondition.

@Test
public void shouldWrapWhileCondition() throws Exception {
    StringBuilder script = new StringBuilder("var x = 1;\n");
    script.append("while (x > 0)\n");
    script.append("  x--;\n");
    runScript(script.toString(), false);
    ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
    assertThat(coverageData.get("evalTrue"), equalTo(1.0));
    assertThat(coverageData.get("evalFalse"), equalTo(1.0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 27 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldHandleTwoSeparateConditions.

@Test
public void shouldHandleTwoSeparateConditions() throws Exception {
    StringBuilder script = new StringBuilder("function test(x) {\n");
    script.append("  if (x < 0)\n");
    script.append("    ;\n");
    script.append("  else if (x > 100)\n");
    script.append("    ;\n");
    script.append("};\n");
    runScript(script.toString(), false);
    ScriptObjectMirror coverageData1 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
    ScriptObjectMirror coverageData2 = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[4][1]");
    assertThat(coverageData1.callMember("covered"), equalTo(false));
    assertThat(coverageData2.callMember("covered"), equalTo(false));
    invocable.invokeFunction("test", -1);
    assertThat(coverageData1.callMember("covered"), equalTo(false));
    assertThat(coverageData2.callMember("covered"), equalTo(false));
    invocable.invokeFunction("test", 1);
    assertThat(coverageData1.callMember("covered"), equalTo(true));
    assertThat(coverageData2.callMember("covered"), equalTo(false));
    invocable.invokeFunction("test", 1000);
    assertThat(coverageData1.callMember("covered"), equalTo(true));
    assertThat(coverageData2.callMember("covered"), equalTo(true));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 28 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapWhileConditionVariable.

@Test
public void shouldWrapWhileConditionVariable() throws Exception {
    StringBuilder script = new StringBuilder("var x = true;\n");
    script.append("while (x)\n");
    script.append("  x = false;\n");
    runScript(script.toString(), false);
    ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
    assertThat(coverageData.get("evalTrue"), equalTo(1.0));
    assertThat(coverageData.get("evalFalse"), equalTo(1.0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Example 29 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.

the class EnginesController method installEngine.

private void installEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("install", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
    }, errorCallback), errorCallback);
}
Also used : RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) LoggerFactory(org.slf4j.LoggerFactory) AppsController(org.phoenicis.javafx.controller.apps.AppsController) ArrayList(java.util.ArrayList) TypeDTO(org.phoenicis.repository.dto.TypeDTO) EnginesSource(org.phoenicis.engines.EnginesSource) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) URI(java.net.URI) Path(java.nio.file.Path) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Files(java.nio.file.Files) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) RepositoryManager(org.phoenicis.repository.RepositoryManager) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) File(java.io.File) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) List(java.util.List) EngineDTO(org.phoenicis.engines.dto.EngineDTO) Optional(java.util.Optional) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ThemeManager(org.phoenicis.javafx.views.common.ThemeManager) EnginesView(org.phoenicis.javafx.views.mainwindow.engines.EnginesView) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 30 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.

the class EnginesController method deleteEngine.

private void deleteEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("delete", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
    }, errorCallback), errorCallback);
}
Also used : RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) LoggerFactory(org.slf4j.LoggerFactory) AppsController(org.phoenicis.javafx.controller.apps.AppsController) ArrayList(java.util.ArrayList) TypeDTO(org.phoenicis.repository.dto.TypeDTO) EnginesSource(org.phoenicis.engines.EnginesSource) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) URI(java.net.URI) Path(java.nio.file.Path) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Files(java.nio.file.Files) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) RepositoryManager(org.phoenicis.repository.RepositoryManager) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) File(java.io.File) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) List(java.util.List) EngineDTO(org.phoenicis.engines.dto.EngineDTO) Optional(java.util.Optional) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ThemeManager(org.phoenicis.javafx.views.common.ThemeManager) EnginesView(org.phoenicis.javafx.views.mainwindow.engines.EnginesView) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Aggregations

ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)76 Test (org.junit.Test)34 InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)28 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)28 Consumer (java.util.function.Consumer)27 List (java.util.List)23 LoggerFactory (org.slf4j.LoggerFactory)20 File (java.io.File)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)14 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 RegistryParameter (org.phoenicis.containers.wine.parameters.RegistryParameter)10 LibraryManager (org.phoenicis.library.LibraryManager)10 ShortcutManager (org.phoenicis.library.ShortcutManager)10 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)10 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)10 RegistryWriter (org.phoenicis.win32.registry.RegistryWriter)10 URI (java.net.URI)8