I have a C++ project, and I want to use bazel coverage
to get its code coverage information.
However, after running the command, I find the file coverage.dat
inside bazel-testlogs
does not contain anything.
So am I looking at the right place? Or is there some problem with Bazel?
I am using Bazel 1.0.0.
Complete Example
WORKSPACE
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "gtest",
remote = "https://github.com/google/googletest",
commit = "3306848f697568aacf4bcca330f6bdd5ce671899",
)
lib/a.cc
int f(int x) {
if (x == 0)
return x + 1;
else
return 1 + x;
}
lib/BUILD
cc_library(
name = "a",
srcs = ["a.cc"],
visibility = ["//test:__pkg__"],
)
test/my_test.cc
#include "gtest/gtest.h"
TEST(FactorialTest, Negative) {
EXPECT_EQ(1, 1);
}
test/BUILD
cc_test(
name = "my_test",
srcs = ["my_test.cc"],
copts = ["-Iexternal/gtest"],
deps = ["@gtest//:gtest_main", "//lib:a"],
)
After I run bazel coverage //test:my_test
, I see a file at bazel-testlogs/test/my_test/coverage.dat
generated, but it is empty (0 bytes).