mgechev / mgechev/revive

extend testing machinery to allow more precise checks

Open
#424 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted low priority
Dominant language
Go
Stars
5.6k
Forks
330
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Rules are tested through a tiny mechanism where rules are executed on source files with annotations describing the expected failures.
For example:

```go
package fixtures

func foo(a, b, c, d int) {
a = 1.0 // ignore
b = "ignore"
c = 2 // ignore
println("lit", 12) // MATCH /avoid magic numbers like '12', create a named constant for it/
if a == 12.50 { // MATCH /avoid magic numbers like '12.50', create a named constant for it/
if b == "lit" {
c = "lit" // MATCH /string literal "lit" appears, at least, 3 times, create a named constant for it/
}
for i := 0; i < 1; i++ {
println("lit")
}
}
}
```

The test machinery will check if the rule produced a failure at the line annotated with `// MATCH` and will also check that the message of the failure matches that of the annotation.

This approach works fine for almost all cases but it has its limitations: only the message attribute of the failure can be checked. We have no mean to check other attributes of the failure (for example, testing the fix for #416 needs to check that a failure has a certain confidence)

It could be interesting to extend the current testing mechanism to allow checking on any failure property

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the annotation-based rule testing machinery described in the issue and inspect how it currently compares failure messages. Review the failure properties needed by the fix for #416, then extend the checks so tests can assert properties beyond the message while preserving existing annotations and message checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.