Add some java plugin integration tests.

PiperOrigin-RevId: 689943588
pull/19003/head
Mike Kruskal 5 months ago committed by Copybara-Service
parent 9f6c3d5f39
commit e98a263d22
  1. 15
      src/google/protobuf/compiler/java/BUILD.bazel
  2. 5
      src/google/protobuf/compiler/java/file.cc
  3. 72
      src/google/protobuf/compiler/java/generator_unittest.cc

@ -129,6 +129,7 @@ cc_library(
deps = [
":generator_common",
":helpers",
":internal_helpers",
":java_features_bootstrap",
":names",
"//src/google/protobuf",
@ -194,6 +195,20 @@ cc_library(
],
)
cc_test(
name = "generator_unittest",
srcs = ["generator_unittest.cc"],
deps = [
":java",
":java_features_bootstrap",
"//:protobuf",
"//src/google/protobuf",
"//src/google/protobuf/compiler:command_line_interface_tester",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "doc_comment_unittest",
srcs = ["doc_comment_unittest.cc"],

@ -26,6 +26,7 @@
#include "google/protobuf/compiler/java/generator_factory.h"
#include "google/protobuf/compiler/java/helpers.h"
#include "google/protobuf/compiler/java/full/generator_factory.h"
#include "google/protobuf/compiler/java/internal_helpers.h"
#include "google/protobuf/compiler/java/lite/generator_factory.h"
#include "google/protobuf/compiler/java/name_resolver.h"
#include "google/protobuf/compiler/java/options.h"
@ -33,6 +34,7 @@
#include "google/protobuf/compiler/retention.h"
#include "google/protobuf/compiler/versions.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor_visitor.h"
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
@ -250,7 +252,8 @@ bool FileGenerator::Validate(std::string* error) {
"https://github.com/protocolbuffers/protobuf/blob/main/java/"
"lite.md";
}
return true;
return error->empty();
}
void FileGenerator::Generate(io::Printer* printer) {

@ -0,0 +1,72 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "google/protobuf/compiler/java/generator.h"
#include <memory>
#include "google/protobuf/descriptor.pb.h"
#include <gtest/gtest.h>
#include "google/protobuf/compiler/java/java_features.pb.h"
#include "google/protobuf/compiler/command_line_interface_tester.h"
namespace google {
namespace protobuf {
namespace compiler {
namespace java {
namespace {
class JavaGeneratorTest : public CommandLineInterfaceTester {
protected:
JavaGeneratorTest() {
RegisterGenerator("--java_out", "--java_opt",
std::make_unique<JavaGenerator>(), "Java test generator");
// Generate built-in protos.
CreateTempFile(
"google/protobuf/descriptor.proto",
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
CreateTempFile("third_party/java/protobuf/java_features.proto",
pb::JavaFeatures::descriptor()->file()->DebugString());
}
};
TEST_F(JavaGeneratorTest, Basic) {
CreateTempFile("foo.proto",
R"schema(
syntax = "proto2";
message Foo {
optional int32 bar = 1;
})schema");
RunProtoc(
"protocol_compiler --proto_path=$tmpdir --java_out=$tmpdir foo.proto");
ExpectNoErrors();
}
TEST_F(JavaGeneratorTest, BasicError) {
CreateTempFile("foo.proto",
R"schema(
syntax = "proto2";
message Foo {
int32 bar = 1;
})schema");
RunProtoc(
"protocol_compiler --proto_path=$tmpdir --java_out=$tmpdir foo.proto");
ExpectErrorSubstring(
"foo.proto:4:7: Expected \"required\", \"optional\", or \"repeated\"");
}
} // namespace
} // namespace java
} // namespace compiler
} // namespace protobuf
} // namespace google
Loading…
Cancel
Save