all: add testing for compiler error messages

This is needed for some improvements I'm going to make next.

This commit also refactors error handling slightly to make it more
easily testable, this should hopefully not result in any actual changes
in behavior.
This commit is contained in:
Ayke van Laethem
2024-07-09 17:16:32 +02:00
committed by Ayke
parent 7ac1ca0ae2
commit 8a357af3d8
6 changed files with 141 additions and 19 deletions
+15
View File
@@ -0,0 +1,15 @@
package main
// #error hello
// )))
import "C"
func main() {
}
// TODO: this error should be relative to the current directory (so cgo.go
// instead of testdata/errors/cgo.go).
// ERROR: # command-line-arguments
// ERROR: testdata/errors/cgo.go:3:5: error: hello
// ERROR: testdata/errors/cgo.go:4:4: error: expected identifier or '('
+7
View File
@@ -0,0 +1,7 @@
package main
func main(var) { // syntax error
}
// ERROR: # command-line-arguments
// ERROR: syntax.go:3:11: expected ')', found 'var'
+12
View File
@@ -0,0 +1,12 @@
package main
func main() {
var a int
a = "foobar"
nonexisting()
}
// ERROR: # command-line-arguments
// ERROR: types.go:5:6: cannot use "foobar" (untyped string constant) as int value in assignment
// ERROR: types.go:6:2: undefined: nonexisting
// ERROR: types.go:4:6: a declared and not used