diff --git a/infer/tests/codetoanalyze/erlang/features/issues.exp b/infer/tests/codetoanalyze/erlang/features/issues.exp index 875fc551d..8b46535f3 100644 --- a/infer/tests/codetoanalyze/erlang/features/issues.exp +++ b/infer/tests/codetoanalyze/erlang/features/issues.exp @@ -13,3 +13,17 @@ codetoanalyze/erlang/features/src/arithmetic.erl, test_uminus2_Bad/0, -183, NO_M codetoanalyze/erlang/features/src/arithmetic.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] codetoanalyze/erlang/features/src/block.erl, test_block_Bad/0, -15, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no matching function clause here] codetoanalyze/erlang/features/src/block.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] +codetoanalyze/erlang/features/src/comparison.erl, fp_test_equal_Ok2/0, 3, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/comparison.erl, fp_test_exactly_not_equal_Ok2/0, 3, NO_TRUE_BRANCH_IN_IF, no_bucket, ERROR, [no true branch in if expression here] +codetoanalyze/erlang/features/src/comparison.erl, test_atleast_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_atmost_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_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_exactly_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_exactly_equal_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_exactly_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_greater_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_greater_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_less_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_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] diff --git a/infer/tests/codetoanalyze/erlang/features/src/comparison.erl b/infer/tests/codetoanalyze/erlang/features/src/comparison.erl new file mode 100644 index 000000000..660c7cd1f --- /dev/null +++ b/infer/tests/codetoanalyze/erlang/features/src/comparison.erl @@ -0,0 +1,203 @@ +% 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(comparison). + +-export([ + test_equal_Ok/0, + fp_test_equal_Ok2/0, + test_equal_Bad/0, + test_exactly_equal_Ok/0, + test_exactly_equal_Bad/0, + test_exactly_equal_Bad2/0, + test_not_equal_Ok/0, + test_not_equal_Bad/0, + test_not_equal_Bad2/0, + test_exactly_not_equal_Ok/0, + fp_test_exactly_not_equal_Ok2/0, + test_exactly_not_equal_Bad/0, + test_greater_Ok/0, + test_greater_Bad/0, + test_greater_Bad2/0, + test_less_Ok/0, + test_less_Bad/0, + test_less_Bad2/0, + test_atleast_Ok/0, + test_atleast_Ok2/0, + test_atleast_Bad/0, + test_atmost_Ok/0, + test_atmost_Ok2/0, + test_atmost_Bad/0 +]). + +test_equal_Ok() -> + X = 2, + Y = 2, + if + X == Y -> ok + end. + +% FP (T95767672) +fp_test_equal_Ok2() -> + X = 2, + Y = 2.0, + if + X == Y -> ok + end. + +test_equal_Bad() -> + X = 2, + Y = 3, + if + X == Y -> ok + end. + +test_exactly_equal_Ok() -> + X = 2, + Y = 2, + if + X =:= Y -> ok + end. + +test_exactly_equal_Bad() -> + X = 2, + Y = 3, + if + X =:= Y -> ok + end. + +test_exactly_equal_Bad2() -> + X = 2, + Y = 2.0, + if + X =:= Y -> ok + end. + +test_not_equal_Ok() -> + X = 2, + Y = 3, + if + X /= Y -> ok + end. + +test_not_equal_Bad() -> + X = 2, + Y = 2, + if + X /= Y -> ok + end. + +test_not_equal_Bad2() -> + X = 2, + Y = 2.0, + if + X /= Y -> ok + end. + +test_exactly_not_equal_Ok() -> + X = 2, + Y = 3, + if + X =/= Y -> ok + end. + +% FP (T95767672) +fp_test_exactly_not_equal_Ok2() -> + X = 2, + Y = 2.0, + if + X =/= Y -> ok + end. + +test_exactly_not_equal_Bad() -> + X = 2, + Y = 2, + if + X =/= Y -> ok + end. + +test_greater_Ok() -> + X = 3, + Y = 2, + if + X > Y -> ok + end. + +test_greater_Bad() -> + X = 2, + Y = 3, + if + X > Y -> ok + end. + +test_greater_Bad2() -> + X = 2, + Y = 2, + if + X > Y -> ok + end. + +test_less_Ok() -> + X = 2, + Y = 3, + if + X < Y -> ok + end. + +test_less_Bad() -> + X = 3, + Y = 2, + if + X < Y -> ok + end. + +test_less_Bad2() -> + X = 2, + Y = 2, + if + X < Y -> ok + end. + +test_atleast_Ok() -> + X = 2, + Y = 2, + if + X >= Y -> ok + end. + +test_atleast_Ok2() -> + X = 3, + Y = 2, + if + X >= Y -> ok + end. + +test_atleast_Bad() -> + X = 2, + Y = 3, + if + X >= Y -> ok + end. + +test_atmost_Ok() -> + X = 2, + Y = 2, + if + X =< Y -> ok + end. + +test_atmost_Ok2() -> + X = 2, + Y = 3, + if + X =< Y -> ok + end. + +test_atmost_Bad() -> + X = 3, + Y = 2, + if + X =< Y -> ok + end.