aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/command_line_interface_unittest.cc
diff options
context:
space:
mode:
authorGravatar Bo Yang <paulyang1211@gmail.com>2015-02-03 21:35:50 -0800
committerGravatar Bo Yang <paulyang1211@gmail.com>2015-02-03 21:35:50 -0800
commit5914ce7a160a82db1490e99c45c95c69417b20ea (patch)
treefdd9219543de9caf2490a1bcc10ef62ffe27d254 /src/google/protobuf/compiler/command_line_interface_unittest.cc
parent532c94145b6605361513682601f1d8e9f97a2497 (diff)
Implement a feature to generate a dependency file. By giving protoc the flag
"--dependency_manifest_out=FILE", protoc will write dependencies of input proto files into FILE. In FILE, the format will be <full path to FILE>: <full path to 1st proto>\\\n <full path to 2nd proto> ... This cl is based on https://github.com/google/protobuf/pull/178
Diffstat (limited to 'src/google/protobuf/compiler/command_line_interface_unittest.cc')
-rw-r--r--src/google/protobuf/compiler/command_line_interface_unittest.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index dbaaa405..e7cfff6b 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -116,6 +116,10 @@ class CommandLineInterfaceTest : public testing::Test {
cli_.SetInputsAreProtoPathRelative(enable);
}
+ string GetTempDirectory() {
+ return temp_directory_;
+ }
+
// -----------------------------------------------------------------
// Methods to check the test results (called after Run()).
@@ -176,6 +180,9 @@ class CommandLineInterfaceTest : public testing::Test {
void ReadDescriptorSet(const string& filename,
FileDescriptorSet* descriptor_set);
+ void ExpectFileContent(const string& filename,
+ const string& content);
+
private:
// The object we are testing.
CommandLineInterface cli_;
@@ -456,6 +463,17 @@ void CommandLineInterfaceTest::ExpectCapturedStdout(
EXPECT_EQ(expected_text, captured_stdout_);
}
+
+void CommandLineInterfaceTest::ExpectFileContent(
+ const string& filename, const string& content) {
+ string path = temp_directory_ + "/" + filename;
+ string file_contents;
+ GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true));
+
+ EXPECT_EQ(StringReplace(content, "$tmpdir", temp_directory_, true),
+ file_contents);
+}
+
// ===================================================================
TEST_F(CommandLineInterfaceTest, BasicOutput) {
@@ -940,6 +958,53 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSetWithSourceInfo) {
EXPECT_TRUE(descriptor_set.file(1).has_source_code_info());
}
+TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFile) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message Foo {}\n");
+ CreateTempFile("bar.proto",
+ "syntax = \"proto2\";\n"
+ "import \"foo.proto\";\n"
+ "message Bar {\n"
+ " optional Foo foo = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --dependency_manifest_out=$tmpdir/manifest "
+ "--test_out=$tmpdir --proto_path=$tmpdir bar.proto");
+
+ ExpectNoErrors();
+
+ ExpectFileContent("manifest",
+ "$tmpdir/manifest: $tmpdir/foo.proto\\\n"
+ " $tmpdir/bar.proto");
+}
+
+TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForRelativePath) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message Foo {}\n");
+ CreateTempFile("bar.proto",
+ "syntax = \"proto2\";\n"
+ "import \"foo.proto\";\n"
+ "message Bar {\n"
+ " optional Foo foo = 1;\n"
+ "}\n");
+
+ string current_working_directory = get_current_dir_name();
+ File::ChangeWorkingDirectory(GetTempDirectory());
+
+ Run("protocol_compiler --dependency_manifest_out=manifest "
+ "--test_out=$tmpdir --proto_path=$tmpdir bar.proto");
+
+ ExpectNoErrors();
+
+ ExpectFileContent("manifest",
+ "$tmpdir/manifest: $tmpdir/foo.proto\\\n"
+ " $tmpdir/bar.proto");
+
+ File::ChangeWorkingDirectory(current_working_directory);
+}
+
// -------------------------------------------------------------------
TEST_F(CommandLineInterfaceTest, ParseErrors) {