Skip to content

Commit

Permalink
Merge pull request #1534 from ivangalkin/fix_1521
Browse files Browse the repository at this point in the history
Fix SensorDescriptors for CxxCompiler{Gcc|Vc}Sensor
  • Loading branch information
guwirth authored Aug 9, 2018
2 parents f801e04 + 862403f commit f72c496
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public CxxCompilerGccSensor(CxxLanguage language) {

@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name(getLanguage().getName() + " CxxCompilerGccSensor").onlyOnLanguage(getLanguage().getKey())
.createIssuesForRuleRepositories(getReportPathKey()).onlyWhenConfiguration(new IsGccParserConfigured());
descriptor
.name(getLanguage().getName() + " CxxCompilerGccSensor")
.onlyOnLanguage(getLanguage().getKey())
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(new IsGccParserConfigured());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public CxxCompilerVcSensor(CxxLanguage language) {

@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name(getLanguage().getName() + " CxxCompilerVcSensor").onlyOnLanguage(getLanguage().getKey())
.createIssuesForRuleRepositories(getReportPathKey()).onlyWhenConfiguration(new IsVcParserConfigured());
descriptor
.name(getLanguage().getName() + " CxxCompilerVcSensor")
.onlyOnLanguage(getLanguage().getKey())
.createIssuesForRuleRepository(getRuleRepositoryKey())
.onlyWhenConfiguration(new IsVcParserConfigured());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import java.util.Optional;
import javax.xml.stream.XMLStreamException;
import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.core.api.SoftAssertions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.batch.sensor.internal.SensorContextTester;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.profiles.RulesProfile;
Expand Down Expand Up @@ -140,4 +143,32 @@ public void shouldReportWarningsWithoutFileAndLineInformation() throws XMLStream

Assert.assertTrue(warnings.containsAll(sensor.savedWarnings));
}

@Test
public void sensorDescriptorGcc() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
CxxCompilerGccSensor sensor = new CxxCompilerGccSensor(language);
sensor.describe(descriptor);

SoftAssertions softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo(language.getName() + " CxxCompilerGccSensor");
softly.assertThat(descriptor.languages()).containsOnly(language.getKey());
softly.assertThat(descriptor.ruleRepositories())
.containsOnly(CxxCompilerGccRuleRepository.getRepositoryKey(language));
softly.assertAll();
}

@Test
public void sensorDescriptorVc() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
CxxCompilerVcSensor sensor = new CxxCompilerVcSensor(language);
sensor.describe(descriptor);

SoftAssertions softly = new SoftAssertions();
softly.assertThat(descriptor.name()).isEqualTo(language.getName() + " CxxCompilerVcSensor");
softly.assertThat(descriptor.languages()).containsOnly(language.getKey());
softly.assertThat(descriptor.ruleRepositories())
.containsOnly(CxxCompilerVcRuleRepository.getRepositoryKey(language));
softly.assertAll();
}
}

0 comments on commit f72c496

Please sign in to comment.