1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 1997-2011. All Rights Reserved. 5: %% 6: %% The contents of this file are subject to the Erlang Public License, 7: %% Version 1.1, (the "License"); you may not use this file except in 8: %% compliance with the License. You should have received a copy of the 9: %% Erlang Public License along with this software. If not, it can be 10: %% retrieved online at http://www.erlang.org/. 11: %% 12: %% Software distributed under the License is distributed on an "AS IS" 13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14: %% the License for the specific language governing rights and limitations 15: %% under the License. 16: %% 17: %% %CopyrightEnd% 18: %% 19: 20: -module(nested_SUITE). 21: 22: -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 23: init_per_group/2,end_per_group/2, 24: case_in_case/1, case_in_after/1, catch_in_catch/1, bif_in_bif/1]). 25: 26: -include_lib("test_server/include/test_server.hrl"). 27: 28: suite() -> [{ct_hooks,[ts_install_cth]}]. 29: 30: all() -> 31: [case_in_case, case_in_after, catch_in_catch, 32: bif_in_bif]. 33: 34: groups() -> 35: []. 36: 37: init_per_suite(Config) -> 38: Config. 39: 40: end_per_suite(_Config) -> 41: ok. 42: 43: init_per_group(_GroupName, Config) -> 44: Config. 45: 46: end_per_group(_GroupName, Config) -> 47: Config. 48: 49: 50: case_in_case(suite) -> []; 51: case_in_case(Config) when is_list(Config) -> 52: ?line done = search_any([a], [{a, 1}]), 53: ?line done = search_any([x], [{a, 1}]), 54: ok. 55: 56: search_any([Key|Rest], List) -> 57: ?line case case lists:keysearch(Key, 1, List) of 58: {value, _} -> 59: true; 60: _ -> 61: false 62: end of 63: true -> 64: ok; 65: false -> 66: error; 67: Other -> 68: test_server:fail({other_result, Other}) 69: end, 70: ?line search_any(Rest, List); 71: search_any([], _) -> 72: done. 73: 74: case_in_after(suite) -> []; 75: case_in_after(Config) when is_list(Config) -> 76: receive 77: after case {x, y, z} of 78: {x, y, z} -> 0 79: end -> 80: ok 81: end, 82: ok. 83: 84: catch_in_catch(doc) -> "Test a catch within a catch in the same function."; 85: catch_in_catch(suite) -> []; 86: catch_in_catch(Config) when is_list(Config) -> 87: ?line {outer, inner_exit} = catcher(), 88: ok. 89: 90: catcher() -> 91: case (catch 92: case (catch ?MODULE:non_existing()) of % bogus function 93: {'EXIT', _} -> 94: inner_exit; 95: Res1 -> 96: {inner, Res1} 97: end) of 98: {'EXIT', _} -> 99: outer_exit; 100: Res2 -> 101: {outer, Res2} 102: end. 103: 104: bif_in_bif(doc) -> "Test a BIF call within a BIF call."; 105: bif_in_bif(suite) -> []; 106: bif_in_bif(Config) when is_list(Config) -> 107: Self = self(), 108: put(pid, Self), 109: Self = register_me(), 110: ok. 111: 112: register_me() -> 113: register(?MODULE, Pid = get(pid)), 114: Pid.