Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update tests to use embedded configs instead of old style verify #21480

Description

@rupeshkumar92a-arch

Moved from #21441 (comment) at @romani's request.

#21441 converted RegexpOnFilenameCheckTest to verifyWithInlineConfigParser. A sweep of the whole test tree on current master shows the same problem remains in many other tests.

Per @romani: any Check with "Header" in its name cannot use inlined config, so HeaderCheckTest, RegexpHeaderCheckTest and MultiFileRegexpHeaderCheckTest are excluded from everything below (they account for a further 65 old-style calls and 39 config-less inputs that should stay as they are).

Old style verify(...) usage

107 call sites across 31 test classes. (Excludes AbstractModuleTestSupport itself, Mockito's verify, IndentationCheckTest's own private verify helper, and the Header checks.) 49 test classes still build configs in Java via createModuleConfig/createRootConfig.

Test class old-style verify calls
TranslationCheckTest 20
LineEndingCheckTest 16
OrderedPropertiesCheckTest 10
IndentationCheckTest 9
RegexpMultilineCheckTest 5
EmptyLineSeparatorCheckTest 5
UniquePropertiesCheckTest 4
TreeWalkerTest 4
NewlineAtEndOfFileCheckTest 3

and 22 more classes with 1-2 calls each: UnusedImports, UncommentedMain, SuppressWithPlainTextCommentFilter, PackageDeclaration, OuterTypeFilename, NoCodeInFile, JavadocLinkFirstOccurrence, Checker, RedundantImport, OneTopLevelClass, OneStatementPerLine, NonEmptyAtclauseDescription, MutableException, MultipleStringLiterals, LineLength, InnerTypeLast, IllegalType, IllegalInstantiation, EqualsHashCode, CustomImportOrder, AnnotationUseStyle, AllChecksTest.

Bad inputs

80 input files used by those old-style tests have no embedded config. Repo-wide, 292 input files under checks/ + filters/ (excluding checks/header/) do not start with a config block, out of 3916 Input* files scanned; the remaining config-less files are grammar/parser/main inputs that legitimately have none.

Per test class: Translation (33), OrderedProperties (10), LineEnding (10), Indentation (5), UniqueProperties (4), EmptyLineSeparator (4), TreeWalker (3), NewlineAtEndOfFile (3), NoCodeInFile (2), JavadocLinkFirstOccurrence (2), SuppressWithPlainTextCommentFilter (1), PackageDeclaration (1), NonEmptyAtclauseDescription (1), IllegalType (1).

Worst input directories overall: checks/indentation/indentation (157), checks/imports/importcontrol (26), filters/suppressionsloader (17), filters/suppressionxpathfilter (15), filters/suppressionfilter (10), checks/orderedproperties (10), checks/lineending (10).

Easiest wins first

18 call sites where the input already carries an embedded config, so only the test method needs changing, no input edits at all:

  • TreeWalkerTest:723
  • checks/annotation/AnnotationUseStyleCheckTest:102
  • checks/coding/EqualsHashCodeCheckTest:95
  • checks/coding/IllegalTypeCheckTest:293
  • checks/coding/MultipleStringLiteralsCheckTest:87
  • checks/coding/OneStatementPerLineCheckTest:164
  • checks/coding/PackageDeclarationCheckTest:201 (:151 moved to "Known exceptions" - see below; :201 done in Issue #21480: Convert PackageDeclarationCheckTest#testBeginTreeClear to embedded config #21482)
  • checks/design/InnerTypeLastCheckTest:95
  • checks/design/MutableExceptionCheckTest:86
  • checks/imports/CustomImportOrderCheckTest:381
  • checks/imports/RedundantImportCheckTest:74
  • checks/imports/UnusedImportsCheckTest:64
  • checks/indentation/IndentationCheckTest:4533
  • checks/javadoc/JavadocLinkFirstOccurrenceCheckTest:92
  • checks/sizes/LineLengthCheckTest:162
  • checks/whitespace/EmptyLineSeparatorCheckTest:122, :384

Good candidates for standalone issues, in increasing effort: LineEndingCheckTest (16). NoCodeInFileCheckTest and UniquePropertiesCheckTest were previously listed here too - both were wrong, see "Known exceptions" below.

Known exceptions (per @romani unless noted)

  • TranslationCheckTest, OrderedPropertiesCheckTest - operate on property files; an inlined header is not possible for these, so they stay old-style in full.
  • UniquePropertiesCheckTest - same family as the two above (all three are in InlineConfigParser.PERMANENT_SUPPRESSED_CHECKS, "Inlined config is not supported for non java files"), so it stays old-style in full too. Not one of @romani's original examples, but the same underlying restriction applies.
  • IndentationCheckTest - has its own way of handling the header check and trailing comments, so it needs special attention rather than a mechanical conversion.
  • NewlineAtEndOfFileCheckTest - one method needs to stay old-style since it operates on an empty file; the rest should be updated.
  • NoCodeInFileCheckTest - both remaining old-style methods (testBlank, testSingleLineComment) test a file with no text at all and a file containing only a single-line comment, respectively. The inline config format requires a /* ... */ block, which would either add text to the "no text" case or turn the "single-line comment only" case into a multi-line comment (already covered by testMultiLineComment) or a mix of both (already covered by testBothSingleLineAndMultiLineComment). Neither can be embedded without either breaking or duplicating what the test is meant to cover, so this class is not actually convertible - despite being listed as a "good candidate" above until this correction.
  • PackageDeclarationCheckTest#testEmptyFile (:151) - same "operates on a genuinely empty file" restriction as NewlineAtEndOfFileCheckTest and NoCodeInFileCheckTest#testBlank; it was wrongly listed in "Easiest wins" above. :201 (testBeginTreeClear) was convertible and is done in Issue #21480: Convert PackageDeclarationCheckTest#testBeginTreeClear to embedded config #21482, using the existing two-file verifyWithInlineConfigParser(filePath1, filePath2, expectedFromFile1, expectedFromFile2) overload since the two inputs already carried configs from earlier conversions.
  • RegexpOnFilenameCheckTest#testWithFileWithoutParent (the single verify left after Update RegexpOnFilenameCheckTest to use embedded configs #21441) needs a MockFile overriding getParent(), so it has to stay old-style too.

Given how many "empty/comment-only file" cases have turned up (3 so far, across 3 different classes), it's worth treating "input has no meaningful non-comment content to embed a config into" as its own standing exception category, not a one-off per class.

Blockers that need a decision

  1. Multi-file tests with 3+ inputs (EqualsHashCodeCheckTest, IllegalTypeCheckTest) - verifyWithInlineConfigParser only has 1-file and 2-file overloads today, so these need a new overload.
  2. Tests that generate inputs at runtime in a temp dir (RegexpMultilineCheckTest) - no file on disk to embed a config into.
  3. AnnotationUseStyleCheckTest#testNonTrimmedInput deliberately passes untrimmed property values (" ignore "); the inline config parser trims, so this one cannot be expressed as an embedded config.

Should these be filed as separate issues per test class, or tracked here as an umbrella?


Good example of migration #21482

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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions