Skip to content

Commit 74fc3ed

Browse files
committed
add tests
1 parent a37afa3 commit 74fc3ed

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/main/java/com/github/_1c_syntax/bsl/sonar/language/BSLLanguageServerRuleDefinition.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,13 @@ private void setUpRuleParams(NewRule newRule) {
167167
.forEach((DiagnosticParameterInfo diagnosticParameter) -> {
168168
var ruleParamType = getRuleParamType(diagnosticParameter.getType());
169169
if (ruleParamType == null) {
170-
LOGGER.error("Can't cast rule param type {} for rule {}",
171-
diagnosticParameter.getType(), newRule.key());
172-
return;
170+
LOGGER.error("Can't cast rule param type {} for rule {}", diagnosticParameter.getType(), newRule.key());
171+
} else {
172+
var newParam = newRule.createParam(diagnosticParameter.getName());
173+
newParam.setType(ruleParamType);
174+
newParam.setDescription(diagnosticParameter.getDescription());
175+
newParam.setDefaultValue(diagnosticParameter.getDefaultValue().toString());
173176
}
174-
175-
var newParam = newRule.createParam(diagnosticParameter.getName());
176-
newParam.setType(ruleParamType);
177-
newParam.setDescription(diagnosticParameter.getDescription());
178-
newParam.setDefaultValue(diagnosticParameter.getDefaultValue().toString());
179177
});
180178
}
181179

src/test/java/com/github/_1c_syntax/bsl/sonar/LanguageServerDiagnosticsLoaderSensorTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void test_execute() {
5757
var fileName = "src/test.bsl";
5858
var inputFile = Tools.inputFileBSL(fileName, BASE_DIR);
5959

60-
var sonarRuntime = SonarRuntimeImpl.forSonarLint(Version.create(7, 9));
60+
var sonarRuntime = SonarRuntimeImpl.forSonarLint(Version.create(25, 7));
6161
var context = SensorContextTester.create(BASE_DIR);
6262
context.setRuntime(sonarRuntime);
6363
context.settings().setProperty(
@@ -79,4 +79,33 @@ void test_execute() {
7979
assertThat(context.isCancelled()).isFalse();
8080

8181
}
82+
83+
@Test
84+
void test_error() {
85+
86+
var fileName = "src/test6.bsl";
87+
var inputFile = Tools.inputFileBSL(fileName, BASE_DIR);
88+
89+
var sonarRuntime = SonarRuntimeImpl.forSonarLint(Version.create(25, 4));
90+
var context = SensorContextTester.create(BASE_DIR);
91+
context.setRuntime(sonarRuntime);
92+
context.settings().setProperty(
93+
"sonar.bsl.languageserver.reportPaths",
94+
".bsl-language-server.json, fake.json, highlight.bsl");
95+
context.fileSystem().add(inputFile);
96+
97+
var activeRules = new ActiveRulesBuilder()
98+
.addRule(new NewActiveRule.Builder()
99+
.setRuleKey(RuleKey.of(BSLLanguageServerRuleDefinition.REPOSITORY_KEY, "OneStatementPerLine"))
100+
.setName("OneStatementPerLine")
101+
.build())
102+
.build();
103+
context.setActiveRules(activeRules);
104+
105+
var diagnosticsLoaderSensor = new LanguageServerDiagnosticsLoaderSensor(context);
106+
diagnosticsLoaderSensor.execute(context);
107+
108+
assertThat(context.isCancelled()).isFalse();
109+
110+
}
82111
}

0 commit comments

Comments
 (0)