prototest_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package prototest_test
  5. import (
  6. "fmt"
  7. "testing"
  8. "google.golang.org/protobuf/internal/flags"
  9. "google.golang.org/protobuf/proto"
  10. "google.golang.org/protobuf/runtime/protoimpl"
  11. "google.golang.org/protobuf/testing/prototest"
  12. irregularpb "google.golang.org/protobuf/internal/testprotos/irregular"
  13. legacypb "google.golang.org/protobuf/internal/testprotos/legacy"
  14. legacy1pb "google.golang.org/protobuf/internal/testprotos/legacy/proto2.v0.0.0-20160225-2fc053c5"
  15. testpb "google.golang.org/protobuf/internal/testprotos/test"
  16. _ "google.golang.org/protobuf/internal/testprotos/test/weak1"
  17. _ "google.golang.org/protobuf/internal/testprotos/test/weak2"
  18. test3pb "google.golang.org/protobuf/internal/testprotos/test3"
  19. )
  20. func Test(t *testing.T) {
  21. ms := []proto.Message{
  22. (*testpb.TestAllTypes)(nil),
  23. (*test3pb.TestAllTypes)(nil),
  24. (*testpb.TestRequired)(nil),
  25. (*irregularpb.Message)(nil),
  26. (*testpb.TestAllExtensions)(nil),
  27. (*legacypb.Legacy)(nil),
  28. protoimpl.X.MessageOf((*legacy1pb.Message)(nil)).Interface(),
  29. }
  30. if flags.ProtoLegacy {
  31. ms = append(ms, (*testpb.TestWeak)(nil))
  32. }
  33. for _, m := range ms {
  34. t.Run(fmt.Sprintf("%T", m), func(t *testing.T) {
  35. prototest.TestMessage(t, m, prototest.MessageOptions{})
  36. })
  37. }
  38. }