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 bdf37ad1ba26515ccfa14c8c37f917409861441e..d5b3a1dcd82d43c657456c0f086800423dd1e995 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 |
@@ -48,6 +48,7 @@ |
#include <google/protobuf/compiler/command_line_interface.h> |
#include <google/protobuf/compiler/code_generator.h> |
#include <google/protobuf/compiler/mock_code_generator.h> |
+#include <google/protobuf/compiler/subprocess.h> |
#include <google/protobuf/io/printer.h> |
#include <google/protobuf/unittest.pb.h> |
#include <google/protobuf/testing/file.h> |
@@ -143,6 +144,10 @@ class CommandLineInterfaceTest : public testing::Test { |
const string& proto_name, |
const string& message_name, |
const string& output_directory); |
+ void ExpectGeneratedWithMultipleInputs(const string& generator_name, |
+ const string& all_proto_names, |
+ const string& proto_name, |
+ const string& message_name); |
void ExpectGeneratedWithInsertions(const string& generator_name, |
const string& parameter, |
const string& insertions, |
@@ -190,7 +195,7 @@ class CommandLineInterfaceTest::NullCodeGenerator : public CodeGenerator { |
// implements CodeGenerator ---------------------------------------- |
bool Generate(const FileDescriptor* file, |
const string& parameter, |
- OutputDirectory* output_directory, |
+ GeneratorContext* context, |
string* error) const { |
called_ = true; |
parameter_ = parameter; |
@@ -251,7 +256,6 @@ void CommandLineInterfaceTest::Run(const string& command) { |
if (!disallow_plugins_) { |
cli_.AllowPlugins("prefix-"); |
- |
const char* possible_paths[] = { |
// When building with shared libraries, libtool hides the real executable |
// in .libs and puts a fake wrapper in the current directory. |
@@ -353,7 +357,8 @@ void CommandLineInterfaceTest::ExpectGenerated( |
const string& proto_name, |
const string& message_name) { |
MockCodeGenerator::ExpectGenerated( |
- generator_name, parameter, "", proto_name, message_name, temp_directory_); |
+ generator_name, parameter, "", proto_name, message_name, proto_name, |
+ temp_directory_); |
} |
void CommandLineInterfaceTest::ExpectGenerated( |
@@ -363,10 +368,21 @@ void CommandLineInterfaceTest::ExpectGenerated( |
const string& message_name, |
const string& output_directory) { |
MockCodeGenerator::ExpectGenerated( |
- generator_name, parameter, "", proto_name, message_name, |
+ generator_name, parameter, "", proto_name, message_name, proto_name, |
temp_directory_ + "/" + output_directory); |
} |
+void CommandLineInterfaceTest::ExpectGeneratedWithMultipleInputs( |
+ const string& generator_name, |
+ const string& all_proto_names, |
+ const string& proto_name, |
+ const string& message_name) { |
+ MockCodeGenerator::ExpectGenerated( |
+ generator_name, "", "", proto_name, message_name, |
+ all_proto_names, |
+ temp_directory_); |
+} |
+ |
void CommandLineInterfaceTest::ExpectGeneratedWithInsertions( |
const string& generator_name, |
const string& parameter, |
@@ -375,7 +391,7 @@ void CommandLineInterfaceTest::ExpectGeneratedWithInsertions( |
const string& message_name) { |
MockCodeGenerator::ExpectGenerated( |
generator_name, parameter, insertions, proto_name, message_name, |
- temp_directory_); |
+ proto_name, temp_directory_); |
} |
void CommandLineInterfaceTest::ExpectNullCodeGeneratorCalled( |
@@ -455,8 +471,44 @@ TEST_F(CommandLineInterfaceTest, MultipleInputs) { |
"--proto_path=$tmpdir foo.proto bar.proto"); |
ExpectNoErrors(); |
- ExpectGenerated("test_generator", "", "foo.proto", "Foo"); |
- ExpectGenerated("test_generator", "", "bar.proto", "Bar"); |
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", |
+ "foo.proto", "Foo"); |
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", |
+ "bar.proto", "Bar"); |
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", |
+ "foo.proto", "Foo"); |
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", |
+ "bar.proto", "Bar"); |
+} |
+ |
+TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) { |
+ // Test parsing multiple input files with an import of a separate file. |
+ |
+ CreateTempFile("foo.proto", |
+ "syntax = \"proto2\";\n" |
+ "message Foo {}\n"); |
+ CreateTempFile("bar.proto", |
+ "syntax = \"proto2\";\n" |
+ "import \"baz.proto\";\n" |
+ "message Bar {\n" |
+ " optional Baz a = 1;\n" |
+ "}\n"); |
+ CreateTempFile("baz.proto", |
+ "syntax = \"proto2\";\n" |
+ "message Baz {}\n"); |
+ |
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir " |
+ "--proto_path=$tmpdir foo.proto bar.proto"); |
+ |
+ ExpectNoErrors(); |
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", |
+ "foo.proto", "Foo"); |
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", |
+ "bar.proto", "Bar"); |
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", |
+ "foo.proto", "Foo"); |
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", |
+ "bar.proto", "Bar"); |
} |
TEST_F(CommandLineInterfaceTest, CreateDirectory) { |
@@ -515,7 +567,7 @@ TEST_F(CommandLineInterfaceTest, Insert) { |
"foo.proto", "Foo"); |
} |
-#if defined(_WIN32) || defined(__CYGWIN__) |
+#if defined(_WIN32) |
TEST_F(CommandLineInterfaceTest, WindowsOutputPath) { |
// Test that the output path can be a Windows-style path. |
@@ -1089,9 +1141,8 @@ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) { |
"--proto_path=$tmpdir error.proto"); |
#ifdef _WIN32 |
- ExpectErrorSubstring( |
- "--badplug_out: prefix-gen-badplug: The system cannot find the file " |
- "specified."); |
+ ExpectErrorSubstring("--badplug_out: prefix-gen-badplug: " + |
+ Subprocess::Win32ErrorMessage(ERROR_FILE_NOT_FOUND)); |
#else |
// Error written to stdout by child process after exec() fails. |
ExpectErrorSubstring( |