Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore measures for tests that can be saved because they have been added already #971

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.plugins.cxx.CxxLanguage;
import org.sonar.plugins.cxx.CxxPlugin;
import static org.sonar.plugins.cxx.coverage.CxxCoverageSensor.LOG;
import org.sonar.plugins.cxx.utils.StaxParser;

/**
Expand Down Expand Up @@ -154,40 +156,98 @@ private void simpleMode(final SensorContext context, List<TestCase> testcases)
double testsPassed = testsCount - testsErrors - testsFailures;
double successDensity = testsPassed * PERCENT_BASE / testsCount;

context.<Integer>newMeasure()
.forMetric(CoreMetrics.TESTS)
.on(context.module())
.withValue(testsCount)
.save();
try
{
context.<Integer>newMeasure()
.forMetric(CoreMetrics.TESTS)
.on(context.module())
.withValue(testsCount)
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure TESTS : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}

try
{
context.<Integer>newMeasure()
.forMetric(CoreMetrics.TEST_ERRORS)
.on(context.module())
.withValue(testsErrors)
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure TEST_ERRORS : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}

try
{
context.<Integer>newMeasure()
.forMetric(CoreMetrics.TEST_FAILURES)
.on(context.module())
.withValue(testsFailures)
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure TEST_FAILURES : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}

try
{
context.<Integer>newMeasure()
.forMetric(CoreMetrics.SKIPPED_TESTS)
.on(context.module())
.withValue(testsSkipped)
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure SKIPPED_TESTS : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}

try
{
context.<Double>newMeasure()
.forMetric(CoreMetrics.TEST_SUCCESS_DENSITY)
.on(context.module())
.withValue(ParsingUtils.scaleValue(successDensity))
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure TEST_SUCCESS_DENSITY : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}

try
{
context.<Long>newMeasure()
.forMetric(CoreMetrics.TEST_EXECUTION_TIME)
.on(context.module())
.withValue(testsTime)
.save();
} catch(Exception ex) {
LOG.error("Cannot save measure TEST_EXECUTION_TIME : '{}', ignoring measure", ex.getMessage());
if (!settings.getBoolean(CxxPlugin.ERROR_RECOVERY_KEY)) {
LOG.info("Recovery is disabled, failing analysis.");
throw ex;
}
}
} else {
LOG.debug("The reports contain no testcases");
}

}

File transformReport(File report)
Expand Down