Skip to content

Commit

Permalink
Adjust end line and column expectations in lint and breaking tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversun9 authored Sep 13, 2024
1 parent e8e776e commit 6df73b9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"

"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/stretchr/testify/assert"
)

Expand All @@ -27,9 +26,13 @@ func NewFileAnnotationNoLocationOrPath(
t *testing.T,
typeString string,
) bufanalysis.FileAnnotation {
return NewFileAnnotationNoLocation(
return NewFileAnnotation(
t,
"",
0,
0,
0,
0,
typeString,
)
}
Expand All @@ -45,10 +48,10 @@ func NewFileAnnotationNoLocation(
return NewFileAnnotation(
t,
path,
0,
0,
0,
0,
1,
1,
1,
1,
typeString,
)
}
Expand Down Expand Up @@ -113,8 +116,8 @@ func AssertFileAnnotationsEqual(
actual = normalizeFileAnnotations(t, actual)
if !assert.Equal(
t,
slicesext.Map(expected, bufanalysis.FileAnnotation.String),
slicesext.Map(actual, bufanalysis.FileAnnotation.String),
expected,
actual,
) {
t.Log("If actuals are correct, change expectations to the following:")
for _, annotation := range actual {
Expand Down
42 changes: 21 additions & 21 deletions private/bufpkg/bufcheck/breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func TestRunBreakingEnumSameType(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "2.proto", 17, 1, 19, 2, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 5, 1, 7, 2, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 17, 1, 19, 2, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 26, 3, 26, 52, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 26, 3, 26, 38, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "4.proto", 11, 1, 13, 2, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "4.proto", 29, 3, 29, 52, "ENUM_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "4.proto", 29, 3, 29, 36, "ENUM_SAME_TYPE"),
)
}

Expand Down Expand Up @@ -148,9 +148,9 @@ func TestRunBreakingExtensionMessageNoDelete(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "1.proto", 30, 3, 36, 4, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 30, 3, 36, 4, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 49, 1, 53, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 79, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 79, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 79, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 81, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 81, 2, "EXTENSION_MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 75, 1, 81, 2, "EXTENSION_MESSAGE_NO_DELETE"),
)
}

Expand Down Expand Up @@ -225,7 +225,7 @@ func TestRunBreakingFieldSameCardinality(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "1.proto", 22, 7, 22, 20, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 23, 7, 23, 22, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 24, 7, 24, 21, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 10, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 33, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 40, 5, 40, 28, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 41, 5, 41, 26, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 42, 5, 42, 21, "FIELD_SAME_CARDINALITY"),
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestRunBreakingFieldSameCType(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "1.proto", 23, 21, 23, 33, "FIELD_SAME_CPP_STRING_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 49, 28, 49, 48, "FIELD_SAME_CPP_STRING_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 50, 28, 50, 42, "FIELD_SAME_CPP_STRING_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 58, 32, 58, 36, "FIELD_SAME_CPP_STRING_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 58, 32, 58, 44, "FIELD_SAME_CPP_STRING_TYPE"),
)
}

