PSA: Test modes

100 views
Skip to first unread message

Tor Norbye

unread,
Aug 12, 2021, 7:49:06 PM8/12/21
to lint-dev
Hi everyone,
it looks like 7.1.0-alpha08 is out now, and one of the things that includes in lint is new support in the lint testing infrastructure for "source modifying test modes".

Put briefly, this will run your tests repeatedly, and will make some "compatible edits" to the source files that should not affect the outcome, to make sure that the lint checks are handling this correctly.

For example, it will insert unnecessary parentheses. Parentheses show up in the AST, so if your check does something simple like "if (node.uastParent is UQualifiedExpression)" this can return false if there's an unnecessary parenthesis there.

Lint has a bunch of these new test modes -- for example, replacing all symbols with fully qualified names, another which replaces all symbols with import aliases (for Kotlin unit tests), another which replaces all types with type aliases (for Kotlin unit tests), another which switches between method block bodies and expression bodies,  etc.

There are additional test modes coming in some upcoming canaries -- for example, one which adds miscellaneous whitespace (which is most relevant for quickfix tests), and another which replaces if statements with when statements to make sure you handle USwitchExpression if you're already handling UIfExpression, and so on.

There is documentation for this here:

But do try upgrading to the latest canaries and see how your tests fare. The idea here is to catch bugs where your lint checks have false positives. Note that you can always turn off the test modes if (a) your detector is doing something very specific where the test mode doesn't apply, (b) you don't have time to deal with this now but you do want to use the latest lint for the many other recent changes, or (c) you've found a bug in the test mode support -- please let us know about those.

-- Tor

Reply all
Reply to author
Forward
0 new messages