Skip to content

Implement sorting in AbstractModuleTestSupport#verifyViolations #12847

Description

@stoyanK7

Identified at #12151 (comment)

Whenever verifyFilterWithInlineConfigParser() is called, it creates a list of violationsWithoutFilters, sorts it and passes it onto verifyViolations()

Collections.sort(violationsWithoutFilters);
verifyViolations(configWithoutFilters, filePath, violationsWithoutFilters);

The way those violationsWithoutFilters(TestInputViolation objects) are sorted is by line number:

public int compareTo(TestInputViolation testInputViolation) {
return Integer.compare(lineNo, testInputViolation.lineNo);
}

verifyViolations() compares that sorted list against actualViolations

final List<String> actualViolations = getActualViolationsForFile(config, file);

for (int index = 0; index < actualViolations.size(); index++) {
assertWithMessage("Actual and expected violations differ.")
.that(actualViolations.get(index))
.matches(testInputViolations.get(index).toRegex());


This created an issue at #12151 (comment) when there are 2 or more violations per line. See how the violations on line 33 are not matching:
image
image


A temporary hack was implemented at #12151 in SuppressWithNearbyTextFilterTest to make testNearbyTextPattern pass by sorting actualViolations before the assertion happens. This hack should be removed after this issue is resolved.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions