-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # esql-code-coverage/pom.xml # esql-plugin/pom.xml # pom.xml
- Loading branch information
Showing
673 changed files
with
13,420 additions
and
1,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ esql-frontend/.project | |
.settings/ | ||
.classpath | ||
.project | ||
.idea | ||
*.iml | ||
sampleWorkspace/.scannerwork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/CheckMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.exxeta.iss.sonar.esql.checks.verifier; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Arrays; | ||
|
||
public class CheckMessage { | ||
private Integer line; | ||
private Double cost; | ||
private final Object check; | ||
private final String defaultMessage; | ||
private final Object[] messageArguments; | ||
private Boolean bypassExclusion; | ||
|
||
public CheckMessage(Object check, String message, Object... messageArguments) { | ||
this.check = check; | ||
this.defaultMessage = message; | ||
this.messageArguments = messageArguments; | ||
} | ||
|
||
public void setLine(int line) { | ||
this.line = line; | ||
} | ||
|
||
|
||
public Integer getLine() { | ||
return line; | ||
} | ||
|
||
public void setCost(double cost) { | ||
this.cost = cost; | ||
} | ||
|
||
public Double getCost() { | ||
return cost; | ||
} | ||
|
||
public void setBypassExclusion(boolean bypassExclusion) { | ||
this.bypassExclusion = bypassExclusion; | ||
} | ||
|
||
public boolean isBypassExclusion() { | ||
return bypassExclusion != null && bypassExclusion; | ||
} | ||
|
||
|
||
public Object getCheck() { | ||
return check; | ||
} | ||
|
||
public String getDefaultMessage() { | ||
return defaultMessage; | ||
} | ||
|
||
public Object[] getMessageArguments() { | ||
return messageArguments; | ||
} | ||
|
||
|
||
public String getText() { | ||
return formatDefaultMessage(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CheckMessage{" + | ||
"line=" + line + | ||
", cost=" + cost + | ||
", check=" + check + | ||
", defaultMessage='" + defaultMessage + '\'' + | ||
", messageArguments=" + Arrays.toString(messageArguments) + | ||
", bypassExclusion=" + bypassExclusion + | ||
'}'; | ||
} | ||
|
||
public String formatDefaultMessage() { | ||
if (messageArguments.length == 0) { | ||
return defaultMessage; | ||
} else { | ||
return MessageFormat.format(defaultMessage, messageArguments); | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...s-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/CheckMessagesVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.exxeta.iss.sonar.esql.checks.verifier; | ||
|
||
import com.google.common.collect.Ordering; | ||
import org.hamcrest.Matcher; | ||
import com.google.common.base.Objects; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.Iterator; | ||
|
||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* This class was copy&pasted from sslr-squid-bridge to avoid dependency on it | ||
* <p> | ||
* Helper class for testing checks without having to deploy them on a Sonar instance. | ||
* It can be used as following: | ||
* <pre>{@code | ||
* CheckMessagesVerifier.verify(messages) | ||
* .next().atLine(1).withMessage("foo") | ||
* .next().atLine(2).withMessage("bar") | ||
* .noMore(); | ||
* }</pre> | ||
* Strictly speaking this is just a wrapper over collection of {@link CheckMessage}, | ||
* which guarantees order of traversal. | ||
* | ||
* @since sslr-squid-bridge 2.1 | ||
*/ | ||
public final class CheckMessagesVerifier { | ||
|
||
private final Iterator<CheckMessage> iterator; | ||
private CheckMessage current; | ||
|
||
private static final Comparator<CheckMessage> ORDERING = (left, right) -> { | ||
if (Objects.equal(left.getLine(), right.getLine())) { | ||
return left.getDefaultMessage().compareTo(right.getDefaultMessage()); | ||
} else if (left.getLine() == null) { | ||
return -1; | ||
} else if (right.getLine() == null) { | ||
return 1; | ||
} else { | ||
return left.getLine().compareTo(right.getLine()); | ||
} | ||
}; | ||
|
||
private CheckMessagesVerifier(Collection<CheckMessage> messages) { | ||
iterator = Ordering.from(ORDERING).sortedCopy(messages).iterator(); | ||
} | ||
|
||
public static CheckMessagesVerifier verify(Collection<CheckMessage> messages) { | ||
return new CheckMessagesVerifier(messages); | ||
} | ||
|
||
public CheckMessagesVerifier next() { | ||
if (!iterator.hasNext()) { | ||
throw new AssertionError("\nExpected violation"); | ||
} | ||
current = iterator.next(); | ||
return this; | ||
} | ||
|
||
public void noMore() { | ||
if (iterator.hasNext()) { | ||
CheckMessage next = iterator.next(); | ||
throw new AssertionError("\nNo more violations expected\ngot: at line " + next.getLine()); | ||
} | ||
} | ||
|
||
private void checkStateOfCurrent() { | ||
if (current == null) { | ||
throw new IllegalStateException("Prior to this method you should call next()"); | ||
} | ||
} | ||
|
||
public CheckMessagesVerifier atLine(@Nullable Integer expectedLine) { | ||
checkStateOfCurrent(); | ||
if (!Objects.equal(expectedLine, current.getLine())) { | ||
throw assertionError(expectedLine, current.getLine()); | ||
} | ||
return this; | ||
} | ||
|
||
public CheckMessagesVerifier withMessage(String expectedMessage) { | ||
checkStateOfCurrent(); | ||
String actual = current.getText(); | ||
if (!actual.equals(expectedMessage)) { | ||
throw assertionError("\"" + expectedMessage + "\"", "\"" + actual + "\""); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Note that this method requires JUnit and Hamcrest. | ||
*/ | ||
CheckMessagesVerifier withMessageThat(Matcher<String> matcher) { | ||
checkStateOfCurrent(); | ||
String actual = current.getText(); | ||
assertThat(actual, matcher); | ||
return this; | ||
} | ||
|
||
/** | ||
* @since sslr-squid-bridge 2.3 | ||
*/ | ||
CheckMessagesVerifier withCost(Double expectedCost) { | ||
checkStateOfCurrent(); | ||
if (!Objects.equal(expectedCost, current.getCost())) { | ||
throw assertionError(expectedCost, current.getCost()); | ||
} | ||
return this; | ||
} | ||
|
||
private static AssertionError assertionError(@Nullable Object expected, @Nullable Object actual) { | ||
return new AssertionError("\nExpected: " + expected + "\ngot: " + actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/ExpectedIssuesParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestIssue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
esql-checks-test/src/main/java/com/exxeta/iss/sonar/esql/checks/verifier/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s-test/src/test/java/com/exxeta/iss/sonar/esql/checks/verifier/EsqlCheckVerifierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/AbstractDoNotUseFunctionCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ks/src/main/java/com/exxeta/iss/sonar/esql/check/BinaryOperatorSeparatedBySpaceCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.