| Index: third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| index 9b504d25247686de14c1feebb16b77989a9fbea0..dfbaa45abc7d2729112554577f6a4fdf24c19481 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
|
| @@ -653,6 +653,44 @@ TEST_F(CommandLineInterfaceTest, ExtraGeneratorParameters) {
|
| "test_generator", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b");
|
| }
|
|
|
| +TEST_F(CommandLineInterfaceTest, ExtraPluginParameters) {
|
| + // Test that generator parameters specified with the option flag are
|
| + // correctly passed to the code generator.
|
| +
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| + // Create the "a" and "b" sub-directories.
|
| + CreateTempDir("a");
|
| + CreateTempDir("b");
|
| +
|
| + Run("protocol_compiler "
|
| + "--plug_opt=foo1 "
|
| + "--plug_out=bar:$tmpdir/a "
|
| + "--plug_opt=foo2 "
|
| + "--plug_out=baz:$tmpdir/b "
|
| + "--plug_opt=foo3 "
|
| + "--proto_path=$tmpdir foo.proto");
|
| +
|
| + ExpectNoErrors();
|
| + ExpectGenerated(
|
| + "test_plugin", "bar,foo1,foo2,foo3", "foo.proto", "Foo", "a");
|
| + ExpectGenerated(
|
| + "test_plugin", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b");
|
| +}
|
| +
|
| +TEST_F(CommandLineInterfaceTest, UnrecognizedExtraParameters) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| +
|
| + Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
|
| + "--unknown_plug_opt=Foo "
|
| + "--proto_path=$tmpdir foo.proto");
|
| +
|
| + ExpectErrorSubstring("Unknown flag: --unknown_plug_opt");
|
| +}
|
| +
|
| TEST_F(CommandLineInterfaceTest, Insert) {
|
| // Test running a generator that inserts code into another's output.
|
|
|
| @@ -719,6 +757,11 @@ TEST_F(CommandLineInterfaceTest, TrailingBackslash) {
|
| ExpectGenerated("test_generator", "", "foo.proto", "Foo");
|
| }
|
|
|
| +TEST_F(CommandLineInterfaceTest, Win32ErrorMessage) {
|
| + EXPECT_EQ("The system cannot find the file specified.\r\n",
|
| + Subprocess::Win32ErrorMessage(ERROR_FILE_NOT_FOUND));
|
| +}
|
| +
|
| #endif // defined(_WIN32) || defined(__CYGWIN__)
|
|
|
| TEST_F(CommandLineInterfaceTest, PathLookup) {
|
| @@ -786,6 +829,21 @@ TEST_F(CommandLineInterfaceTest, NonRootMapping) {
|
| ExpectGenerated("test_generator", "", "bar/foo.proto", "Foo");
|
| }
|
|
|
| +TEST_F(CommandLineInterfaceTest, PathWithEqualsSign) {
|
| + // Test setting up a search path which happens to have '=' in it.
|
| +
|
| + CreateTempDir("with=sign");
|
| + CreateTempFile("with=sign/foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Foo {}\n");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir "
|
| + "--proto_path=$tmpdir/with=sign foo.proto");
|
| +
|
| + ExpectNoErrors();
|
| + ExpectGenerated("test_generator", "", "foo.proto", "Foo");
|
| +}
|
| +
|
| TEST_F(CommandLineInterfaceTest, MultipleGenerators) {
|
| // Test that we can have multiple generators and use both in one invocation,
|
| // each with a different output directory.
|
| @@ -851,6 +909,92 @@ TEST_F(CommandLineInterfaceTest, AllowServicesHasService) {
|
| ExpectGenerated("test_generator", "", "foo.proto", "Foo");
|
| }
|
|
|
| +TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing_EmptyList) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"bar.proto\";\n"
|
| + "message Foo { optional Bar bar = 1; }");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bar { optional string text = 1; }");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
|
| + "--direct_dependencies= foo.proto");
|
| +
|
| + ExpectErrorText(
|
| + "foo.proto: File is imported but not declared in --direct_dependencies: "
|
| + "bar.proto\n");
|
| +}
|
| +
|
| +TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"bar.proto\";\n"
|
| + "import \"bla.proto\";\n"
|
| + "message Foo { optional Bar bar = 1; optional Bla bla = 2; }");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bar { optional string text = 1; }");
|
| + CreateTempFile("bla.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bla { optional int64 number = 1; }");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
|
| + "--direct_dependencies=bla.proto foo.proto");
|
| +
|
| + ExpectErrorText(
|
| + "foo.proto: File is imported but not declared in --direct_dependencies: "
|
| + "bar.proto\n");
|
| +}
|
| +
|
| +TEST_F(CommandLineInterfaceTest, DirectDependencies_NoViolation) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"bar.proto\";\n"
|
| + "message Foo { optional Bar bar = 1; }");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bar { optional string text = 1; }");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
|
| + "--direct_dependencies=bar.proto foo.proto");
|
| +
|
| + ExpectNoErrors();
|
| +}
|
| +
|
| +TEST_F(CommandLineInterfaceTest, DirectDependencies_NoViolation_MultiImports) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "import \"bar.proto\";\n"
|
| + "import \"bla.proto\";\n"
|
| + "message Foo { optional Bar bar = 1; optional Bla bla = 2; }");
|
| + CreateTempFile("bar.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bar { optional string text = 1; }");
|
| + CreateTempFile("bla.proto",
|
| + "syntax = \"proto2\";\n"
|
| + "message Bla { optional int64 number = 1; }");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
|
| + "--direct_dependencies=bar.proto:bla.proto foo.proto");
|
| +
|
| + ExpectNoErrors();
|
| +}
|
| +
|
| +TEST_F(CommandLineInterfaceTest, DirectDependencies_ProvidedMultipleTimes) {
|
| + CreateTempFile("foo.proto",
|
| + "syntax = \"proto2\";\n");
|
| +
|
| + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir "
|
| + "--direct_dependencies=bar.proto --direct_dependencies=bla.proto "
|
| + "foo.proto");
|
| +
|
| + ExpectErrorText(
|
| + "--direct_dependencies may only be passed once. To specify multiple "
|
| + "direct dependencies, pass them all as a single parameter separated by "
|
| + "':'.\n");
|
| +}
|
| +
|
| TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) {
|
| // Test that we can accept working-directory-relative input files.
|
|
|
|
|