From e3685a8d9da381afdfa440d6c979de7e6ac1c319 Mon Sep 17 00:00:00 2001 From: Akos Hajdu Date: Thu, 15 Jul 2021 15:23:17 -0700 Subject: [PATCH] [erl-frontend] Add tests for logic operators Summary: Add tests for `and`, `or`, `not`. Reviewed By: rgrig Differential Revision: D29696455 fbshipit-source-id: 1b25b2b79 --- .../codetoanalyze/erlang/features/issues.exp | 5 ++ .../erlang/features/src/logic.erl | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 infer/tests/codetoanalyze/erlang/features/src/logic.erl diff --git a/infer/tests/codetoanalyze/erlang/features/issues.exp b/infer/tests/codetoanalyze/erlang/features/issues.exp index 8b46535f3..f7d2bb189 100644 --- a/infer/tests/codetoanalyze/erlang/features/issues.exp +++ b/infer/tests/codetoanalyze/erlang/features/issues.exp @@ -27,3 +27,8 @@ codetoanalyze/erlang/features/src/comparison.erl, test_less_Bad/0, 3, NO_TRUE_BR codetoanalyze/erlang/features/src/comparison.erl, test_less_Bad2/0, 3, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] codetoanalyze/erlang/features/src/comparison.erl, test_not_equal_Bad/0, 3, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] codetoanalyze/erlang/features/src/comparison.erl, test_not_equal_Bad2/0, 3, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/logic.erl, test_and00_Bad/0, 1, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/logic.erl, test_and01_Bad/0, 1, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/logic.erl, test_and10_Bad/0, 1, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/logic.erl, test_or00_Bad/0, 1, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/logic.erl, test_unot_Bad/0, 1, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] diff --git a/infer/tests/codetoanalyze/erlang/features/src/logic.erl b/infer/tests/codetoanalyze/erlang/features/src/logic.erl new file mode 100644 index 000000000..41cec455c --- /dev/null +++ b/infer/tests/codetoanalyze/erlang/features/src/logic.erl @@ -0,0 +1,73 @@ +% 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(logic). + +% Workaround until we support true/false atoms +-define(T, (1 == 1)). +-define(F, (1 == 0)). + +-export([ + test_and00_Bad/0, + test_and01_Bad/0, + test_and10_Bad/0, + test_and11_Ok/0, + test_or00_Bad/0, + test_or01_Ok/0, + test_or10_Ok/0, + test_or11_Ok/0, + test_unot_Ok/0, + test_unot_Bad/0 +]). + +test_and00_Bad() -> + if + ?F and ?F -> ok + end. + +test_and01_Bad() -> + if + ?F and ?T -> ok + end. + +test_and10_Bad() -> + if + ?T and ?F -> ok + end. + +test_and11_Ok() -> + if + ?T and ?T -> ok + end. + +test_or00_Bad() -> + if + ?F or ?F -> ok + end. + +test_or01_Ok() -> + if + ?F or ?T -> ok + end. + +test_or10_Ok() -> + if + ?T or ?F -> ok + end. + +test_or11_Ok() -> + if + ?T or ?T -> ok + end. + +test_unot_Ok() -> + if + not ?F -> ok + end. + +test_unot_Bad() -> + if + not ?T -> ok + end.