Simplified definition of tests.

This commit is contained in:
Martin Sosic 2018-09-29 11:29:04 +02:00
parent 6003d8346f
commit 0b5a88b9ab
3 changed files with 25 additions and 10 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash
bazel build //test:all-tests && bazel-bin/test/all-tests
bazel test //test:all-tests

View File

@ -1,8 +1,12 @@
load(":macros.bzl", "simple_target_test")
# Catch2 is test framework that we are using. It has only one header file, which we included directly in code.
cc_library(
name = "catch2",
hdrs = ["catch.hpp"]
)
# In order to be able to run Catch2 tests, it is important to have this main method defined (as by Catch2 documentation).
cc_library(
name = "catch-main",
srcs = ["main.cpp"],
@ -11,16 +15,14 @@ cc_library(
]
)
# TODO: I could use macros to define each test individiually in easy way.
# Individual tests (per target). Each expects .test.cpp file with same name to exist.
# Add new tests here! Also, add them to test suite all-tests below.
simple_target_test("hello-world")
cc_test(
# Test suite that runs all the tests.
test_suite(
name = "all-tests",
srcs = glob(["**/*.test.cpp"]),
copts = ["-Isrc/"],
deps = [
":catch2",
"catch-main",
"//src:hello-world"
tests = [
"hello-world"
]
)

13
stic/test/macros.bzl Normal file
View File

@ -0,0 +1,13 @@
# Given target name from //src package, expects .test.cpp file with same name.
# Creates a cc_test for that target.
def simple_target_test(target_name):
native.cc_test(
name = target_name,
srcs = [target_name + ".test.cpp"],
copts = ["-Isrc/"],
deps = [
":catch2",
"catch-main",
"//src:" + target_name
]
)