aboutsummaryrefslogtreecommitdiffstats
path: root/lib/hipe/test/basic_SUITE_data/basic_guards.erl
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2015-11-30 23:36:42 +0100
committerKostis Sagonas <[email protected]>2015-12-16 22:08:34 +0100
commita0286ce52c775812e499c4f036033daa5ffe4676 (patch)
treea869bb47e0131c4100d581a555ad5d72d172bbf5 /lib/hipe/test/basic_SUITE_data/basic_guards.erl
parent186868ede408e714afe191c0a40123e4f8b2e847 (diff)
downloadotp-a0286ce52c775812e499c4f036033daa5ffe4676.tar.gz
otp-a0286ce52c775812e499c4f036033daa5ffe4676.tar.bz2
otp-a0286ce52c775812e499c4f036033daa5ffe4676.zip
Include some more old HiPE tests to the test suite
Diffstat (limited to 'lib/hipe/test/basic_SUITE_data/basic_guards.erl')
-rw-r--r--lib/hipe/test/basic_SUITE_data/basic_guards.erl47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/hipe/test/basic_SUITE_data/basic_guards.erl b/lib/hipe/test/basic_SUITE_data/basic_guards.erl
index b821a05ad5..81eeed7c3b 100644
--- a/lib/hipe/test/basic_SUITE_data/basic_guards.erl
+++ b/lib/hipe/test/basic_SUITE_data/basic_guards.erl
@@ -7,6 +7,8 @@
-module(basic_guards).
-export([test/0]).
+%% Prevent the inlining of the following functions
+-export([bad_arith/0, bad_tuple/0, is_strange_guard/0]).
test() ->
ok = guard0(4.2),
@@ -15,6 +17,7 @@ test() ->
ok = test_guard3(),
ok = test_guard4(),
ok = test_is_boolean(),
+ ok = test_bad_guards(),
ok.
%%--------------------------------------------------------------------
@@ -115,3 +118,47 @@ tg(_) ->
not_bool.
yes() -> yes.
+
+%%--------------------------------------------------------------------
+%% original test by Bjorn G
+
+test_bad_guards() ->
+ ok = bad_arith(),
+ ok = bad_tuple(),
+ ok = is_strange_guard(),
+ ok.
+
+bad_arith() ->
+ 13 = bad_arith1(1, 12),
+ 42 = bad_arith1(1, infinity),
+ 42 = bad_arith1(infinity, 1),
+ 42 = bad_arith2(infinity, 1),
+ 42 = bad_arith3(inf),
+ 42 = bad_arith4(infinity, 1),
+ ok.
+
+bad_arith1(T1, T2) when (T1 + T2) < 17 -> T1 + T2;
+bad_arith1(_, _) -> 42.
+
+bad_arith2(T1, T2) when (T1 * T2) < 17 -> T1 * T2;
+bad_arith2(_, _) -> 42.
+
+bad_arith3(T) when (bnot T) < 17 -> T;
+bad_arith3(_) -> 42.
+
+bad_arith4(T1, T2) when (T1 bsr T2) < 10 -> T1 bsr T2;
+bad_arith4(_, _) -> 42.
+
+bad_tuple() ->
+ error = bad_tuple1(a),
+ error = bad_tuple1({a, b}),
+ x = bad_tuple1({x, b}),
+ y = bad_tuple1({a, b, y}),
+ ok.
+
+bad_tuple1(T) when element(1, T) =:= x -> x;
+bad_tuple1(T) when element(3, T) =:= y -> y;
+bad_tuple1(_) -> error.
+
+is_strange_guard() when is_tuple({1, bar, length([1, 2, 3, 4]), self()}) -> ok;
+is_strange_guard() -> error.