Search in sources :

Example 11 with RuntimeData

use of org.jacoco.core.runtime.RuntimeData in project jacoco by jacoco.

the class AgentTest method startup_should_log_exception.

@Test
public void startup_should_log_exception() throws Exception {
    final Exception expected = new Exception();
    Agent agent = new Agent(options, this) {

        @Override
        IAgentOutput createAgentOutput() {
            return new IAgentOutput() {

                public void startup(AgentOptions options, RuntimeData data) throws Exception {
                    throw expected;
                }

                public void shutdown() {
                }

                public void writeExecutionData(boolean reset) {
                }
            };
        }
    };
    agent.startup();
    assertSame(expected, loggedException);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) IAgentOutput(org.jacoco.agent.rt.internal.output.IAgentOutput) IOException(java.io.IOException) InstanceNotFoundException(javax.management.InstanceNotFoundException) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Example 12 with RuntimeData

use of org.jacoco.core.runtime.RuntimeData in project jacoco by jacoco.

the class FileOutputTest method testInvalidDestFile.

@Test(expected = IOException.class)
public void testInvalidDestFile() throws Exception {
    AgentOptions options = new AgentOptions();
    options.setDestfile(folder.newFolder("folder").getAbsolutePath());
    FileOutput controller = new FileOutput();
    // Startup should fail as the file can not be created:
    controller.startup(options, new RuntimeData());
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) FileOutput(org.jacoco.agent.rt.internal.output.FileOutput) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Example 13 with RuntimeData

use of org.jacoco.core.runtime.RuntimeData in project dspot by STAMP-project.

the class JacocoExecutor method executeJacoco.

public CoverageResults executeJacoco(CtType<?> testClass) {
    final String testClassesDirectory = this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
    final RuntimeData data = new RuntimeData();
    final ExecutionDataStore executionData = new ExecutionDataStore();
    final SessionInfoStore sessionInfos = new SessionInfoStore();
    URLClassLoader classLoader;
    try {
        classLoader = new URLClassLoader(new URL[] { new File(testClassesDirectory).toURI().toURL() }, this.internalClassLoader);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    final String resource = testClass.getQualifiedName().replace('.', '/') + ".class";
    try {
        this.internalClassLoader.addDefinition(testClass.getQualifiedName(), IOUtils.toByteArray(classLoader.getResourceAsStream(resource)));
        runtime.startup(data);
        final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass);
        if (!listener.getFailingTests().isEmpty()) {
            LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + listener.getFailingTests().stream().map(Failure::toString).collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
        }
        data.collect(executionData, sessionInfos, false);
        runtime.shutdown();
        clearCache(this.internalClassLoader);
        return coverageResults(executionData);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) MalformedURLException(java.net.MalformedURLException) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) URLClassLoader(java.net.URLClassLoader) TestListener(fr.inria.stamp.test.listener.TestListener) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 14 with RuntimeData

use of org.jacoco.core.runtime.RuntimeData in project dspot by STAMP-project.

the class JacocoExecutor method executeJacoco.

public Map<String, CoverageResults> executeJacoco(CtType<?> testClass, Collection<String> methodNames) {
    final String testClassesDirectory = this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
    final String classesDirectory = this.program.getProgramDir() + "/" + this.program.getClassesDir();
    URLClassLoader classLoader;
    try {
        classLoader = new URLClassLoader(new URL[] { new File(testClassesDirectory).toURI().toURL() }, this.internalClassLoader);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    final String resource = testClass.getQualifiedName().replace('.', '/') + ".class";
    try {
        this.internalClassLoader.addDefinition(testClass.getQualifiedName(), IOUtils.toByteArray(classLoader.getResourceAsStream(resource)));
        final RuntimeData data = new RuntimeData();
        this.runtime.startup(data);
        final JacocoListener jacocoListener = new JacocoListener(data, classesDirectory);
        final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass, methodNames, jacocoListener);
        if (!listener.getFailingTests().isEmpty()) {
            LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + listener.getFailingTests().stream().map(Failure::toString).collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
        }
        this.runtime.shutdown();
        clearCache(this.internalClassLoader);
        return jacocoListener.getCoverageResultsMap();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RuntimeData(org.jacoco.core.runtime.RuntimeData) URLClassLoader(java.net.URLClassLoader) TestListener(fr.inria.stamp.test.listener.TestListener) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

RuntimeData (org.jacoco.core.runtime.RuntimeData)14 AgentOptions (org.jacoco.core.runtime.AgentOptions)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 File (java.io.File)4 Before (org.junit.Before)4 FileOutput (org.jacoco.agent.rt.internal.output.FileOutput)3 TestListener (fr.inria.stamp.test.listener.TestListener)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ExceptionRecorder (org.jacoco.agent.rt.internal.ExceptionRecorder)2 IAgentOutput (org.jacoco.agent.rt.internal.output.IAgentOutput)2 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)2 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)2 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)2 Instrumenter (org.jacoco.core.instr.Instrumenter)2 IRuntime (org.jacoco.core.runtime.IRuntime)2 LoggerRuntime (org.jacoco.core.runtime.LoggerRuntime)2