Expand Down Expand Up @@ -554,8 +554,8 @@ func TestRunBreakingFieldSameLabel(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "1.proto", 24, 7, 24, 21, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 24, 7, 24, 21, "FIELD_WIRE_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 24, 7, 24, 21, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 10, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 10, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 33, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 33, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 40, 5, 40, 28, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 40, 5, 40, 28, "FIELD_WIRE_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 40, 5, 40, 28, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
Expand Down Expand Up @@ -779,8 +779,8 @@ func TestRunBreakingFieldWireCompatibleType(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "2.proto", 80, 3, 80, 6, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 85, 3, 85, 9, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 89, 12, 89, 15, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 6, 3, 6, 7, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 7, 3, 7, 7, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 6, 3, 6, 10, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 7, 3, 7, 10, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 15, 5, 15, 12, "FIELD_WIRE_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 23, 3, 23, 9, "FIELD_WIRE_COMPATIBLE_TYPE"),
)
Expand All @@ -803,7 +803,7 @@ func TestRunBreakingFieldWireJSONCompatibleCardinality(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "1.proto", 22, 7, 22, 20, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 23, 7, 23, 22, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 24, 7, 24, 21, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 10, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 32, 7, 32, 33, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 40, 5, 40, 28, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 41, 5, 41, 26, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 42, 5, 42, 21, "FIELD_WIRE_JSON_COMPATIBLE_CARDINALITY"),
Expand Down Expand Up @@ -846,8 +846,8 @@ func TestRunBreakingFieldWireJSONCompatibleType(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "2.proto", 88, 3, 88, 9, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 92, 12, 92, 15, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 93, 3, 93, 8, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 6, 3, 6, 7, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 7, 3, 7, 7, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 6, 3, 6, 10, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 7, 3, 7, 10, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 14, 5, 14, 10, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 15, 5, 15, 12, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "3.proto", 16, 5, 16, 11, "FIELD_WIRE_JSON_COMPATIBLE_TYPE"),
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func TestRunBreakingIntEnum(t *testing.T) {
testBreaking(
t,
"breaking_int_enum",
bufanalysistesting.NewFileAnnotation(t, "1.proto", 0, 0, 0, 0, "ENUM_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "1.proto", "ENUM_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 8, "FIELD_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 7, "FIELD_SAME_TYPE"),
)
Expand All @@ -1222,10 +1222,10 @@ func TestRunBreakingMessageEnum(t *testing.T) {
testBreaking(
t,
"breaking_message_enum",
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 6, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 15, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 6, "FIELD_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 0, 0, 0, 0, "ENUM_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 7, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "ENUM_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 16, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 7, "FIELD_SAME_TYPE"),
)
}
Expand All @@ -1235,9 +1235,9 @@ func TestRunBreakingMessageInt(t *testing.T) {
testBreaking(
t,
"breaking_message_int",
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 6, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 15, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 6, "FIELD_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 8, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 17, "FIELD_SAME_CARDINALITY"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 8, "FIELD_SAME_TYPE"),
)
}
Expand All @@ -1248,7 +1248,7 @@ func TestRunBreakingMessageMessage(t *testing.T) {
t,
"breaking_message_message",
bufanalysistesting.NewFileAnnotation(t, "1.proto", 3, 3, 3, 8, "FIELD_SAME_TYPE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 0, 0, 0, 0, "MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "2.proto", "MESSAGE_NO_DELETE"),
bufanalysistesting.NewFileAnnotation(t, "2.proto", 3, 3, 3, 7, "FIELD_SAME_TYPE"),
)
}
Expand Down
20 changes: 10 additions & 10 deletions private/bufpkg/bufcheck/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestRunComments(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "a.proto", 15, 7, 15, 27, "COMMENT_ENUM_VALUE"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 16, 7, 16, 19, "COMMENT_ENUM_VALUE"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 18, 5, 23, 6, "COMMENT_MESSAGE"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 19, 7, 19, 21, "COMMENT_FIELD"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 19, 7, 19, 30, "COMMENT_FIELD"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 20, 7, 22, 8, "COMMENT_ONEOF"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 21, 9, 21, 23, "COMMENT_FIELD"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 24, 5, 24, 19, "COMMENT_FIELD"),
Expand Down Expand Up @@ -357,14 +357,14 @@ func TestRunFieldNoDescriptor(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "a.proto", 25, 23, 25, 34, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 26, 23, 26, 35, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 27, 23, 27, 37, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 30, 27, 30, 38, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 31, 27, 31, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 32, 27, 32, 38, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 33, 27, 33, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 34, 27, 34, 41, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 35, 27, 35, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 36, 27, 36, 38, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 37, 27, 37, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 30, 27, 30, 37, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 31, 27, 31, 37, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 32, 27, 32, 37, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 33, 27, 33, 38, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 34, 27, 34, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 35, 27, 35, 38, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 36, 27, 36, 39, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 37, 27, 37, 41, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 41, 21, 41, 31, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 42, 21, 42, 31, "FIELD_NO_DESCRIPTOR"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 43, 21, 43, 31, "FIELD_NO_DESCRIPTOR"),
Expand Down Expand Up @@ -1202,7 +1202,7 @@ func TestRunLintCustomPlugins(t *testing.T) {
testLint(
t,
"custom_plugins",
bufanalysistesting.NewFileAnnotation(t, "a.proto", 1, 1, 1, 1, "PACKAGE_DEFINED"),
bufanalysistesting.NewFileAnnotationNoLocation(t, "a.proto", "PACKAGE_DEFINED"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 8, 1, 10, 2, "SERVICE_BANNED_SUFFIXES"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 15, 1, 17, 2, "PAGE_REQUEST_HAS_TOKEN"),
bufanalysistesting.NewFileAnnotation(t, "a.proto", 19, 1, 25, 2, "PAGE_RESPONSE_HAS_TOKEN"),
Expand Down

0 comments on commit 6df73b9

Please sign in to comment.