From 3eb55df6a4624f6124d96ea52a7c2915ee7957fd Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Fri, 14 Nov 2014 12:41:10 -0800 Subject: Report a warning if the proto file doesn't have a syntax statement. --- src/google/protobuf/compiler/parser.cc | 4 ++++ src/google/protobuf/compiler/parser_unittest.cc | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'src') diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 0ed80d54..41b73678 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -468,6 +468,10 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) { // Store the syntax into the file. if (file != NULL) file->set_syntax(syntax_identifier_); } else if (!stop_after_syntax_identifier_) { + GOOGLE_LOG(WARNING) << "No syntax specified for the proto file. " + << "Please use 'syntax = \"proto2\";' or " + << "'syntax = \"proto3\";' to specify a syntax " + << "version. (Defaulted to proto2 syntax.)"; syntax_identifier_ = "proto2"; } diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 00112999..45f95df1 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -216,6 +216,15 @@ TEST_F(ParserTest, StopAfterSyntaxIdentifierWithErrors) { EXPECT_EQ("1:9: Expected syntax identifier.\n", error_collector_.text_); } +TEST_F(ParserTest, WarnIfSyntaxIdentifierOmmitted) { + SetupParser("message A {}"); + FileDescriptorProto file; + CaptureTestStderr(); + EXPECT_TRUE(parser_->Parse(input_.get(), &file)); + EXPECT_TRUE( + GetCapturedTestStderr().find("No syntax specified") != string::npos); +} + // =================================================================== typedef ParserTest ParseMessageTest; -- cgit v1.2.3