From 69b4636956c55b620c0776f4262a38a15554169c Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Thu, 25 Aug 2022 17:47:50 -0400 Subject: [PATCH] Fix doc error for analystest.begin (#369) Co-authored-by: Alexandre Rostovtsev --- docs/unittest_doc.md | 6 +++--- lib/unittest.bzl | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) 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,