Skip to content

Commit 057db1f

Browse files
committed
Add information about ct:comment to documentation
1 parent 2920d74 commit 057db1f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/common_test/doc/guides/ct_hooks_chapter.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,49 @@ After any post hook has been executed for all installed CTHs,
281281
skipped, respectively. You cannot affect the outcome of the tests any further at
282282
this point.
283283

284+
[](){: #comment }
285+
286+
### Comment in hooks
287+
288+
As mentioned in `ct:comment/1` same limitation regarding calling `ct:comment/1-2`
289+
exists in hook functions. Calling `ct:comment/1-2` should only be done directly from
290+
the process executing hook function, or it's descendant.
291+
292+
Be aware that if you spawn a process in one hook function and keep it alive
293+
while common_test has moved to calling another hook function, and you try to
294+
execute `ct:comment/1-2` from this process the comment may not be printed in
295+
correct place in html logs, or at all.
296+
297+
Calling this function from process that is neither a common_test process, nor it's
298+
descendant is no-op.
299+
300+
This table presents information where `ct:comment/1-2` prints to, depending on how hook was installed:
301+
302+
| Hook function | Install in: `ct_run`, `ct:run_test/1`, Test Specification | Install in: suite/0, init_per_suite/1, init_per_group/2 |
303+
| -------------------------- | --------------------------------------------------------- | ------------------------------------------------------- |
304+
| id/1 | init_per_suite row | init_per_suite row |
305+
| init/2 | nowhere | init_per_suite row |
306+
| post_all/3 | nowhere | nowhere |
307+
| post_groups/4 | nowhere | nowhere |
308+
| pre_init_per_suite/3 | init_per_suite row | init_per_suite row |
309+
| post_init_per_suite/4 | init_per_suite row | init_per_suite row |
310+
| pre_init_per_group/3,4 | init_per_group row | init_per_group row |
311+
| post_init_per_group/4,5 | init_per_group row | init_per_group row |
312+
| pre_init_per_testcase/3,4 | testcase row | testcase row |
313+
| post_init_per_testcase/4,5 | testcase row | testcase row |
314+
| post_init_per_testcase/4,5 | testcase row | testcase row |
315+
| pre_end_per_testcase/3,4 | testcase row | testcase row |
316+
| post_end_per_testcase/4,5 | testcase row | testcase row |
317+
| pre_end_per_group/3,4 | end_per_group row | end_per_group row |
318+
| post_end_per_group/4,5 | end_per_group row | end_per_group row |
319+
| pre_end_per_suite/3 | end_per_suite row | end_per_suite row |
320+
| post_end_per_suite/4 | end_per_suite row | end_per_suite row |
321+
| on_tc_skip/4 | testcase row | testcase row |
322+
| on_tc_fail/4 | nowhere | nowhere |
323+
| terminate/1 | nowhere | end_per_suite row |
324+
325+
_Table: Behavior of `ct:comment/1-2` depending on hook installation method_
326+
284327
[](){: #synchronizing }
285328

286329
## Synchronizing External User Applications with Common Test

lib/common_test/src/ct.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,20 @@ suite result page.
10551055

10561056
If called several times, only the last comment is printed. The test case return
10571057
value `{comment,Comment}` overwrites the string set by this function.
1058+
1059+
> #### Warning {: .warning }
1060+
>
1061+
> This function (and `ct:comment/2`) should only be called from the process running
1062+
> the common_test functions, typically the test case process or it's descendant.
1063+
> Be aware that if you spawn a new process in one common_test function (e.g. `init_per_suite`)
1064+
> and then execute `ct:comment/1-2` in that new process while the test execution has moved
1065+
> to another common_test function (e.g. `init_per_testcase` or test case function) the comment
1066+
> might not be printed in the correct place in html logs or at all.
1067+
>
1068+
> Calling this function from process that is neither a common_test process, nor it's
1069+
> descendant is no-op.
1070+
>
1071+
> Similar limitation exists for common_test hooks, see: [Comment in hooks](ct_hooks_chapter.md#comment)
10581072
""".
10591073
-spec comment(Comment) -> ok
10601074
when Comment :: term().

0 commit comments

Comments
 (0)