1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2015-2016. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(beam_bool_SUITE).
-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
before_and_inside_if/1,
scotland/1]).
suite() ->
[{ct_hooks,[ts_install_cth]}].
all() ->
test_lib:recompile(?MODULE),
[{group,p}].
groups() ->
[{p,[parallel],
[before_and_inside_if,
scotland
]}].
init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
before_and_inside_if(_Config) ->
no = before_and_inside_if([a], [b], delete),
no = before_and_inside_if([a], [b], x),
no = before_and_inside_if([a], [], delete),
no = before_and_inside_if([a], [], x),
no = before_and_inside_if([], [], delete),
yes = before_and_inside_if([], [], x),
yes = before_and_inside_if([], [b], delete),
yes = before_and_inside_if([], [b], x),
{ch1,ch2} = before_and_inside_if_2([a], [b], blah),
{ch1,ch2} = before_and_inside_if_2([a], [b], xx),
{ch1,ch2} = before_and_inside_if_2([a], [], blah),
{ch1,ch2} = before_and_inside_if_2([a], [], xx),
{no,no} = before_and_inside_if_2([], [b], blah),
{no,no} = before_and_inside_if_2([], [b], xx),
{ch1,no} = before_and_inside_if_2([], [], blah),
{no,ch2} = before_and_inside_if_2([], [], xx),
ok.
%% Thanks to Simon Cornish and Kostis Sagonas.
%% Used to crash beam_bool.
before_and_inside_if(XDo1, XDo2, Do3) ->
Do1 = (XDo1 =/= []),
Do2 = (XDo2 =/= []),
if
%% This expression occurs in a try/catch (protected)
%% block, which cannot refer to variables outside of
%% the block that are boolean expressions.
Do1 =:= true;
Do1 =:= false, Do2 =:= false, Do3 =:= delete ->
no;
true ->
yes
end.
%% Thanks to Simon Cornish.
%% Used to generate code that would not set {y,0} on
%% all paths before its use (and therefore fail
%% validation by the beam_validator).
before_and_inside_if_2(XDo1, XDo2, Do3) ->
Do1 = (XDo1 =/= []),
Do2 = (XDo2 =/= []),
CH1 = if Do1 == true;
Do1 == false,Do2==false,Do3 == blah ->
ch1;
true ->
no
end,
CH2 = if Do1 == true;
Do1 == false,Do2==false,Do3 == xx ->
ch2;
true ->
no
end,
{CH1,CH2}.
%% beam_bool would remove the initialization of {y,0}.
%% (Thanks to Thomas Arts and QuickCheck.)
scotland(_Config) ->
million = do_scotland(placed),
{'EXIT',{{badmatch,placed},_}} = (catch do_scotland(false)),
{'EXIT',{{badmatch,placed},_}} = (catch do_scotland(true)),
{'EXIT',{{badmatch,placed},_}} = (catch do_scotland(echo)),
ok.
do_scotland(Echo) ->
found(case Echo of
Echo when true; Echo, Echo, Echo ->
Echo;
echo ->
[]
end,
Echo = placed).
found(_, _) -> million.
|