From 4f72bfff6cbcb69ae0b54f1958fab575d4d366f9 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 30 Nov 2011 16:56:05 +0100 Subject: Add ct:fail/2 function --- lib/common_test/src/ct.erl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/common_test/src/ct.erl') diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 69e15fa246..9e787ef508 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -63,7 +63,7 @@ log/1, log/2, log/3, print/1, print/2, print/3, pal/1, pal/2, pal/3, - fail/1, comment/1, + fail/1, fail/2, comment/1, testcases/2, userdata/2, userdata/3, timetrap/1, sleep/1]). @@ -528,6 +528,25 @@ pal(Category,Format,Args) -> fail(Reason) -> exit({test_case_failed,Reason}). + +%%%----------------------------------------------------------------- +%%% @spec fail(Format, Args) -> void() +%%% Format = string() +%%% Args = list() +%%% +%%% @doc Terminate a test case with an error message specified +%%% by a format string and a list of values (used as arguments to +%%% io_lib:format/2). +fail(Format, Args) -> + try io_lib:format(Format, Args) of + Str -> + exit({test_case_failed,lists:flatten(Str)}) + catch + _:BadArgs -> + exit({BadArgs,{?MODULE,fail,[Format,Args]}}) + end. + + %%%----------------------------------------------------------------- %%% @spec comment(Comment) -> void() %%% Comment = term() -- cgit v1.2.3