Add target tests to CQ
Change-Id: I3a403af1722c9b6e7d89d45257f90a15b7590dec
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-integration/+/787722
Commit-Queue: Chase Latta <chaselatta@google.com>
Reviewed-by: Darren Chan <chandarren@google.com>
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..48d40d1
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "tests/third_party/googletest"]
+ path = tests/third_party/googletest
+ url = https://fuchsia.googlesource.com/third_party/github.com/google/googletest
+ branch = sandbox/fuchsia_bazel_sdk
diff --git a/scripts/run_bazel_tests.sh b/scripts/run_bazel_tests.sh
index c8284ca..d27088e 100755
--- a/scripts/run_bazel_tests.sh
+++ b/scripts/run_bazel_tests.sh
@@ -57,7 +57,6 @@
validate_tests_for_tools() {
for suite in "${TEST_SUITES[@]}"; do
(
- cd "${TESTS_ROOT}"
show_run_test_message "${suite}"
run_bazel test --test_output=all "${suite}"
) || exit 1
@@ -67,7 +66,6 @@
run_build_only_tests() {
for suite in "${BUILD_ONLY_TEST_SUITES[@]}"; do
(
- cd "${TESTS_ROOT}"
for config in "${BUILD_ONLY_TEST_CONFIGS[@]}"; do
show_build_only_test_message "${suite}" "${config}"
run_bazel build --config="${config}" "${suite}"
@@ -94,6 +92,8 @@
done
run_bootstrap
+
+ cd "${TESTS_ROOT}"
validate_tests_for_tools
run_build_only_tests
}
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index 9d10eb9..f296595 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -59,7 +59,9 @@
name = "build_only_tests",
srcs = [
"//examples/hello_world_cpp:pkg",
+ "//examples/hello_world_cpp:test_pkg",
],
+ testonly = True,
)
# The workstation product bundle for running the emulator
diff --git a/tests/WORKSPACE.bazel b/tests/WORKSPACE.bazel
index cfcdbc1..0e02e19 100644
--- a/tests/WORKSPACE.bazel
+++ b/tests/WORKSPACE.bazel
@@ -76,3 +76,8 @@
],
)
+# gTest.
+local_repository(
+ name = "com_google_googletest",
+ path = "third_party/googletest",
+)
diff --git a/tests/examples/hello_world_cpp/BUILD.bazel b/tests/examples/hello_world_cpp/BUILD.bazel
index d14ee17..87c35f6 100644
--- a/tests/examples/hello_world_cpp/BUILD.bazel
+++ b/tests/examples/hello_world_cpp/BUILD.bazel
@@ -5,9 +5,12 @@
load(
"@rules_fuchsia//fuchsia:defs.bzl",
"fuchsia_cc_binary",
+ "fuchsia_cc_test",
"fuchsia_component",
"fuchsia_component_manifest",
"fuchsia_package",
+ "fuchsia_test_package",
+ "if_fuchsia",
)
fuchsia_cc_binary(
@@ -46,3 +49,25 @@
],
visibility = ["//visibility:public"],
)
+
+fuchsia_cc_test(
+ name = "hello_test",
+ size = "small",
+ srcs = ["hello_test.cc"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "@com_google_googletest//:gtest_main",
+ ] + if_fuchsia([
+ "@fuchsia_sdk//pkg/fdio",
+ "@fuchsia_sdk//pkg/syslog",
+ ]),
+)
+
+fuchsia_test_package(
+ name = "test_pkg",
+ package_name = "hello_tests",
+ test_components = [
+ ":hello_test",
+ ],
+ visibility = ["//visibility:public"],
+)
diff --git a/tests/examples/hello_world_cpp/hello_test.cc b/tests/examples/hello_world_cpp/hello_test.cc
new file mode 100644
index 0000000..5fda0b5
--- /dev/null
+++ b/tests/examples/hello_world_cpp/hello_test.cc
@@ -0,0 +1,9 @@
+// Copyright 2023 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gtest/gtest.h>
+
+TEST(HelloTest, Addition) {
+ EXPECT_EQ(1 + 1, 2);
+}
diff --git a/tests/third_party/googletest b/tests/third_party/googletest
new file mode 160000
index 0000000..0b56cbe
--- /dev/null
+++ b/tests/third_party/googletest
@@ -0,0 +1 @@
+Subproject commit 0b56cbec076adbb75d22e3d9f75e99ad063d1ac3