Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README-Bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ WPILib is normally built with Gradle, but [Bazel](https://www.bazel.build/) can
To build the entire repository, simply run `bazel build //...`. To run all of the unit tests, run `bazel test //...`
Other examples:
- `bazel build //wpimath/...` - Builds every target in the wpimath folder
- `bazel test //wpiutil:wpiutil-cpp-test` - Runs only the cpp test target in the wpiutil folder
- `bazel test //wpiutil:gtest_tests` - Runs only the gtest (C++) test target in the wpiutil folder
- `bazel run //wpiutil:java_tests` - Runs only the java test target in the wpiutil folder
- `bazel test //wpiutil:python_tests` - Runs only the python test target in the wpiutil folder
- `bazel coverage //wpiutil/...` - (*Nix only) - Runs a code coverage report for both C++ and Java on all the targets under wpiutil

## User settings
Expand Down
4 changes: 2 additions & 2 deletions apriltag/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pkg_files(
)

cc_test(
name = "apriltag-cpp-test",
name = "gtest_tests",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this tests the code built by the apriltag rule I recommend naming it apriltag_test or apriltag_tests.

This is convention used internally at Google. When you are making changes to code built by a C++ library target named "foo", and you want to run the tests for that target, the target is generally named "foo_test", which is easy to remember. The same convention is used for Python and Go.

(you can, of course, run all of the tests in the package via :all, but for some packages that can be slow, so people would iterate by running the individual target, and run all of the tests before committing)

If you use bash or zsh and setup autocompletion then you can type "bazel test //apriltag:foo_" and press tab and it will auto-complete (so I don't have to remember whether the build target ends in "s").

I personally don't see the benefit to encoding the test framework in the build target. Would it be common for a single build target to have multiple test targets, each using different test frameworks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merry Christmas!

Since this tests the code built by the apriltag rule I recommend naming it apriltag_test or apriltag_tests.

apriltag_test or apriltag_tests wouldn't work, since we need to include some information about the language to disambiguate the C++, Java, and Python test targets.

When you are making changes to code built by a C++ library target named "foo", and you want to run the tests for that target, the target is generally named "foo_test", which is easy to remember.

In allwpilib, there's a one-to-one correspondence between packages and library targets, so there's no point in including the library target name in the test name (because it's identical to the package name). See also this thread for previous discussion on dropping the package name.

Would it be common for a single build target to have multiple test targets, each using different test frameworks?

Right now, wpiutil has both, so there needs to be some way to disambiguate the two. That's probably going to be the only case, though, so it maybe it'd be better to use cpp_tests for everything except wpiutil? CC @pjreiniger since you recommended switching to gtest_tests and catch2_tests.

size = "small",
srcs = glob(["src/test/native/cpp/**"]),
tags = [
Expand All @@ -173,7 +173,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "apriltag-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
resource_strip_prefix = "apriltag/src/test/resources",
resources = glob(["src/test/resources/**"]),
Expand Down
2 changes: 1 addition & 1 deletion cameraserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ wpilib_java_library(
)

cc_test(
name = "cameraserver-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**"]),
deps = [
Expand Down
4 changes: 2 additions & 2 deletions commandsv2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ wpilib_java_library(
)

cc_test(
name = "commandsv2-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob([
"src/test/native/**/*.cpp",
Expand All @@ -141,7 +141,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "commandsv2-java-test",
name = "java_tests",
srcs = glob(["src/main/java/**/*.java"]),
resource_strip_prefix = "commandsv2/src/test/resources",
resources = glob(["src/test/resources/**"]),
Expand Down
2 changes: 1 addition & 1 deletion commandsv3/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ wpilib_java_library(
)

wpilib_java_junit5_test(
name = "commandsv3-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
plugins = [
"//epilogue-processor:plugin",
Expand Down
4 changes: 2 additions & 2 deletions cscore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ wpilib_jni_java_library(
)

cc_test(
name = "cscore-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**"]),
deps = [
Expand All @@ -231,7 +231,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "cscore-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":cscore-java",
Expand Down
6 changes: 3 additions & 3 deletions datalog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ cc_binary(
)

cc_test(
name = "datalog-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**/*.cpp"]),
tags = [
Expand All @@ -154,7 +154,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "datalog-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
tags = ["exclusive"],
deps = [
Expand Down Expand Up @@ -206,7 +206,7 @@ define_pybind_library(
)

robotpy_py_test(
"datalog_tests",
"python_tests",
srcs = glob(["src/test/python/**/*.py"]),
deps = [
":robotpy-wpilog",
Expand Down
2 changes: 1 addition & 1 deletion epilogue-processor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ java_plugin(
)

wpilib_java_junit5_test(
name = "processor-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
plugins = [
":plugin",
Expand Down
2 changes: 1 addition & 1 deletion epilogue-runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ wpilib_java_library(
)

wpilib_java_junit5_test(
name = "epilogue-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":epilogue-java",
Expand Down
2 changes: 1 addition & 1 deletion fields/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pkg_files(
)

wpilib_java_junit5_test(
name = "fields-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":fields-java",
Expand Down
4 changes: 2 additions & 2 deletions hal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ wpilib_jni_java_library(
)

cc_test(
name = "hal-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**/*.cpp"]),
deps = [
Expand All @@ -203,7 +203,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "hal-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":hal-java",
Expand Down
4 changes: 2 additions & 2 deletions ntcore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ wpilib_jni_java_library(
)

cc_test(
name = "ntcore-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob([
"src/test/native/**/*.cpp",
Expand All @@ -196,7 +196,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "ntcore-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
tags = ["exclusive"],
deps = [
Expand Down
2 changes: 1 addition & 1 deletion romiVendordep/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ wpilib_java_library(
)

cc_test(
name = "romi-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/cpp/**"]),
deps = [
Expand Down
2 changes: 1 addition & 1 deletion shared/bazel/rules/java_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def wpilib_java_junit5_test(
"@maven//:org_junit_platform_junit_platform_console",
]

# TODO - replace with java_test once shared libraries are hooked up.
# TODO - replace with java_test once shared libraries are hooked up, and update aliases to use test_suite
java_binary(
name = name,
deps = deps + junit_deps,
Expand Down
2 changes: 1 addition & 1 deletion simulation/halsim_ds_socket/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ wpilib_cc_static_library(
)

cc_test(
name = "halsim_ds_socket-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**/*.cpp"]),
deps = [
Expand Down
2 changes: 1 addition & 1 deletion simulation/halsim_gui/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ wpilib_cc_static_library(
)

cc_test(
name = "halsim_gui-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**/*.cpp"]),
tags = [
Expand Down
2 changes: 1 addition & 1 deletion simulation/halsim_ws_server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cc_library(
)

cc_test(
name = "halsim_ws_server-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/**/*.cpp"]),
tags = [
Expand Down
7 changes: 6 additions & 1 deletion tools/sysid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cc_binary(
)

cc_test(
name = "sysid-test",
name = "gtest_tests",
size = "medium",
srcs = glob(["src/test/native/cpp/**"]),
tags = [
Expand All @@ -57,6 +57,11 @@ cc_test(
],
)

test_suite(
name = "tests",
tests = ["gtest_tests"],
)

package_binary_cc_project(
name = "sysid",
maven_artifact_name = "SysId",
Expand Down
7 changes: 6 additions & 1 deletion tools/wpical/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ cc_binary(
)

cc_test(
name = "wpical_test",
name = "gtest_tests",
size = "medium",
srcs = glob(["src/test/native/**"]),
copts = copts,
Expand All @@ -239,6 +239,11 @@ cc_test(
],
)

test_suite(
name = "tests",
tests = ["gtest_tests"],
)

package_binary_cc_project(
name = "wpical",
extra_files = [":licenses"],
Expand Down
2 changes: 1 addition & 1 deletion wpilibc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ cc_library(
)

cc_test(
name = "wpilibc-test",
name = "gtest_tests",
size = "small",
srcs = glob(["src/test/native/cpp/**"]),
tags = [
Expand Down
6 changes: 5 additions & 1 deletion wpilibcExamples/build_cpp_examples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_tests():
example_src_folder = "src/main/cpp/examples/" + folder
example_test_folder = "src/test/cpp/examples/" + folder
cc_test(
name = folder + "-test",
name = folder + "_gtest_tests",
size = "small",
srcs = native.glob([example_test_folder + "/**/*.cpp", example_src_folder + "/cpp/**/*.cpp", example_src_folder + "/c/**/*.c"], allow_empty = True),
deps = [
Expand All @@ -111,3 +111,7 @@ def build_tests():
defines = ["RUNNING_WPILIB_TESTS=1"],
tags = ["wpi-example", "no-tsan", "no-asan", "no-ubsan", "exclusive"],
)
native.test_suite(
name = folder + "_tests",
tests = [folder + "_gtest_tests"],
)
2 changes: 1 addition & 1 deletion wpilibj/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pkg_files(
)

wpilib_java_junit5_test(
name = "wpilibj-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
resource_strip_prefix = "wpilibj/src/test/resources",
resources = glob(["src/test/resources/**"]),
Expand Down
6 changes: 5 additions & 1 deletion wpilibjExamples/build_java_examples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def build_templates():
def build_tests():
for folder in TEST_FOLDERS:
wpilib_java_junit5_test(
name = folder + "-test",
name = folder + "_java_tests",
srcs = native.glob(["src/test/java/org/wpilib/examples/" + folder + "/**/*.java"]),
deps = [
":" + folder + "-example",
Expand All @@ -122,3 +122,7 @@ def build_tests():
],
tags = ["wpi-example"],
)
native.alias(
name = folder + "_tests",
actual = folder + "_java_tests",
)
4 changes: 2 additions & 2 deletions wpimath/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ cc_library(
)

cc_test(
name = "wpimath-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob([
"src/test/native/cpp/**/*.cpp",
Expand All @@ -281,7 +281,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "wpimath-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":wpimath-java",
Expand Down
4 changes: 2 additions & 2 deletions wpinet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ wpilib_jni_java_library(
)

cc_test(
name = "wpinet-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob([
"src/test/native/**/*.cpp",
Expand All @@ -232,7 +232,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "wpinet-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":wpinet-java",
Expand Down
2 changes: 1 addition & 1 deletion wpiunits/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ wpilib_java_library(
)

wpilib_java_junit5_test(
name = "wpiunits-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":wpiunits-java",
Expand Down
8 changes: 4 additions & 4 deletions wpiutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ CATCH2_SRCS = [
]

cc_test(
name = "wpiutil-gtest-cpp-test",
name = "gtest_tests",
size = "small",
srcs = glob(
[
Expand All @@ -314,7 +314,7 @@ cc_test(
)

cc_test(
name = "wpiutil-catch2-cpp-test",
name = "catch2_tests",
size = "small",
srcs = CATCH2_SRCS,
linkstatic = True,
Expand All @@ -326,7 +326,7 @@ cc_test(
)

wpilib_java_junit5_test(
name = "wpiutil-java-test",
name = "java_tests",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
":wpiutil-java",
Expand Down Expand Up @@ -427,7 +427,7 @@ py_library(
)

robotpy_py_test(
"wpiutil_tests",
"python_tests",
srcs = glob(
["src/test/python/**/*.py"],
exclude = ["src/test/python/cpp/**"],
Expand Down
Loading
Loading