mirror of
https://github.com/golang/go
synced 2024-11-19 02:44:44 -07:00
d88f79806b
If a package has an error that makes it completely unparseable, such as containing a .go file with no "package" statement, the error was previously unreported. Such errors would manifest as other errors. Fixes golang/go#31712 Change-Id: I11b8d0e2e4d64b03fbcb4c35e7f0b02fccc83fad GitHub-Last-Rev: 1581cbe36c269dd964f0b9226dbd63b1650c2a5b GitHub-Pull-Request: golang/tools#102 Reviewed-on: https://go-review.googlesource.com/c/tools/+/177605 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package source
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseErrorMessage(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
expectedFileName string
|
|
expectedLine int
|
|
expectedColumn int
|
|
}{
|
|
{
|
|
name: "from go list output",
|
|
in: "\nattributes.go:13:1: expected 'package', found 'type'",
|
|
expectedFileName: "attributes.go",
|
|
expectedLine: 13,
|
|
expectedColumn: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
spn := parseDiagnosticMessage(tt.in)
|
|
fn, err := spn.URI().Filename()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if !strings.HasSuffix(fn, tt.expectedFileName) {
|
|
t.Errorf("expected filename with suffix %v but got %v", tt.expectedFileName, fn)
|
|
}
|
|
|
|
if !spn.HasPosition() {
|
|
t.Fatalf("expected span to have position")
|
|
}
|
|
|
|
pos := spn.Start()
|
|
if pos.Line() != tt.expectedLine {
|
|
t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line())
|
|
}
|
|
|
|
if pos.Column() != tt.expectedColumn {
|
|
t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line())
|
|
}
|
|
})
|
|
}
|
|
}
|