<commit_before>%%%----------------------------------------------------------------------
%%% File        : error_tests.erl
%%% Authors     : <NAME> <<EMAIL>>
%%%               <NAME> <<EMAIL>>
%%% Description : Error interface unit tests
%%% Created     : 28 Sep 2010
%%%----------------------------------------------------------------------

-module(error_tests).

-include_lib("eunit/include/eunit.hrl").

%% Spec for auto-generated test/0 function (eunit).
-spec test() -> 'ok' | {'error', term()}.

-spec deadlock_test() -> term().

deadlock_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1", "P1.2"],
    Error = error:new(ErrorType, ErrorDescr),
    Blocked =
        sets:add_element("P1",
                         sets:add_element("P1.1",
                                          sets:add_element("P1.2",
                                                           sets:new()))),
    Deadlock = error:deadlock(Blocked),
    ?assertEqual(Error, Deadlock).

-spec error_type_to_string_test() -> term().

error_type_to_string_test() ->
    ErrorType = assertion_violation,
    ErrorDescr = {{assertion_violation, [{module, mymodule}, {line, 42},
                                         {expression, "true =:= false"},
                                         {expected, true}, {value, false}]},
                  []},
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~s~n", ["Assertion violation"]),
                 error:error_type_to_string(Error)).

-spec error_reason_to_string1_test() -> term().

error_reason_to_string1_test() ->
    ErrorType = assertion_violation,
    ErrorDescr = {{assertion_violation, [{module, mymodule}, {line, 42},
                                         {expression, "true =:= false"},
                                         {expected, true}, {value, false}]},
                  []},
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("On line ~p of module ~p, "
                               ++ "the expression ~s evaluates to ~p "
                               ++ "instead of ~p~n",
                               [42, mymodule, "true =:= false", false, true]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string2_test() -> term().

error_reason_to_string2_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1"],
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("Process ~s blocks~n", ["P1"]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string3_test() -> term().

error_reason_to_string3_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1"],
    Error = error:new(ErrorType, ErrorDescr),
    Ps = io_lib:format("~s and ~s", ["P1", "P1.1"]),
    ?assertEqual(io_lib:format("Processes ~s block~n", [Ps]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string4_test() -> term().

error_reason_to_string4_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1", "P1.2"],
    Error = error:new(ErrorType, ErrorDescr),
    Ps = io_lib:format("~s, ~s and ~s", ["P1", "P1.1", "P1.2"]),
    ?assertEqual(io_lib:format("Processes ~s block~n", [Ps]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string5_test() -> term().

error_reason_to_string5_test() ->
    ErrorType = exception,
    ErrorDescr = foobar,
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~p~n", [ErrorDescr]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string6_test() -> term().

error_reason_to_string6_test() ->
    ErrorType = exception,
    ErrorDescr = {badarg, []},
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~p~n", [badarg]),
                 error:error_reason_to_string(Error, long)).

-spec error_stack_to_string1_test() -> term().

error_stack_to_string1_test() ->
    ErrorType = assertion_violation,
    ErrorDescr = {{assertion_violation, [{module, mymodule}, {line, 42},
                                         {expression, "true =:= false"},
                                         {expected, true}, {value, false}]},
                  []},
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~p", [[]]),
                 error:error_stack_to_string(Error)).

-spec error_stack_to_string2_test() -> term().

error_stack_to_string2_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1"],
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual("", error:error_stack_to_string(Error)).<commit_msg>Use error:stub/0 in error unit tests<commit_after>%%%----------------------------------------------------------------------
%%% File        : error_tests.erl
%%% Authors     : <NAME> <<EMAIL>>
%%%               <NAME> <<EMAIL>>
%%% Description : Error interface unit tests
%%% Created     : 28 Sep 2010
%%%----------------------------------------------------------------------

-module(error_tests).

-include_lib("eunit/include/eunit.hrl").

%% Spec for auto-generated test/0 function (eunit).
-spec test() -> 'ok' | {'error', term()}.

-spec deadlock_test() -> term().

deadlock_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1", "P1.2"],
    Error = error:new(ErrorType, ErrorDescr),
    Blocked =
        sets:add_element("P1",
                         sets:add_element("P1.1",
                                          sets:add_element("P1.2",
                                                           sets:new()))),
    Deadlock = error:deadlock(Blocked),
    ?assertEqual(Error, Deadlock).

-spec error_type_to_string_test() -> term().

error_type_to_string_test() ->
    Error = error:stub(),
    ?assertEqual(io_lib:format("~s~n", ["Assertion violation"]),
                 error:error_type_to_string(Error)).

-spec error_reason_to_string1_test() -> term().

error_reason_to_string1_test() ->
    Error = error:stub(),
    ?assertEqual(io_lib:format("On line ~p of module ~p, "
                               ++ "the expression ~s evaluates to ~p "
                               ++ "instead of ~p~n",
                               [42, mymodule, "true =:= false", false, true]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string2_test() -> term().

error_reason_to_string2_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1"],
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("Process ~s blocks~n", ["P1"]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string3_test() -> term().

error_reason_to_string3_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1"],
    Error = error:new(ErrorType, ErrorDescr),
    Ps = io_lib:format("~s and ~s", ["P1", "P1.1"]),
    ?assertEqual(io_lib:format("Processes ~s block~n", [Ps]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string4_test() -> term().

error_reason_to_string4_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1", "P1.1", "P1.2"],
    Error = error:new(ErrorType, ErrorDescr),
    Ps = io_lib:format("~s, ~s and ~s", ["P1", "P1.1", "P1.2"]),
    ?assertEqual(io_lib:format("Processes ~s block~n", [Ps]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string5_test() -> term().

error_reason_to_string5_test() ->
    ErrorType = exception,
    ErrorDescr = foobar,
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~p~n", [ErrorDescr]),
                 error:error_reason_to_string(Error, long)).

-spec error_reason_to_string6_test() -> term().

error_reason_to_string6_test() ->
    ErrorType = exception,
    ErrorDescr = {badarg, []},
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual(io_lib:format("~p~n", [badarg]),
                 error:error_reason_to_string(Error, long)).

-spec error_stack_to_string1_test() -> term().

error_stack_to_string1_test() ->
    Error = error:stub(),
    ?assertEqual(io_lib:format("~p", [[]]),
                 error:error_stack_to_string(Error)).

-spec error_stack_to_string2_test() -> term().

error_stack_to_string2_test() ->
    ErrorType = deadlock,
    ErrorDescr = ["P1"],
    Error = error:new(ErrorType, ErrorDescr),
    ?assertEqual("", error:error_stack_to_string(Error)).
{'fraction_non_alphanumeric': 0.18794579172610557, 'fraction_numerical': 0.01367094626723728, 'mean_word_length': 2.355803749501396, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3672201', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2620, 'n_words': 472}