Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend testing machinery to allow more precise checks #424

Open
chavacava opened this issue May 20, 2020 · 0 comments
Open

extend testing machinery to allow more precise checks #424

chavacava opened this issue May 20, 2020 · 0 comments

Comments

@chavacava
Copy link
Collaborator

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

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

@chavacava chavacava changed the title extend testing machinery to allow more precise cheks extend testing machinery to allow more precise checks May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant