31
32
t_is_boolean/1,is_function_2/1,
32
33
tricky/1,rel_ops/1,literal_type_tests/1,
33
34
basic_andalso_orelse/1,traverse_dcd/1,
34
check_qlc_hrl/1,andalso_semi/1,tuple_size/1]).
37
test_lib:recompile(?MODULE),
38
[misc,const_cond,basic_not,complex_not,nested_nots,
39
semicolon,complex_semicolon,
40
comma,or_guard,more_or_guards,
41
complex_or_guards,and_guard,
42
xor_guard,more_xor_guards,
43
build_in_guard,old_guard_tests,gbif,
44
t_is_boolean,is_function_2,tricky,rel_ops,literal_type_tests,
45
basic_andalso_orelse,traverse_dcd,check_qlc_hrl,andalso_semi,
35
check_qlc_hrl/1,andalso_semi/1,t_tuple_size/1,binary_part/1]).
37
suite() -> [{ct_hooks,[ts_install_cth]}].
40
test_lib:recompile(guard_SUITE),
41
[misc, const_cond, basic_not, complex_not, nested_nots,
42
semicolon, complex_semicolon, comma, or_guard,
43
more_or_guards, complex_or_guards, and_guard, xor_guard,
44
more_xor_guards, build_in_guard, old_guard_tests, gbif,
45
t_is_boolean, is_function_2, tricky, rel_ops,
46
literal_type_tests, basic_andalso_orelse, traverse_dcd,
47
check_qlc_hrl, andalso_semi, t_tuple_size, binary_part].
52
init_per_suite(Config) ->
55
end_per_suite(_Config) ->
58
init_per_group(_GroupName, Config) ->
61
end_per_group(_GroupName, Config) ->
48
65
misc(Config) when is_list(Config) ->
49
66
?line 42 = case id(42) of
1362
1379
when tuple_size(T) =:= 16#FFFFFFFFFFFFFFFF -> ok;
1363
1380
ludicrous_tuple_size(_) -> error.
1383
%% The binary_part/2,3 guard BIFs
1385
-define(MASK_ERROR(EXPR),mask_error((catch (EXPR)))).
1386
mask_error({'EXIT',{Err,_}}) ->
1392
["Tests the binary_part/2,3 guard (GC) bif's"];
1393
binary_part(Config) when is_list(Config) ->
1394
%% This is more or less a copy of what the guard_SUITE in emulator
1395
%% does to cover the guard bif's
1396
?line 1 = bptest(<<1,2,3>>),
1397
?line 2 = bptest(<<2,1,3>>),
1398
?line error = bptest(<<1>>),
1399
?line error = bptest(<<>>),
1400
?line error = bptest(apa),
1401
?line 3 = bptest(<<2,3,3>>),
1402
% With one variable (pos)
1403
?line 1 = bptest(<<1,2,3>>,1),
1404
?line 2 = bptest(<<2,1,3>>,1),
1405
?line error = bptest(<<1>>,1),
1406
?line error = bptest(<<>>,1),
1407
?line error = bptest(apa,1),
1408
?line 3 = bptest(<<2,3,3>>,1),
1409
% With one variable (length)
1410
?line 1 = bptesty(<<1,2,3>>,1),
1411
?line 2 = bptesty(<<2,1,3>>,1),
1412
?line error = bptesty(<<1>>,1),
1413
?line error = bptesty(<<>>,1),
1414
?line error = bptesty(apa,1),
1415
?line 3 = bptesty(<<2,3,3>>,2),
1416
% With one variable (whole tuple)
1417
?line 1 = bptestx(<<1,2,3>>,{1,1}),
1418
?line 2 = bptestx(<<2,1,3>>,{1,1}),
1419
?line error = bptestx(<<1>>,{1,1}),
1420
?line error = bptestx(<<>>,{1,1}),
1421
?line error = bptestx(apa,{1,1}),
1422
?line 3 = bptestx(<<2,3,3>>,{1,2}),
1423
% With two variables
1424
?line 1 = bptest(<<1,2,3>>,1,1),
1425
?line 2 = bptest(<<2,1,3>>,1,1),
1426
?line error = bptest(<<1>>,1,1),
1427
?line error = bptest(<<>>,1,1),
1428
?line error = bptest(apa,1,1),
1429
?line 3 = bptest(<<2,3,3>>,1,2),
1430
% Direct (autoimported) call, these will be evaluated by the compiler...
1431
?line <<2>> = binary_part(<<1,2,3>>,1,1),
1432
?line <<1>> = binary_part(<<2,1,3>>,1,1),
1433
% Compiler warnings due to constant evaluation expected (3)
1434
?line badarg = ?MASK_ERROR(binary_part(<<1>>,1,1)),
1435
?line badarg = ?MASK_ERROR(binary_part(<<>>,1,1)),
1436
?line badarg = ?MASK_ERROR(binary_part(apa,1,1)),
1437
?line <<3,3>> = binary_part(<<2,3,3>>,1,2),
1438
% Direct call through apply
1439
?line <<2>> = apply(erlang,binary_part,[<<1,2,3>>,1,1]),
1440
?line <<1>> = apply(erlang,binary_part,[<<2,1,3>>,1,1]),
1441
% Compiler warnings due to constant evaluation expected (3)
1442
?line badarg = ?MASK_ERROR(apply(erlang,binary_part,[<<1>>,1,1])),
1443
?line badarg = ?MASK_ERROR(apply(erlang,binary_part,[<<>>,1,1])),
1444
?line badarg = ?MASK_ERROR(apply(erlang,binary_part,[apa,1,1])),
1445
?line <<3,3>> = apply(erlang,binary_part,[<<2,3,3>>,1,2]),
1446
% Constant propagation
1447
?line Bin = <<1,2,3>>,
1449
binary_part(Bin,1,1) =:= <<2>> ->
1451
%% Compiler warning, clause cannot match (expected)
1456
binary_part(Bin,{1,1}) =:= <<2>> ->
1458
%% Compiler warning, clause cannot match (expected)
1465
bptest(B) when length(B) =:= 1337 ->
1467
bptest(B) when binary_part(B,{1,1}) =:= <<2>> ->
1469
bptest(B) when erlang:binary_part(B,1,1) =:= <<1>> ->
1471
bptest(B) when erlang:binary_part(B,{1,2}) =:= <<3,3>> ->
1476
bptest(B,A) when length(B) =:= A ->
1478
bptest(B,A) when binary_part(B,{A,1}) =:= <<2>> ->
1480
bptest(B,A) when erlang:binary_part(B,A,1) =:= <<1>> ->
1482
bptest(B,A) when erlang:binary_part(B,{A,2}) =:= <<3,3>> ->
1487
bptestx(B,A) when length(B) =:= A ->
1489
bptestx(B,A) when binary_part(B,A) =:= <<2>> ->
1491
bptestx(B,A) when erlang:binary_part(B,A) =:= <<1>> ->
1493
bptestx(B,A) when erlang:binary_part(B,A) =:= <<3,3>> ->
1498
bptesty(B,A) when length(B) =:= A ->
1500
bptesty(B,A) when binary_part(B,{1,A}) =:= <<2>> ->
1502
bptesty(B,A) when erlang:binary_part(B,1,A) =:= <<1>> ->
1504
bptesty(B,A) when erlang:binary_part(B,{1,A}) =:= <<3,3>> ->
1509
bptest(B,A,_C) when length(B) =:= A ->
1511
bptest(B,A,C) when binary_part(B,{A,C}) =:= <<2>> ->
1513
bptest(B,A,C) when erlang:binary_part(B,A,C) =:= <<1>> ->
1515
bptest(B,A,C) when erlang:binary_part(B,{A,C}) =:= <<3,3>> ->
1366
1523
%% Call this function to turn off constant propagation.