Bazel powered Java testing (#8506)

* Protobuf Java/Core Tests running w/ Bazel.

Also integrates rules_jvm_external and migrates existing maven deps
in place.

* Add test_suite target that maps to rule name.

* Lite tests passing in Bazel

* util tests passing with Bazel.

* Add conformance and build testing to //java:core

* Cleanup bzl style and lock down access to failure lists.

* Adding Java Lite conformance tests.

* rm newline

* parameterize conformance_test

This makes usage of failure lists more explicit.

* restrict visibility more for newly added libs and fix formatting.

* fix formatting and visibility.

* move testing.bzl to an internal package.

* fix file formatting.

* moving conformance_test to internal.bzl
pull/8519/head
Derek Perez 4 years ago committed by GitHub
parent fecf7e9340
commit bc45f92262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 155
      BUILD
  2. 65
      WORKSPACE
  3. 57
      conformance/conformance_test_runner.sh
  4. 29
      internal.bzl
  5. 8
      java/BUILD
  6. 208
      java/core/BUILD
  7. 1
      java/internal/BUILD
  8. 72
      java/internal/testing.bzl
  9. 42
      java/lite/BUILD
  10. 1
      java/lite/pom.xml
  11. 37
      java/util/BUILD
  12. 10
      protobuf.bzl
  13. 8
      protobuf_deps.bzl

155
BUILD

@ -4,6 +4,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_python//python:defs.bzl", "py_library") load("@rules_python//python:defs.bzl", "py_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_proto_library", "java_lite_proto_library")
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test") load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
licenses(["notice"]) licenses(["notice"])
@ -458,6 +459,12 @@ cc_binary(
# Tests # Tests
################################################################################ ################################################################################
filegroup(
name = "testdata",
visibility = ["//:__subpackages__"],
srcs = glob(["src/google/protobuf/testdata/**/*"]),
)
RELATIVE_LITE_TEST_PROTOS = [ RELATIVE_LITE_TEST_PROTOS = [
# AUTOGEN(lite_test_protos) # AUTOGEN(lite_test_protos)
"google/protobuf/map_lite_unittest.proto", "google/protobuf/map_lite_unittest.proto",
@ -519,6 +526,57 @@ RELATIVE_TEST_PROTOS = [
TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS] TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
GENERIC_RELATIVE_TEST_PROTOS = [
"google/protobuf/unittest.proto",
"google/protobuf/unittest_arena.proto",
"google/protobuf/unittest_custom_options.proto",
"google/protobuf/unittest_drop_unknown_fields.proto",
"google/protobuf/unittest_embed_optimize_for.proto",
"google/protobuf/unittest_empty.proto",
"google/protobuf/unittest_enormous_descriptor.proto",
"google/protobuf/unittest_import.proto",
"google/protobuf/unittest_import_public.proto",
"google/protobuf/unittest_lazy_dependencies.proto",
"google/protobuf/unittest_lazy_dependencies_custom_option.proto",
"google/protobuf/unittest_lazy_dependencies_enum.proto",
"google/protobuf/unittest_lite_imports_nonlite.proto",
"google/protobuf/unittest_mset.proto",
"google/protobuf/unittest_mset_wire_format.proto",
"google/protobuf/unittest_no_field_presence.proto",
"google/protobuf/unittest_no_generic_services.proto",
"google/protobuf/unittest_optimize_for.proto",
"google/protobuf/unittest_preserve_unknown_enum.proto",
"google/protobuf/unittest_preserve_unknown_enum2.proto",
"google/protobuf/unittest_proto3.proto",
"google/protobuf/unittest_proto3_arena.proto",
"google/protobuf/unittest_proto3_arena_lite.proto",
"google/protobuf/unittest_proto3_lite.proto",
"google/protobuf/unittest_proto3_optional.proto",
"google/protobuf/unittest_well_known_types.proto",
]
GENERIC_TEST_PROTOS = ["src/" + s for s in GENERIC_RELATIVE_TEST_PROTOS]
proto_library(
name = "generic_test_protos",
visibility = ["//:__subpackages__"],
strip_import_prefix = "src",
srcs = LITE_TEST_PROTOS + GENERIC_TEST_PROTOS,
deps = [
"//:any_proto",
"//:api_proto",
"//:descriptor_proto",
"//:duration_proto",
"//:empty_proto",
"//:field_mask_proto",
"//:source_context_proto",
"//:struct_proto",
"//:timestamp_proto",
"//:type_proto",
"//:wrappers_proto",
],
)
cc_proto_library( cc_proto_library(
name = "cc_test_protos", name = "cc_test_protos",
srcs = LITE_TEST_PROTOS + TEST_PROTOS, srcs = LITE_TEST_PROTOS + TEST_PROTOS,
@ -685,6 +743,15 @@ internal_gen_well_known_protos_java(
], ],
) )
internal_gen_well_known_protos_java(
name = "gen_well_known_protos_javalite",
deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
javalite = True,
visibility = [
"//java:__subpackages__",
],
)
alias( alias(
name = "protobuf_java", name = "protobuf_java",
actual = "//java/core", actual = "//java/core",
@ -1111,3 +1178,91 @@ sh_test(
"update_file_lists.sh", "update_file_lists.sh",
], ],
) )
java_proto_library(
name = "test_messages_proto2_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_proto_library(
name = "test_messages_proto3_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
java_proto_library(
name = "conformance_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":conformance_proto"],
)
java_lite_proto_library(
name = "test_messages_proto2_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_lite_proto_library(
name = "conformance_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":conformance_proto"],
)
java_lite_proto_library(
name = "test_messages_proto3_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
java_binary(
name = "conformance_java",
srcs = ["conformance/ConformanceJava.java"],
visibility = [
"//java:__subpackages__",
],
main_class = "ConformanceJava",
deps = [
":conformance_java_proto",
":test_messages_proto2_java_proto",
":test_messages_proto3_java_proto",
"//:protobuf_java",
"//:protobuf_java_util",
],
)
java_binary(
name = "conformance_java_lite",
srcs = ["conformance/ConformanceJavaLite.java"],
visibility = [
"//java:__subpackages__",
],
main_class = "ConformanceJavaLite",
deps = [
":conformance_java_proto_lite",
":test_messages_proto2_java_proto_lite",
":test_messages_proto3_java_proto_lite",
"//:protobuf_javalite",
"//:protobuf_java_util",
],
)
exports_files([
"conformance/conformance_test_runner.sh",
"conformance/failure_list_java.txt",
"conformance/failure_list_java_lite.txt",
"conformance/text_format_failure_list_java.txt",
"conformance/text_format_failure_list_java_lite.txt",
])

@ -26,23 +26,27 @@ http_archive(
], ],
) )
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:protobuf_deps.bzl", "protobuf_deps")
# Load common dependencies. # Load common dependencies.
load("//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps() protobuf_deps()
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
bind( bind(
name = "python_headers", name = "python_headers",
actual = "//util/python:python_headers", actual = "//util/python:python_headers",
) )
jvm_maven_import_external( load("@rules_jvm_external//:defs.bzl", "maven_install")
name = "guava_maven", maven_install(
artifact = "com.google.guava:guava:18.0", artifacts = [
artifact_sha256 = "d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99", "com.google.guava:guava:18.0",
server_urls = [ "com.google.code.gson:gson:2.7",
"com.google.errorprone:error_prone_annotations:2.3.2",
"junit:junit:4.12",
"org.easymock:easymock:3.2",
"org.easymock:easymockclassextension:3.2",
"com.google.truth:truth:1.1.2",
],
repositories = [
"https://jcenter.bintray.com/", "https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2", "https://repo1.maven.org/maven2",
], ],
@ -50,40 +54,39 @@ jvm_maven_import_external(
bind( bind(
name = "guava", name = "guava",
actual = "@guava_maven//jar", actual = "@maven//:com_google_guava_guava",
) )
jvm_maven_import_external( bind(
name = "gson_maven", name = "gson",
artifact = "com.google.code.gson:gson:2.7", actual = "@maven//:com_google_code_gson_gson",
artifact_sha256 = "2d43eb5ea9e133d2ee2405cc14f5ee08951b8361302fdd93494a3a997b508d32",
server_urls = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
) )
bind( bind(
name = "gson", name = "error_prone_annotations",
actual = "@gson_maven//jar", actual = "@maven//:com_google_errorprone_error_prone_annotations",
) )
jvm_maven_import_external( bind(
name = "error_prone_annotations_maven", name = "junit",
artifact = "com.google.errorprone:error_prone_annotations:2.3.2", actual = "@maven//:junit_junit",
artifact_sha256 = "357cd6cfb067c969226c442451502aee13800a24e950fdfde77bcdb4565a668d",
server_urls = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
) )
bind( bind(
name = "error_prone_annotations", name = "easymock",
actual = "@error_prone_annotations_maven//jar", actual = "@maven//:org_easymock_easymock",
)
bind(
name = "easymock_classextension",
actual = "@maven//:org_easymock_easymockclassextension",
)
bind(
name = "truth",
actual = "@maven//:com_google_truth_truth",
) )
# For `cc_proto_blacklist_test`. # For `cc_proto_blacklist_test`.
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace() bazel_skylib_workspace()

@ -0,0 +1,57 @@
#!/bin/bash
set -x
echo $@
set -euo pipefail
# --- begin runfiles.bash initialization ---
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---
TESTEE=unset
FAILURE_LIST=unset
TEXT_FORMAT_FAILURE_LIST=unset
while [[ -n "$@" ]]; do
arg="$1"; shift
val="$1"; shift
case "$arg" in
"--testee") TESTEE="$val" ;;
"--failure_list") FAILURE_LIST="$val" ;;
"--text_format_failure_list") TEXT_FORMAT_FAILURE_LIST="$val" ;;
*) echo "Flag $arg is not recognized." && exit 1 ;;
esac
done
conformance_test_runner=$(rlocation com_google_protobuf/conformance_test_runner)
conformance_testee=$(rlocation $TESTEE)
args=(--enforce_recommended)
failure_list=$(rlocation $FAILURE_LIST)
if [ "$failure_list" != "1" ] ; then
args+=(--failure_list $failure_list)
fi
text_format_failure_list=$(rlocation $TEXT_FORMAT_FAILURE_LIST)
if [ "$text_format_failure_list" != "1" ]; then
args+=(--text_format_failure_list $text_format_failure_list)
fi
$conformance_test_runner "${args[@]}" $conformance_testee

@ -0,0 +1,29 @@
# PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
def conformance_test(name, testee, failure_list = None, text_format_failure_list = None):
args = ["--testee %s" % _strip_bazel(testee)]
failure_lists = []
if failure_list:
args = args + ["--failure_list %s" % _strip_bazel(failure_list)]
failure_lists = failure_lists + [failure_list]
if text_format_failure_list:
args = args + ["--text_format_failure_list %s" % _strip_bazel(text_format_failure_list)]
failure_lists = failure_lists + [text_format_failure_list]
native.sh_test(
name = name,
srcs = ["//:conformance/conformance_test_runner.sh"],
data = [testee] + failure_lists + [
"//:conformance_test_runner",
],
args = args,
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)
def _strip_bazel(testee):
if testee.startswith("//"):
testee = testee.replace("//", "com_google_protobuf")
return testee.replace(":", "/")

@ -0,0 +1,8 @@
test_suite(
name = "tests",
tests = [
"//java/core:tests",
"//java/lite:tests",
"//java/util:tests",
],
)

@ -1,5 +1,8 @@
load("@rules_java//java:defs.bzl", "java_library") load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") load("@rules_java//java:defs.bzl", "java_library", "java_proto_library", "java_lite_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("//:internal.bzl", "conformance_test")
load("//java/internal:testing.bzl", "junit_tests")
LITE_SRCS = [ LITE_SRCS = [
# Keep in sync with `//java/lite:pom.xml`. # Keep in sync with `//java/lite:pom.xml`.
@ -95,12 +98,19 @@ LITE_SRCS = [
# Should be used as `//java/lite`. # Should be used as `//java/lite`.
java_library( java_library(
name = "lite", name = "lite",
srcs = LITE_SRCS, srcs = LITE_SRCS + [
"//:gen_well_known_protos_javalite"
],
visibility = [ visibility = [
"//java/lite:__pkg__", "//java/lite:__pkg__",
], ],
) )
java_library(
name = "lite_runtime_only",
srcs = LITE_SRCS,
)
java_library( java_library(
name = "core", name = "core",
srcs = glob( srcs = glob(
@ -113,10 +123,10 @@ java_library(
], ],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
exports = [ exports = [
"//java/lite", ":lite_runtime_only",
], ],
deps = [ deps = [
"//java/lite", ":lite_runtime_only",
], ],
) )
@ -126,3 +136,191 @@ proto_lang_toolchain(
runtime = ":core", runtime = ":core",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
proto_library(
name = "java_test_protos",
srcs = glob(["src/test/proto/**/*.proto"]),
strip_import_prefix = "src/test/proto",
deps = [
"//:any_proto",
"//:descriptor_proto",
"//:generic_test_protos",
"//:wrappers_proto",
],
)
java_proto_library(
name = "generic_test_protos_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = ["//:generic_test_protos"],
)
java_proto_library(
name = "java_test_protos_java_proto",
deps = [":java_test_protos"],
)
java_library(
name = "test_util",
srcs = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java"
],
deps = [
":core",
":generic_test_protos_java_proto",
":java_test_protos_java_proto",
"//external:guava",
"//external:junit",
],
)
test_suite(
name = "tests",
tests = [
"core_build_test",
"conformance_test",
"core_tests",
],
)
build_test(
name = "core_build_test",
targets = [
":core",
],
)
conformance_test(
name = "conformance_test",
testee = "//:conformance_java",
failure_list = "//:conformance/failure_list_java.txt",
text_format_failure_list = "//:conformance/text_format_failure_list_java.txt",
)
junit_tests(
name = "core_tests",
srcs = glob(["src/test/java/**/*.java"], exclude = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
]),
data = ["//:testdata"],
size = "large",
deps = [
":core",
":generic_test_protos_java_proto",
":java_test_protos_java_proto",
":test_util",
"//external:easymock",
"//external:easymock_classextension",
"//external:junit",
"//external:truth",
]
)
java_lite_proto_library(
name = "generic_test_protos_java_proto_lite",
visibility = [
"//java/lite:__pkg__",
],
deps = ["//:generic_test_protos"],
)
java_lite_proto_library(
name = "java_test_protos_java_proto_lite",
visibility = [
"//java/lite:__pkg__",
],
deps = [":java_test_protos"],
)
genrule(
name = "rewrite_javalite_test_util",
srcs = [
"//java/lite:lite.awk",
"src/test/java/com/google/protobuf/TestUtil.java"
],
outs = ["TestUtil.java"],
cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@"
)
java_library(
name = "test_util_lite",
srcs = [
":rewrite_javalite_test_util",
"src/test/java/com/google/protobuf/TestUtilLite.java"
],
visibility = [
"//java/lite:__pkg__",
],
deps = [
":generic_test_protos_java_proto_lite",
":java_test_protos_java_proto_lite",
":lite_runtime_only",
"//external:guava",
"//external:junit",
],
)
LITE_TEST_EXCLUSIONS = [
# Keep in sync with //java/lite:pom.xml id=copy-test-source-files execution.
"src/test/java/com/google/protobuf/AbstractMessageTest.java",
"src/test/java/com/google/protobuf/AbstractProto2SchemaTest.java",
"src/test/java/com/google/protobuf/AnyTest.java",
"src/test/java/com/google/protobuf/CodedInputStreamTest.java",
"src/test/java/com/google/protobuf/DeprecatedFieldTest.java",
"src/test/java/com/google/protobuf/DescriptorsTest.java",
"src/test/java/com/google/protobuf/DiscardUnknownFieldsTest.java",
"src/test/java/com/google/protobuf/DynamicMessageTest.java",
"src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java",
"src/test/java/com/google/protobuf/FieldPresenceTest.java",
"src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java",
"src/test/java/com/google/protobuf/GeneratedMessageTest.java",
"src/test/java/com/google/protobuf/LazyFieldTest.java",
"src/test/java/com/google/protobuf/LazyStringEndToEndTest.java",
"src/test/java/com/google/protobuf/MapForProto2Test.java",
"src/test/java/com/google/protobuf/MapTest.java",
"src/test/java/com/google/protobuf/MessageTest.java",
"src/test/java/com/google/protobuf/NestedBuildersTest.java",
"src/test/java/com/google/protobuf/PackedFieldTest.java",
"src/test/java/com/google/protobuf/ParserTest.java",
"src/test/java/com/google/protobuf/ParseExceptionsTest.java",
"src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java",
"src/test/java/com/google/protobuf/Proto2SchemaTest.java",
"src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java",
"src/test/java/com/google/protobuf/ServiceTest.java",
"src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java",
"src/test/java/com/google/protobuf/TestBadIdentifiers.java",
"src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java",
"src/test/java/com/google/protobuf/TextFormatParseLocationTest.java",
"src/test/java/com/google/protobuf/TextFormatTest.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
"src/test/java/com/google/protobuf/TypeRegistryTest.java",
"src/test/java/com/google/protobuf/UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetTest.java",
"src/test/java/com/google/protobuf/WellKnownTypesTest.java",
"src/test/java/com/google/protobuf/WireFormatTest.java",
]
junit_tests(
name = "lite_tests",
srcs = glob(["src/test/java/**/*.java"], exclude = LITE_TEST_EXCLUSIONS),
data = ["//:testdata"],
test_prefix = "Lite",
size = "large",
deps = [
":lite",
":generic_test_protos_java_proto_lite",
":java_test_protos_java_proto_lite",
":test_util_lite",
"//external:easymock",
"//external:easymock_classextension",
"//external:junit",
"//external:truth",
]
)

@ -0,0 +1 @@
package(default_visibility = ["//java:__subpackages__"])

@ -0,0 +1,72 @@
"""
Generates a side-car JUnit suite test runner class for each
input src.
"""
_template = """import org.junit.runners.Suite;
import org.junit.runner.RunWith;
@RunWith(Suite.class)
@Suite.SuiteClasses({%s})
public class %s {}
"""
def _as_classname(fname, pkg):
path_name = [x.path for x in fname.files.to_list()][0]
file_name = path_name.split("/")[-1]
return ".".join([pkg, file_name.split(".")[0]]) + ".class"
def _gen_suite_impl(ctx):
classes = ",".join(
[_as_classname(x, ctx.attr.package_name) for x in ctx.attr.srcs],
)
ctx.actions.write(output = ctx.outputs.out, content = _template % (
classes,
ctx.attr.outname,
))
_gen_suite = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"package_name": attr.string(),
"outname": attr.string(),
},
outputs = {"out": "%{name}.java"},
implementation = _gen_suite_impl,
)
def junit_tests(name, srcs, data = [], deps = [], package_name = "com.google.protobuf", test_prefix = None, **kwargs):
testlib_name = "%s_lib" % name
native.java_library(
name = testlib_name,
srcs = srcs,
deps = deps,
resources = data,
data = data,
)
test_names = []
prefix = name.replace("-", "_") + "TestSuite"
for src in srcs:
test_name = src.rsplit("/", 1)[1].split(".")[0]
if not test_name.endswith("Test") or test_name.startswith("Abstract"):
continue
if test_prefix:
test_name = "%s%s" % (test_prefix, test_name)
test_names = test_names + [test_name]
suite_name = prefix + '_' + test_name
_gen_suite(
name = suite_name,
srcs = [src],
package_name = package_name,
outname = suite_name,
)
native.java_test(
name = test_name,
test_class = suite_name,
srcs = [src] + [":" + suite_name],
deps = deps + [":%s" % testlib_name],
**kwargs
)
native.test_suite(
name = name,
tests = test_names,
)

@ -1,4 +1,9 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
load("//:internal.bzl", "conformance_test")
load("//java/internal:testing.bzl", "junit_tests")
exports_files(["lite.awk"], visibility = ["//java/core:__pkg__"])
alias( alias(
name = "lite", name = "lite",
@ -12,3 +17,40 @@ proto_lang_toolchain(
runtime = ":lite", runtime = ":lite",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
test_suite(
name = "tests",
tests = [
"lite_build_test",
"conformance_test",
"lite_tests",
"//java/core:lite_tests",
],
)
build_test(
name = "lite_build_test",
targets = [
":lite",
],
)
conformance_test(
name = "conformance_test",
testee = "//:conformance_java_lite",
failure_list = "//:conformance/failure_list_java_lite.txt",
text_format_failure_list = "//:conformance/text_format_failure_list_java_lite.txt",
)
junit_tests(
name = "lite_tests",
srcs = glob(["src/test/**/*.java"]),
size = "small",
deps = [
":lite",
"//external:junit",
"//java/core:generic_test_protos_java_proto_lite",
"//java/core:java_test_protos_java_proto_lite",
"//java/core:test_util_lite",
],
)

@ -199,6 +199,7 @@
and exclude only the full runtime exclusive tests so we don't accidentally miss and exclude only the full runtime exclusive tests so we don't accidentally miss
any test. --> any test. -->
<excludes> <excludes>
<!-- Keep in sync with //java/core:lite_tests BUILD rule. -->
<exclude>AbstractMessageTest.java</exclude> <exclude>AbstractMessageTest.java</exclude>
<exclude>AbstractProto2SchemaTest.java</exclude> <exclude>AbstractProto2SchemaTest.java</exclude>
<exclude>AnyTest.java</exclude> <exclude>AnyTest.java</exclude>

@ -1,4 +1,6 @@
load("@rules_java//java:defs.bzl", "java_library") load("@rules_java//java:defs.bzl", "java_library", "java_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//java/internal:testing.bzl", "junit_tests")
java_library( java_library(
name = "util", name = "util",
@ -14,3 +16,36 @@ java_library(
"//java/lite", "//java/lite",
], ],
) )
proto_library(
name = "test_protos",
srcs = glob(["src/test/proto/**/*.proto"]),
deps = [
"//:any_proto",
"//:duration_proto",
"//:field_mask_proto",
"//:struct_proto",
"//:timestamp_proto",
"//:wrappers_proto",
],
)
java_proto_library(
name = "test_protos_java_proto",
deps = [":test_protos"],
)
junit_tests(
name = "tests",
srcs = glob(["src/test/java/**/*.java"]),
package_name = "com.google.protobuf.util",
deps = [
":test_protos_java_proto",
":util",
"//external:guava",
"//external:junit",
"//external:truth",
"//java/core",
"//java/core:generic_test_protos_java_proto",
],
)

@ -328,7 +328,12 @@ def _internal_gen_well_known_protos_java_impl(ctx):
deps = [d[ProtoInfo] for d in ctx.attr.deps] deps = [d[ProtoInfo] for d in ctx.attr.deps]
srcjar = ctx.actions.declare_file("{}.srcjar".format(ctx.attr.name)) srcjar = ctx.actions.declare_file("{}.srcjar".format(ctx.attr.name))
args.add("--java_out", srcjar) if ctx.attr.javalite:
java_out = "lite:%s" % srcjar.path
else:
java_out = srcjar
args.add("--java_out", java_out)
descriptors = depset( descriptors = depset(
transitive = [dep.transitive_descriptor_sets for dep in deps], transitive = [dep.transitive_descriptor_sets for dep in deps],
@ -368,6 +373,9 @@ internal_gen_well_known_protos_java = rule(
mandatory = True, mandatory = True,
providers = [ProtoInfo], providers = [ProtoInfo],
), ),
"javalite": attr.bool(
default = False,
),
"_protoc": attr.label( "_protoc": attr.label(
executable = True, executable = True,
cfg = "host", cfg = "host",

@ -63,3 +63,11 @@ def protobuf_deps():
strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27", strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
urls = ["https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz"], urls = ["https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz"],
) )
if not native.existing_rule("rules_jvm_external"):
http_archive(
name = "rules_jvm_external",
sha256 = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169",
strip_prefix = "rules_jvm_external-4.0",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.0.zip"],
)

Loading…
Cancel
Save