golang/go

test: errorcheck support for intraline errors

Open

#19,577 opened on Mar 16, 2017

View on GitHub
 (8 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
FeatureRequestNeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Now that the compiler supports reporting column position for errors, we need a mechanism in test/run.go for testing this.

I propose we use /* ERROR "foo" */ placed just before where we expect the error to be emitted, except to allow for white space in between.

E.g., for #19576, the test would be

package p

func f() int { /* ERROR "missing return" */ }

Rationale:

  • run.go currently only looks for // ERROR annotations, which can only occur at the end of the line, so there's no risk of collision using /* ERROR */ for column-precise error matching.

  • Not explicitly having to write column numbers into the errors makes them easier to maintain, just like how we don't currently have to worry about line numbers.

  • We emit errors at the start of tokens, so putting the error expectation before that lets us unambiguously match it to an expected column. Putting afterwards would require more complex logic for figuring out how many characters to rewind past.

  • Allowing whitespace after the error comment allows the code to be gofmt'd.

/cc @griesemer @ianlancetaylor @bradfitz

Contributor guide