|
@@ -29,6 +29,7 @@
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
#include <memory>
|
|
#include <memory>
|
|
|
|
+#include <list>
|
|
|
|
|
|
#include <google/protobuf/compiler/ruby/ruby_generator.h>
|
|
#include <google/protobuf/compiler/ruby/ruby_generator.h>
|
|
#include <google/protobuf/compiler/command_line_interface.h>
|
|
#include <google/protobuf/compiler/command_line_interface.h>
|
|
@@ -56,7 +57,7 @@ string FindRubyTestDir() {
|
|
// Some day, we may integrate build systems between protoc and the language
|
|
// Some day, we may integrate build systems between protoc and the language
|
|
// extensions to the point where we can do this test in a more automated way.
|
|
// extensions to the point where we can do this test in a more automated way.
|
|
|
|
|
|
-TEST(RubyGeneratorTest, Proto3GeneratorTest) {
|
|
|
|
|
|
+void RubyTest(string proto_file) {
|
|
string ruby_tests = FindRubyTestDir();
|
|
string ruby_tests = FindRubyTestDir();
|
|
|
|
|
|
google::protobuf::compiler::CommandLineInterface cli;
|
|
google::protobuf::compiler::CommandLineInterface cli;
|
|
@@ -68,22 +69,23 @@ TEST(RubyGeneratorTest, Proto3GeneratorTest) {
|
|
// Copy generated_code.proto to the temporary test directory.
|
|
// Copy generated_code.proto to the temporary test directory.
|
|
string test_input;
|
|
string test_input;
|
|
GOOGLE_CHECK_OK(File::GetContents(
|
|
GOOGLE_CHECK_OK(File::GetContents(
|
|
- ruby_tests + "/ruby_generated_code.proto",
|
|
|
|
|
|
+ ruby_tests + proto_file + ".proto",
|
|
&test_input,
|
|
&test_input,
|
|
true));
|
|
true));
|
|
GOOGLE_CHECK_OK(File::SetContents(
|
|
GOOGLE_CHECK_OK(File::SetContents(
|
|
- TestTempDir() + "/ruby_generated_code.proto",
|
|
|
|
|
|
+ TestTempDir() + proto_file + ".proto",
|
|
test_input,
|
|
test_input,
|
|
true));
|
|
true));
|
|
|
|
|
|
// Invoke the proto compiler (we will be inside TestTempDir() at this point).
|
|
// Invoke the proto compiler (we will be inside TestTempDir() at this point).
|
|
string ruby_out = "--ruby_out=" + TestTempDir();
|
|
string ruby_out = "--ruby_out=" + TestTempDir();
|
|
string proto_path = "--proto_path=" + TestTempDir();
|
|
string proto_path = "--proto_path=" + TestTempDir();
|
|
|
|
+ string proto_target = TestTempDir() + proto_file + ".proto";
|
|
const char* argv[] = {
|
|
const char* argv[] = {
|
|
"protoc",
|
|
"protoc",
|
|
ruby_out.c_str(),
|
|
ruby_out.c_str(),
|
|
proto_path.c_str(),
|
|
proto_path.c_str(),
|
|
- "ruby_generated_code.proto",
|
|
|
|
|
|
+ proto_target.c_str(),
|
|
};
|
|
};
|
|
|
|
|
|
EXPECT_EQ(0, cli.Run(4, argv));
|
|
EXPECT_EQ(0, cli.Run(4, argv));
|
|
@@ -91,61 +93,35 @@ TEST(RubyGeneratorTest, Proto3GeneratorTest) {
|
|
// Load the generated output and compare to the expected result.
|
|
// Load the generated output and compare to the expected result.
|
|
string output;
|
|
string output;
|
|
GOOGLE_CHECK_OK(File::GetContentsAsText(
|
|
GOOGLE_CHECK_OK(File::GetContentsAsText(
|
|
- TestTempDir() + "/ruby_generated_code_pb.rb",
|
|
|
|
|
|
+ TestTempDir() + proto_file + "_pb.rb",
|
|
&output,
|
|
&output,
|
|
true));
|
|
true));
|
|
string expected_output;
|
|
string expected_output;
|
|
GOOGLE_CHECK_OK(File::GetContentsAsText(
|
|
GOOGLE_CHECK_OK(File::GetContentsAsText(
|
|
- ruby_tests + "/ruby_generated_code_pb.rb",
|
|
|
|
|
|
+ ruby_tests + proto_file + "_pb.rb",
|
|
&expected_output,
|
|
&expected_output,
|
|
true));
|
|
true));
|
|
EXPECT_EQ(expected_output, output);
|
|
EXPECT_EQ(expected_output, output);
|
|
}
|
|
}
|
|
|
|
|
|
-TEST(RubyGeneratorTest, Proto2GeneratorTest) {
|
|
|
|
- string ruby_tests = FindRubyTestDir();
|
|
|
|
-
|
|
|
|
- google::protobuf::compiler::CommandLineInterface cli;
|
|
|
|
- cli.SetInputsAreProtoPathRelative(true);
|
|
|
|
-
|
|
|
|
- ruby::Generator ruby_generator;
|
|
|
|
- cli.RegisterGenerator("--ruby_out", &ruby_generator, "");
|
|
|
|
|
|
+TEST(RubyGeneratorTest, Proto3GeneratorTest) {
|
|
|
|
+ RubyTest("/ruby_generated_code");
|
|
|
|
+}
|
|
|
|
|
|
- // Copy generated_code.proto to the temporary test directory.
|
|
|
|
- string test_input;
|
|
|
|
- GOOGLE_CHECK_OK(File::GetContents(
|
|
|
|
- ruby_tests + "/ruby_generated_code_proto2.proto",
|
|
|
|
- &test_input,
|
|
|
|
- true));
|
|
|
|
- GOOGLE_CHECK_OK(File::SetContents(
|
|
|
|
- TestTempDir() + "/ruby_generated_code_proto2.proto",
|
|
|
|
- test_input,
|
|
|
|
- true));
|
|
|
|
|
|
+TEST(RubyGeneratorTest, Proto2GeneratorTest) {
|
|
|
|
+ RubyTest("/ruby_generated_code_proto2");
|
|
|
|
+}
|
|
|
|
|
|
- // Invoke the proto compiler (we will be inside TestTempDir() at this point).
|
|
|
|
- string ruby_out = "--ruby_out=" + TestTempDir();
|
|
|
|
- string proto_path = "--proto_path=" + TestTempDir();
|
|
|
|
- const char* argv[] = {
|
|
|
|
- "protoc",
|
|
|
|
- ruby_out.c_str(),
|
|
|
|
- proto_path.c_str(),
|
|
|
|
- "ruby_generated_code_proto2.proto",
|
|
|
|
- };
|
|
|
|
|
|
+TEST(RubyGeneratorTest, Proto3ImplicitPackageTest) {
|
|
|
|
+ RubyTest("/ruby_generated_pkg_implicit");
|
|
|
|
+}
|
|
|
|
|
|
- EXPECT_EQ(0, cli.Run(4, argv));
|
|
|
|
|
|
+TEST(RubyGeneratorTest, Proto3ExplictPackageTest) {
|
|
|
|
+ RubyTest("/ruby_generated_pkg_explicit");
|
|
|
|
+}
|
|
|
|
|
|
- // Load the generated output and compare to the expected result.
|
|
|
|
- string output;
|
|
|
|
- GOOGLE_CHECK_OK(File::GetContents(
|
|
|
|
- TestTempDir() + "/ruby_generated_code_proto2_pb.rb",
|
|
|
|
- &output,
|
|
|
|
- true));
|
|
|
|
- string expected_output;
|
|
|
|
- GOOGLE_CHECK_OK(File::GetContents(
|
|
|
|
- ruby_tests + "/ruby_generated_code_proto2_pb.rb",
|
|
|
|
- &expected_output,
|
|
|
|
- true));
|
|
|
|
- EXPECT_EQ(expected_output, output);
|
|
|
|
|
|
+TEST(RubyGeneratorTest, Proto3ExplictLegacyPackageTest) {
|
|
|
|
+ RubyTest("/ruby_generated_pkg_explicit_legacy");
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace
|
|
} // namespace
|