|
|
|
@ -15,7 +15,6 @@ |
|
|
|
|
#include "google/protobuf/testing/file.h" |
|
|
|
|
#include "google/protobuf/compiler/command_line_interface.h" |
|
|
|
|
#include "google/protobuf/compiler/python/generator.h" |
|
|
|
|
#include "google/protobuf/testing/googletest.h" |
|
|
|
|
#include <gtest/gtest.h> |
|
|
|
|
#include "absl/log/absl_check.h" |
|
|
|
|
#include "absl/strings/str_split.h" |
|
|
|
@ -58,7 +57,7 @@ TEST(PythonPluginTest, ImportTest) { |
|
|
|
|
// Create files test1.proto and test2.proto with the former importing the
|
|
|
|
|
// latter.
|
|
|
|
|
ABSL_CHECK_OK( |
|
|
|
|
File::SetContents(absl::StrCat(TestTempDir(), "/test1.proto"), |
|
|
|
|
File::SetContents(absl::StrCat(::testing::TempDir(), "/test1.proto"), |
|
|
|
|
"syntax = \"proto3\";\n" |
|
|
|
|
"package foo;\n" |
|
|
|
|
"import \"test2.proto\";" |
|
|
|
@ -67,7 +66,7 @@ TEST(PythonPluginTest, ImportTest) { |
|
|
|
|
"}\n", |
|
|
|
|
true)); |
|
|
|
|
ABSL_CHECK_OK( |
|
|
|
|
File::SetContents(absl::StrCat(TestTempDir(), "/test2.proto"), |
|
|
|
|
File::SetContents(absl::StrCat(::testing::TempDir(), "/test2.proto"), |
|
|
|
|
"syntax = \"proto3\";\n" |
|
|
|
|
"package foo;\n" |
|
|
|
|
"message Message2 {}\n", |
|
|
|
@ -77,8 +76,8 @@ TEST(PythonPluginTest, ImportTest) { |
|
|
|
|
cli.SetInputsAreProtoPathRelative(true); |
|
|
|
|
python::Generator python_generator; |
|
|
|
|
cli.RegisterGenerator("--python_out", &python_generator, ""); |
|
|
|
|
std::string proto_path = absl::StrCat("-I", TestTempDir()); |
|
|
|
|
std::string python_out = absl::StrCat("--python_out=", TestTempDir()); |
|
|
|
|
std::string proto_path = absl::StrCat("-I", ::testing::TempDir()); |
|
|
|
|
std::string python_out = absl::StrCat("--python_out=", ::testing::TempDir()); |
|
|
|
|
const char* argv[] = {"protoc", proto_path.c_str(), "-I.", python_out.c_str(), |
|
|
|
|
"test1.proto"}; |
|
|
|
|
ASSERT_EQ(0, cli.Run(5, argv)); |
|
|
|
@ -87,7 +86,7 @@ TEST(PythonPluginTest, ImportTest) { |
|
|
|
|
// ordinary Python import but do not find the string "importlib".
|
|
|
|
|
std::string output; |
|
|
|
|
ABSL_CHECK_OK( |
|
|
|
|
File::GetContents(absl::StrCat(TestTempDir(), "/test1_pb2.py"), |
|
|
|
|
File::GetContents(absl::StrCat(::testing::TempDir(), "/test1_pb2.py"), |
|
|
|
|
&output, true)); |
|
|
|
|
std::vector<absl::string_view> lines = absl::StrSplit(output, '\n'); |
|
|
|
|
std::string expected_import = "import test2_pb2"; |
|
|
|
|