From 036699b790635abe1209ba3d4808f2aea1ea6c5e Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 7 Dec 2011 17:38:57 +0100 Subject: Create ct interface to the test_server:capture_* functions --- lib/common_test/src/ct.erl | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index d72b8bc0e1..e59a177473 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -63,6 +63,7 @@ log/1, log/2, log/3, print/1, print/2, print/3, pal/1, pal/2, pal/3, + capture_start/0, capture_stop/0, capture_get/0, capture_get/1, fail/1, fail/2, comment/1, comment/2, testcases/2, userdata/2, userdata/3, timetrap/1, sleep/1]). @@ -517,6 +518,65 @@ pal(X1,X2) -> pal(Category,Format,Args) -> ct_logs:tc_pal(Category,Format,Args). +%%%----------------------------------------------------------------- +%%% @spec capture_start() -> ok +%%% +%%% @doc Start capturing all text strings printed to stdout during +%%% execution of the test case. +%%% +%%% @see capture_stop/0 +%%% @see capture_get/1 +capture_start() -> + test_server:capture_start(). + +%%%----------------------------------------------------------------- +%%% @spec capture_stop() -> ok +%%% +%%% @doc Stop capturing text strings (a session started with +%%% capture_start/0). +%%% +%%% @see capture_start/0 +%%% @see capture_get/1 +capture_stop() -> + test_server:capture_stop(). + +%%%----------------------------------------------------------------- +%%% @spec capture_get() -> ListOfStrings +%%% ListOfStrings = [string()] +%%% +%%% @equiv capture_get([default]) +capture_get() -> + %% remove default log printouts (e.g. ct:log/2 printouts) + capture_get([default]). + +%%%----------------------------------------------------------------- +%%% @spec capture_get(ExclCategories) -> ListOfStrings +%%% ExclCategories = [atom()] +%%% ListOfStrings = [string()] +%%% +%%% @doc Return and purge the list of text strings buffered +%%% during the latest session of capturing printouts to stdout. +%%% With ExclCategories it's possible to specify +%%% log categories that should be ignored in ListOfStrings. +%%% If ExclCategories = [], no filtering takes place. +%%% +%%% @see capture_start/0 +%%% @see capture_stop/0 +%%% @see log/3 +capture_get([ExclCat | ExclCats]) -> + Strs = test_server:capture_get(), + CatsStr = [atom_to_list(ExclCat) | + [[$| | atom_to_list(EC)] || EC <- ExclCats]], + {ok,MP} = re:compile("
.*"), + lists:flatmap(fun(Str) -> + case re:run(Str, MP) of + {match,_} -> []; + nomatch -> [Str] + end + end, Strs); + +capture_get([]) -> + test_server:capture_get(). %%%----------------------------------------------------------------- %%% @spec fail(Reason) -> void() -- cgit v1.2.3 From 0b2e64a9beb959753d576cc01e65e4bea8ee4571 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Thu, 8 Dec 2011 15:57:57 +0100 Subject: Fix error in documentation --- lib/common_test/src/ct.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index e59a177473..860bfb45ee 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -563,10 +563,10 @@ capture_get() -> %%% @see capture_start/0 %%% @see capture_stop/0 %%% @see log/3 -capture_get([ExclCat | ExclCats]) -> +capture_get([ExclCat | ExclCategories]) -> Strs = test_server:capture_get(), CatsStr = [atom_to_list(ExclCat) | - [[$| | atom_to_list(EC)] || EC <- ExclCats]], + [[$| | atom_to_list(EC)] || EC <- ExclCategories]], {ok,MP} = re:compile("
.*"), lists:flatmap(fun(Str) -> case re:run(Str, MP) of -- cgit v1.2.3