diff --git a/stic/run-tests b/stic/run-tests index f5dd85517..89796ab8a 100755 --- a/stic/run-tests +++ b/stic/run-tests @@ -1,3 +1,3 @@ #!/usr/bin/env bash -bazel build //test:all-tests && bazel-bin/test/all-tests +bazel test //test:all-tests diff --git a/stic/test/BUILD b/stic/test/BUILD index e5abc9c30..33d64daf6 100644 --- a/stic/test/BUILD +++ b/stic/test/BUILD @@ -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" ] ) diff --git a/stic/test/macros.bzl b/stic/test/macros.bzl new file mode 100644 index 000000000..3cb01ee14 --- /dev/null +++ b/stic/test/macros.bzl @@ -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 + ] + )