Reputation: 1
I am extremely new to Bazel and Gtest and have been trying to run the tests on a cpp file called "species_test".cpp. This is the main error that I keep getting:
Wills-iMac:species Will$ bazel test species_test --test_output=all
ERROR: Skipping 'species_test': no such target '//species:species_test': target 'species_test' not declared in package 'species' defined by /Users/Will/git/orville-regularwills/species/BUILD.bazel
ERROR: no such target '//species:species_test': target 'species_test' not declared in package 'species' defined by /Users/Will/git/orville-regularwills/species/BUILD.bazel
INFO: Elapsed time: 0.473s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)
I have two BUILD.bazel files: this one is for the .cpp class implementation:
cc_library(
name="species",
srcs=glob(["*.cpp"]),
hdrs=glob(["*.h"]),
visibility=["//visibility:public"]
)
and this one is for the file for google test that has species_test.cpp:
cc_test(
name="species_test",
srcs=["species_test.cpp"],
copts=["-Iexternal/gtest/include"],
deps=[
"@gtest//::main",
"//species"
]
)
and here is my workspace file:
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "gtest",
remote = "https://github.com/google/googletest",
branch = "v1.10.x",
)
I have no idea what the error is referring to and greatly appreciate anything that points me in the right direction or clears anything up.
Upvotes: 0
Views: 7513
Reputation: 1304
Read https://docs.bazel.build/versions/master/build-ref.html . Package (directory) should contain only one BUILD
file. Files layout should looks like that one:
├── WORKSPACE
└── species
├── BUILD
├── species.cpp
├── species.hpp
└── species_test.cpp
and BUILD
file:
cc_library(
name="species",
srcs=["species.cpp"],
hdrs=["species.hpp"],
visibility=["//visibility:public"]
)
cc_test(
name="species_test",
srcs=["species_test.cpp"],
deps=[
"@gtest//:main",
":species"
]
)
Notice changes:
glob
call, because in your version the species
library will also compile the test file, which is not wantedspecies.hpp
header, because library without a public interface is not usable by other targetscopts
to set an include path as Bazel will do this for you@gtest//::main
-> @gtest//:main
: in Bazel you use one colon to indicate a targetcc_test
rule depend on species
target. :species
is label for a target in the same package. Alternatively you can use full path //species:species
, where first species
is the name of package (same as directory path from the root, which is a WORKSPACE
directory) and the :species
is a name of your cc_library
targetUpvotes: 1