Fix doc error for analystest.begin (#369)

Co-authored-by: Alexandre Rostovtsev <arostovtsev@google.com>
This commit is contained in:
Vinh Tran 2022-08-25 17:47:50 -04:00 committed by GitHub
parent c1dfc324fb
commit 69b4636956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -94,9 +94,9 @@ A rule definition that should be stored in a global whose name ends in
analysistest.begin(<a href="#analysistest.begin-ctx">ctx</a>) analysistest.begin(<a href="#analysistest.begin-ctx">ctx</a>)
</pre> </pre>
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 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 assertion failures so that they can be reported and logged at the end of the
test. test.
@ -112,7 +112,7 @@ test.
**RETURNS** **RETURNS**
A test environment struct that must be passed to assertions and finally to 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. struct as it may change.

View File

@ -364,6 +364,25 @@ def _begin(ctx):
""" """
return struct(ctx = ctx, failures = []) 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): def _end_analysis_test(env):
"""Ends an analysis test and logs the results. """Ends an analysis test and logs the results.
@ -647,7 +666,7 @@ unittest = struct(
analysistest = struct( analysistest = struct(
make = _make_analysis_test, make = _make_analysis_test,
begin = _begin, begin = _begin_analysis_test,
end = _end_analysis_test, end = _end_analysis_test,
fail = _fail, fail = _fail,
target_actions = _target_actions, target_actions = _target_actions,