diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-29 01:06:04 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-29 01:06:04 +0000 |
commit | 09b3a0d2bb1fd662c14a1e7d8e2b6db9c0481fa8 (patch) | |
tree | 329839a67b2b6d2a26d17780d4002e4eee0808fd /lib/test_suite.bzl | |
parent | 74bdad7c2e3a8531da040325cd8102a6ec73d9cf (diff) | |
parent | d605057434dcabba796c020773aab68d9790ff9f (diff) | |
download | bazelbuild-rules_testing-09b3a0d2bb1fd662c14a1e7d8e2b6db9c0481fa8.tar.gz |
Snap for 10878163 from d605057434dcabba796c020773aab68d9790ff9f to 24Q1-releaseandroid-14.0.0_r37android-14.0.0_r36android-14.0.0_r35android-14.0.0_r34android-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android-14.0.0_r28android14-qpr2-s5-releaseandroid14-qpr2-s4-releaseandroid14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: I5432c013e363b410651db122ce34f909f023d8bf
Diffstat (limited to 'lib/test_suite.bzl')
-rw-r--r-- | lib/test_suite.bzl | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/test_suite.bzl b/lib/test_suite.bzl new file mode 100644 index 0000000..d26c02f --- /dev/null +++ b/lib/test_suite.bzl @@ -0,0 +1,64 @@ +"""# Test suite + +Aggregates multiple Starlark tests in a single test_suite. +""" + +load("//lib/private:util.bzl", "get_test_name_from_function") +load("//lib:unit_test.bzl", "unit_test") + +def test_suite(name, *, tests = [], basic_tests = [], test_kwargs = {}): + """Instantiates given test macros/implementations and gathers their main targets into a `test_suite`. + + Use this function to wrap all tests into a single target. + + ``` + def simple_test_suite(name): + test_suite( + name = name, + tests = [ + your_test, + your_other_test, + ] + ) + ``` + + Then, in your `BUILD` file, simply load the macro and invoke it to have all + of the targets created: + + ``` + load("//path/to/your/package:tests.bzl", "simple_test_suite") + simple_test_suite(name = "simple_test_suite") + ``` + + Args: + name: (str) The name of the suite + tests: (list of callables) Test macros functions that + define a test. The signature is `def setup(name, **test_kwargs)`, + where (positional) `name` is name of the test target that must be + created, and `**test_kwargs` are the additional arguments from the + test suite's `test_kwargs` arg. The name of the function will + become the name of the test. + basic_tests: (list of callables) Test implementation functions + (functions that implement a test's asserts). Each callable takes a + single positional arg, `env`, which is information about the test + environment (see analysis_test docs). The name of the function will + become the name of the test. + test_kwargs: (dict) Additional kwargs to pass onto each test (both + regular and basic test callables). + """ + test_targets = [] + + for setup_func in tests: + test_name = get_test_name_from_function(setup_func) + setup_func(name = test_name, **test_kwargs) + test_targets.append(test_name) + + for impl in basic_tests: + test_name = get_test_name_from_function(impl) + unit_test(name = test_name, impl = impl, **test_kwargs) + test_targets.append(test_name) + + native.test_suite( + name = name, + tests = test_targets, + ) |