-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bazel] Define a macro to generate test cases
The `gen_java_tests` macro expands all the `srcs` into individual `java_test` targets. In order to reduce compilation time, a `java_library` is generated. Should you wish to use a test suite, then the original `java_test` rule is still available and should be used.
- Loading branch information
Showing
12 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
_PREFIXES = ("com", "io", "net", "org") | ||
|
||
def _contains(list, value): | ||
for v in list: | ||
if v == value: | ||
return True | ||
return False | ||
|
||
def _shortName(file): | ||
base = file.rpartition("/")[-1] | ||
return base.rpartition(".")[0] | ||
|
||
# We assume that package name matches directory structure, which may not | ||
# actually be true, but is for Selenium. | ||
def _className(file): | ||
dir = native.package_name() | ||
|
||
segments = dir.split('/') | ||
idx = len(segments) - 1 | ||
for i, segment in enumerate(segments): | ||
if _contains(_PREFIXES, segment): | ||
idx = i | ||
break | ||
return ".".join(segments[idx:]) + "." + _shortName(file) | ||
|
||
def _impl(ctx): | ||
for src in ctx.files.srcs: | ||
test = native.java_test( | ||
name = _shortName(src), | ||
test_class = _className(src), | ||
srcs = ctx.attr.srcs, | ||
size = ctx.attr.size, | ||
deps = ctx.attr.deps) | ||
print(test) | ||
|
||
def gen_java_tests(name, srcs=[], deps=[], **kwargs): | ||
native.java_library( | ||
name = "%s-lib" % name, | ||
srcs = srcs, | ||
deps = deps) | ||
|
||
deps.append(":%s-lib" % name) | ||
|
||
for src in srcs: | ||
native.java_test( | ||
name = _shortName(src), | ||
test_class = _className(src), | ||
runtime_deps = deps, | ||
**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
java/server/src/org/openqa/selenium/grid/sessionmap/remote/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
java_library( | ||
name = "remote", | ||
srcs = glob(["*.java"]), | ||
deps = [ | ||
"//java/server/src/org/openqa/selenium/grid/sessionmap", | ||
], | ||
visibility = [ | ||
"//java/server/src/org/openqa/selenium/grid:__subpackages__", | ||
"//java/server/test/org/openqa/selenium/grid:__subpackages__", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
java/server/test/org/openqa/selenium/grid/sessionmap/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//java:bazel-rules.bzl", "gen_java_tests") | ||
|
||
gen_java_tests( | ||
name = "sessionmap", | ||
srcs = glob(["*.java"]), | ||
size = "small", | ||
deps = [ | ||
"//java/server/src/org/openqa/selenium/grid/sessionmap", | ||
"//java/server/src/org/openqa/selenium/grid/sessionmap/local", | ||
"//java/server/src/org/openqa/selenium/grid/sessionmap/remote", | ||
"//java/server/test/org/openqa/selenium/grid/web:utils", | ||
"//third_party/java/assertj", | ||
"//third_party/java/junit", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("//java:bazel-rules.bzl", "gen_java_tests") | ||
|
||
gen_java_tests( | ||
name = "web", | ||
size = "small", | ||
srcs = glob(["*Test.java"]), | ||
deps = [ | ||
":utils", | ||
"//java/server/src/org/openqa/selenium/injector", | ||
"//java/server/src/org/openqa/selenium/grid/web", | ||
"//third_party/java/assertj", | ||
"//third_party/java/guava:guava", | ||
"//third_party/java/junit", | ||
], | ||
) | ||
|
||
java_library( | ||
name = "utils", | ||
srcs = glob(["*.java"], exclude = ["*Test.java"]), | ||
deps = [ | ||
"//java/client/src/org/openqa/selenium/remote", | ||
"//java/server/src/org/openqa/selenium/grid/web", | ||
], | ||
visibility = [ | ||
"//java/server/test/org/openqa/selenium/grid:__subpackages__", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
java_import( | ||
name = 'assertj', | ||
licenses = [ | ||
"notice", # Apache 2 | ||
], | ||
jars = [ | ||
'assertj-core-3.11.1.jar', | ||
], | ||
srcjar = 'assertj-core-3.11.1-sources.jar', | ||
visibility = [ | ||
'//java/client/test:__subpackages__', | ||
], | ||
name = "assertj", | ||
tags = [ | ||
"maven_coordinates=org.assertj:assertj-core:jar:3.11.1", | ||
], | ||
licenses = [ | ||
"notice", # Apache 2 | ||
], | ||
jars = ["assertj-core-3.11.1.jar"], | ||
srcjar = "assertj-core-3.11.1-sources.jar", | ||
visibility = [ | ||
"//java/client/test:__subpackages__", | ||
"//java/server/test:__subpackages__", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
java_import( | ||
name = "hamcrest-core", | ||
tags = [ | ||
"maven_coordinates=org.hamcrest:hamcrest-core:jar:1.3", | ||
], | ||
licenses = [ | ||
"notice", # BSD | ||
], | ||
jars = ["hamcrest-core-1.3.jar"], | ||
srcjar = "hamcrest-core-1.3-sources.jar", | ||
visibility = [ | ||
"//third_party/java/junit:__pkg__", | ||
], | ||
) | ||
|
||
java_import( | ||
name = "hamcrest-library", | ||
tags = [ | ||
"maven_coordinates=org.hamcrest:hamcrest-library:jar:1.3", | ||
], | ||
licenses = [ | ||
"notice", # BSD | ||
], | ||
jars = ["hamcrest-library-1.3.jar"], | ||
srcjar = "hamcrest-library-1.3-sources.jar", | ||
deps = [ | ||
":hamcrest-core", | ||
], | ||
visibility = [ | ||
"//java/client/test:__subpackages__", | ||
"//java/server/test:__subpackages__", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
java_import( | ||
name = 'junit', | ||
licenses = [ | ||
"notice", # Eclipse Public License - v 1.0 | ||
], | ||
jars = [ | ||
'junit-4.12.jar', | ||
], | ||
srcjar = 'junit-4.12-sources.jar', | ||
visibility = [ | ||
'//java/client/test:__subpackages__', | ||
], | ||
name = "junit", | ||
tags = [ | ||
"maven_coordinates=junit:junit:jar:4.12", | ||
], | ||
licenses = [ | ||
"reciprocal", # EPL | ||
], | ||
jars = ["junit-4.12.jar"], | ||
srcjar = "junit-4.12-sources.jar", | ||
deps = [ | ||
"//third_party/java/hamcrest:hamcrest-core", | ||
], | ||
visibility = [ | ||
"//java/client/test:__subpackages__", | ||
"//java/server/test:__subpackages__", | ||
], | ||
) |