Skip to content

Commit

Permalink
Move java_test_suite rule to test.bzl
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jul 16, 2019
1 parent a94c564 commit 3f56851
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 82 deletions.
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/atoms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//:copy_file.bzl", "copy_file")
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

copy_file(
name = "execute_script",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/devtools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

DEV_TOOLS_BROWSERS = {
"chrome": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_library(
name = "environment",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/io/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/json/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/net/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_library(
name = "net",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/os/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "AllTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "MediumTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_library(
name = "test-lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_library(
name = "annotations",
Expand Down
59 changes: 0 additions & 59 deletions java/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,62 +57,3 @@ def java_binary(name, maven_coords = None, deps = [], **kwargs):
deps = all_deps,
**kwargs
)

def java_test_suite(
name,
srcs,
resources=None,
jvm_flags=[],
deps=None,
visibility=None,
size = None,
tags = []):

# By default bazel computes the name of test classes based on the
# standard Maven directory structure, which we don't use in
# Selenium, so try to compute the correct package name.
pkg = native.package_name()
idx = pkg.find("/com/")
if idx == -1:
idx = pkg.find("/org/")
if idx != -1:
pkg = pkg[idx+1:].replace("/", ".")
else:
pkg = None

tests = []

actual_tags = []
actual_tags.extend(tags)
if "small" != size:
actual_tags.append("no-sandbox")

for src in srcs:
if src.endswith('Test.java'):
test_name = src[:-len('.java')]

tests += [test_name]
test_class = None
if pkg != None:
test_class = pkg + "." + test_name.replace("/", ".")

if test_name in native.existing_rules():
test_name = "%s-%s" % (name, test_name)

native.java_test(
name = test_name,
srcs = [src],
size = size,
jvm_flags = jvm_flags,
test_class = test_class,
resources = resources,
tags = actual_tags,
deps = deps,
visibility = ["//visibility:private"])

native.test_suite(
name = name,
tests = tests,
tags = ["manual"] + tags,
visibility = visibility)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "MediumTests",
Expand All @@ -15,4 +15,4 @@ java_test_suite(
"//third_party/java/jetty",
"//third_party/java/junit",
]
)
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
2 changes: 1 addition & 1 deletion java/server/test/org/openqa/selenium/grid/data/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "MediumTests",
Expand Down
2 changes: 1 addition & 1 deletion java/server/test/org/openqa/selenium/grid/node/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "MediumTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "MediumTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
2 changes: 1 addition & 1 deletion java/server/test/org/openqa/selenium/grid/web/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//java:rules.bzl", "java_test_suite")
load("//java:test.bzl", "java_test_suite")

java_test_suite(
name = "SmallTests",
Expand Down
50 changes: 50 additions & 0 deletions java/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,53 @@ def java_selenium_test_suite(
native.test_suite(name = test_name, tests = tests, tags = ["manual"])
suites.append(test_name)
native.test_suite(name = name, tests = suites, tags = tags + ["manual"])


def java_test_suite(
name,
srcs,
resources=None,
jvm_flags=[],
deps=None,
visibility=None,
size = None,
tags = []):

# By default bazel computes the name of test classes based on the
# standard Maven directory structure, which we don't use in
# Selenium, so try to compute the correct package name.
pkg = _package_name()

tests = []

actual_tags = []
actual_tags.extend(tags)
if "small" != size:
actual_tags.append("no-sandbox")

for src in srcs:
if src.endswith('Test.java'):
test_name = src[:-len('.java')]

test_class = _test_class_name(src)

if test_name in native.existing_rules():
test_name = "%s-%s" % (name, test_name)
tests += [test_name]

native.java_test(
name = test_name,
srcs = [src],
size = size,
jvm_flags = jvm_flags,
test_class = test_class,
resources = resources,
tags = actual_tags,
deps = deps,
visibility = ["//visibility:private"])

native.test_suite(
name = name,
tests = tests,
tags = ["manual"] + tags,
visibility = visibility)

0 comments on commit 3f56851

Please sign in to comment.