From 541354284bf44266522ad04359e5acb896ac11f4 Mon Sep 17 00:00:00 2001 From: Johyn Papin Date: Thu, 14 Dec 2023 14:41:18 +0100 Subject: [PATCH] Build protos using the nullable option for testing. --- protoc_plugin/Makefile | 10 ++++++++++ protoc_plugin/test/unittest_proto3_test.dart | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/protoc_plugin/Makefile b/protoc_plugin/Makefile index 4e1effcbd..291cb8478 100644 --- a/protoc_plugin/Makefile +++ b/protoc_plugin/Makefile @@ -102,6 +102,16 @@ $(TEST_PROTO_LIBS): $(PLUGIN_SRC) $(TEST_PROTO_SRCS) --plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH))\ $(TEST_PROTO_SRCS) + mkdir -p $(TEST_PROTO_DIR)/nullable + + protoc\ + --experimental_allow_proto3_optional\ + --dart_out="nullable:$(TEST_PROTO_DIR)/nullable"\ + -Iprotos\ + -I$(TEST_PROTO_SRC_DIR)\ + --plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH))\ + $(TEST_PROTO_SRCS) + dart format $(TEST_PROTO_DIR) update-pregenerated: $(PLUGIN_PATH) $(PREGENERATED_SRCS) diff --git a/protoc_plugin/test/unittest_proto3_test.dart b/protoc_plugin/test/unittest_proto3_test.dart index 29d2a1319..4d9866a99 100644 --- a/protoc_plugin/test/unittest_proto3_test.dart +++ b/protoc_plugin/test/unittest_proto3_test.dart @@ -1,5 +1,5 @@ import 'package:test/test.dart'; -import '../out/protos/google/protobuf/unittest_proto3.pb.dart'; +import '../out/protos/nullable/google/protobuf/unittest_proto3.pb.dart'; void main() { group('Optional fields should be nullable for', () { @@ -16,7 +16,7 @@ void main() { expect(obj2.optionalSingleInt32, null); // should not generate linting errors expect(obj2.optionalSingleInt32 ?? 1, 1); - expect(obj.hasOptionalSingleInt32(), false); + expect(obj2.hasOptionalSingleInt32(), false); }); }); }