From 97fde8643cad9b688c3115731fd29ef3329a6178 Mon Sep 17 00:00:00 2001 From: Akos Hajdu Date: Fri, 30 Jul 2021 05:34:30 -0700 Subject: [PATCH] [erl-frontend] Add tests related to variables Summary: Basic tests for variables and their assignments. Reviewed By: mmarescotti Differential Revision: D29964611 fbshipit-source-id: c22b3565c --- .../codetoanalyze/erlang/features/issues.exp | 4 ++ .../erlang/features/src/variables.erl | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 infer/tests/codetoanalyze/erlang/features/src/variables.erl diff --git a/infer/tests/codetoanalyze/erlang/features/issues.exp b/infer/tests/codetoanalyze/erlang/features/issues.exp index 4c3dd589d..c2af04349 100644 --- a/infer/tests/codetoanalyze/erlang/features/issues.exp +++ b/infer/tests/codetoanalyze/erlang/features/issues.exp @@ -59,3 +59,7 @@ codetoanalyze/erlang/features/src/tuples.erl, test_second_Bad/0, -24, NO_MATCHIN codetoanalyze/erlang/features/src/tuples.erl, test_third_Bad/0, -36, 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/tuples.erl, third/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] codetoanalyze/erlang/features/src/tuples.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] +codetoanalyze/erlang/features/src/variables.erl, test2_Bad/0, -13, 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/variables.erl, test3_Bad/0, -24, 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/variables.erl, test5_Bad/0, 2, NO_MATCH_OF_RHS, no_bucket, ERROR, [no match of RHS here] +codetoanalyze/erlang/features/src/variables.erl, warn/1, 0, NO_MATCHING_FUNCTION_CLAUSE, no_bucket, ERROR, [*** LATENT ***,no matching function clause here] diff --git a/infer/tests/codetoanalyze/erlang/features/src/variables.erl b/infer/tests/codetoanalyze/erlang/features/src/variables.erl new file mode 100644 index 000000000..25c268db4 --- /dev/null +++ b/infer/tests/codetoanalyze/erlang/features/src/variables.erl @@ -0,0 +1,59 @@ +% 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(variables). +-export([ + test1_Ok/0, + test2_Bad/0, + test3_Bad/0, + test4_Ok/0, + test5_Bad/0 +]). + +% Call this method with warn(1) to trigger a warning to expect +warn(0) -> ok. + +test1_Ok() -> + X = 2, + Y = X, + Z = 3, + case Y of + 2 -> ok + end, + case Z of + 3 -> ok + end. + +test2_Bad() -> + X = 2, + Y = X, + Z = 3, + case Y of + 2 -> warn(1) + end, + case Z of + 3 -> ok + end. + +test3_Bad() -> + X = 2, + Y = X, + Z = 3, + case Y of + 2 -> ok + end, + case Z of + 3 -> warn(1) + end. + +test4_Ok() -> + X = 2, + 2 = X, + ok. + +test5_Bad() -> + X = 2, + 3 = X, + ok.