From a0286ce52c775812e499c4f036033daa5ffe4676 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Mon, 30 Nov 2015 23:36:42 +0100 Subject: Include some more old HiPE tests to the test suite --- lib/hipe/test/basic_SUITE_data/basic_guards.erl | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib/hipe/test/basic_SUITE_data/basic_guards.erl') 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. -- cgit v1.2.3