diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index 5472d74..facd55f 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -94,9 +94,9 @@ A rule definition that should be stored in a global whose name ends in analysistest.begin(ctx) -Begins a unit test. +Begins an analysis test. -This should be the first function called in a unit test implementation +This should be the first function called in an analysis test implementation function. It initializes a "test environment" that is used to collect assertion failures so that they can be reported and logged at the end of the test. @@ -112,7 +112,7 @@ test. **RETURNS** A test environment struct that must be passed to assertions and finally to -`unittest.end`. Do not rely on internal details about the fields in this +`analysistest.end`. Do not rely on internal details about the fields in this struct as it may change. diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 3757b08..badb462 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -364,6 +364,25 @@ def _begin(ctx): """ return struct(ctx = ctx, failures = []) +def _begin_analysis_test(ctx): + """Begins an analysis test. + + This should be the first function called in an analysis test implementation + function. It initializes a "test environment" that is used to collect + assertion failures so that they can be reported and logged at the end of the + test. + + Args: + ctx: The Starlark context. Pass the implementation function's `ctx` argument + in verbatim. + + Returns: + A test environment struct that must be passed to assertions and finally to + `analysistest.end`. Do not rely on internal details about the fields in this + struct as it may change. + """ + return struct(ctx = ctx, failures = []) + def _end_analysis_test(env): """Ends an analysis test and logs the results. @@ -647,7 +666,7 @@ unittest = struct( analysistest = struct( make = _make_analysis_test, - begin = _begin, + begin = _begin_analysis_test, end = _end_analysis_test, fail = _fail, target_actions = _target_actions,