[erl-frontend] Add tests for binary expression translation

Summary: Add some tests for binary expressions. The idea is that tests come in pairs: in both cases we do the same calculations, one is asserting the good result and one is not, where only the latter should trigger a warning.

Reviewed By: rgrig

Differential Revision: D29556364

fbshipit-source-id: 5b601d141
master
Akos Hajdu 3 years ago committed by Facebook GitHub Bot
parent ab550541dc
commit 7f64015957

@ -153,6 +153,7 @@ ifneq ($(REBAR3),no)
DIRECT_TESTS += \
erlang_nonmatch \
erlang_topl \
erlang_features \
BUILD_SYSTEMS_TESTS += rebar3
endif

@ -0,0 +1,17 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
TESTS_DIR = ../../..
# see explanations in cpp/biabduction/Makefile for the custom isystem
INFER_OPTIONS = --pulse-only --debug-exceptions --project-root $(TESTS_DIR) \
--pulse-report-latent-issues
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard src/*.erl)
include $(TESTS_DIR)/erlang.make
infer-out/report.json: $(MAKEFILE_LIST)

@ -0,0 +1,7 @@
codetoanalyze/erlang/features/src/arithmetic.erl, test_add_Bad/0, -9, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, test_idiv1_Bad/0, -54, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, test_mul_Bad/0, -39, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, test_multiple_Bad/0, -98, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, test_rem_Bad/0, -85, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, test_sub_Bad/0, -24, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here]
codetoanalyze/erlang/features/src/arithmetic.erl, warn/1, 0, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [*** LATENT ***,no pattern match here]

@ -0,0 +1,11 @@
% Copyright (c) Facebook, Inc. and its affiliates.
%
% This source code is licensed under the MIT license found in the
% LICENSE file in the root directory of this source tree.
{erl_opts, []}.
{deps, []}.
{shell, [
{apps, [translation]}
]}.

@ -0,0 +1,128 @@
% Copyright (c) Facebook, Inc. and its affiliates.
%
% This source code is licensed under the MIT license found in the
% LICENSE file in the root directory of this source tree.
-module(arithmetic).
-export([
test_add_Ok/0,
test_add_Bad/0,
test_sub_Ok/0,
test_sub_Bad/0,
test_mul_Ok/0,
test_mul_Bad/0,
test_idiv1_Ok/0,
test_idiv1_Bad/0,
test_idiv2_Ok/0,
fn_test_idiv2_Bad/0,
test_rem_Ok/0,
test_rem_Bad/0,
test_multiple_Ok/0,
test_multiple_Bad/0
]).
% Call this method with warn(1) to trigger a warning to expect
warn(0) -> ok.
test_add_Ok() ->
X = 2,
Y = 3,
case X + Y of
5 -> ok;
_ -> warn(1)
end.
test_add_Bad() ->
X = 2,
Y = 3,
case X + Y of
5 -> warn(1);
_ -> ok
end.
test_sub_Ok() ->
X = 5,
Y = 3,
case X - Y of
2 -> ok;
_ -> warn(1)
end.
test_sub_Bad() ->
X = 5,
Y = 3,
case X - Y of
2 -> warn(1);
_ -> ok
end.
test_mul_Ok() ->
X = 5,
Y = 3,
case X * Y of
15 -> ok;
_ -> warn(1)
end.
test_mul_Bad() ->
X = 5,
Y = 3,
case X * Y of
15 -> warn(1);
_ -> ok
end.
test_idiv1_Ok() ->
X = 21,
Y = 3,
case X div Y of
7 -> ok;
_ -> warn(1)
end.
test_idiv1_Bad() ->
X = 21,
Y = 3,
case X div Y of
7 -> warn(1);
_ -> ok
end.
test_idiv2_Ok() ->
X = 22,
Y = 3,
case X div Y of
7 -> ok;
_ -> warn(1)
end.
% FN (T94972453)
fn_test_idiv2_Bad() ->
X = 22,
Y = 3,
case X div Y of
7 -> warn(1);
_ -> ok
end.
test_rem_Ok() ->
X = 5,
Y = 3,
case X rem Y of
2 -> ok;
_ -> warn(1)
end.
test_rem_Bad() ->
X = 5,
Y = 3,
case X rem Y of
2 -> warn(1);
_ -> ok
end.
test_multiple_Ok() ->
case (8 + 4) div 2 * 5 of
30 -> ok;
_ -> warn(1)
end.
test_multiple_Bad() ->
case (8 + 4) div 2 * 5 of
30 -> warn(1);
_ -> ok
end.

@ -0,0 +1,14 @@
% Copyright (c) Facebook, Inc. and its affiliates.
%
% This source code is licensed under the MIT license found in the
% LICENSE file in the root directory of this source tree.
{application, features, [
{description, "An Erlang app for testing various language features"},
{vsn, "0.1.0"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{modules, []}
]}.
Loading…
Cancel
Save