默认情况下,文件下载者
http_file
可包括:
#include "external/<name>/file/<file_name>"
在这种情况下:
#include "external/catch/file/catch.hpp"
但是,这个包含路径很难看,应该用
cc_library
.
此外,为每个测试编译完整的catch头文件将使生成速度变慢。根据
catch docs
, the
实施
catch头的一部分应该单独编译。这样地:
测试/生成:
cc_library(
name = "catch",
hdrs = ["@catch//file"],
srcs = ["catch.cpp"],
visibility = ["//visibility:public"],
strip_include_prefix = "/external/catch/file",
include_prefix = "catch",
linkstatic = True, # otherwise main() will could end up in a .so
)
cc_test(
name = "my_test",
deps = ["//test:catch"],
srcs = ["my_test.cc"],
)
测试/catch.cpp:
#define CATCH_CONFIG_MAIN
#include "catch/catch.hpp"
测试/my_test.cc:
#include "catch/catch.hpp"
TEST_CASE("my_test", "[main]") { /* ... */ }
这种方式
catch.cpp
如果只有
my_test.cc
改变,节省宝贵的时间。