diff --git a/infer/src/unit/accessPathTestUtils.ml b/infer/src/unit/accessPathTestUtils.ml new file mode 100644 index 000000000..e5fb78992 --- /dev/null +++ b/infer/src/unit/accessPathTestUtils.ml @@ -0,0 +1,20 @@ +(* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) + +let make_base base_str = + Var.of_pvar (Pvar.mk (Mangled.from_string base_str) Procname.empty_block), Typ.Tvoid + +let make_field_access access_str = + AccessPath.FieldAccess (Ident.create_fieldname (Mangled.from_string access_str) 0, Typ.Tvoid) + +let make_array_access () = + AccessPath.ArrayAccess Typ.Tvoid + +let make_access_path base_str access_strs = + make_base base_str, IList.map make_field_access access_strs diff --git a/infer/src/unit/accessPathTestUtils.mli b/infer/src/unit/accessPathTestUtils.mli new file mode 100644 index 000000000..ce48da573 --- /dev/null +++ b/infer/src/unit/accessPathTestUtils.mli @@ -0,0 +1,16 @@ +(* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) + +val make_base : string -> AccessPath.base + +val make_field_access : string -> AccessPath.access + +val make_array_access : unit -> AccessPath.access + +val make_access_path : string -> string list -> AccessPath.raw diff --git a/infer/src/unit/accessPathTests.ml b/infer/src/unit/accessPathTests.ml index 9abb1a1cb..ba4e431dd 100644 --- a/infer/src/unit/accessPathTests.ml +++ b/infer/src/unit/accessPathTests.ml @@ -11,20 +11,8 @@ open !Utils module F = Format -let make_base base_str = - Var.of_pvar (Pvar.mk (Mangled.from_string base_str) Procname.empty_block), Typ.Tvoid - -let make_field_access access_str = - AccessPath.FieldAccess (Ident.create_fieldname (Mangled.from_string access_str) 0, Typ.Tvoid) - -let make_access_path base_str accesses = - let rec make_accesses accesses_acc = function - | [] -> accesses_acc - | access_str :: l -> make_accesses ((make_field_access access_str) :: accesses_acc) l in - let accesses = make_accesses [] accesses in - make_base base_str, IList.rev accesses - let tests = + let open AccessPathTestUtils in let x = make_access_path "x" [] in let y = make_access_path "y" [] in let f_access = make_field_access "f" in diff --git a/infer/src/unit/accessTreeTests.ml b/infer/src/unit/accessTreeTests.ml index 8aaf7f78f..acf522f35 100644 --- a/infer/src/unit/accessTreeTests.ml +++ b/infer/src/unit/accessTreeTests.ml @@ -21,23 +21,6 @@ module MockTraceDomain = module Domain = AccessTree.Make (MockTraceDomain) -let make_base base_str = - Var.of_pvar (Pvar.mk (Mangled.from_string base_str) Procname.empty_block), Typ.Tvoid - -let make_field_access access_str = - AccessPath.FieldAccess (Ident.create_fieldname (Mangled.from_string access_str) 0, Typ.Tvoid) - -let make_array_access () = - AccessPath.ArrayAccess Typ.Tvoid - -let rec make_accesses accesses_acc = function - | [] -> accesses_acc - | access_str :: l -> make_accesses ((make_field_access access_str) :: accesses_acc) l - -let make_access_path base_str accesses = - let accesses = make_accesses [] accesses in - make_base base_str, IList.rev accesses - let assert_trees_equal tree1 tree2 = let rec access_tree_equal (trace1, subtree1) (trace2, subtree2) = MockTraceDomain.equal trace1 trace2 && match subtree1, subtree2 with @@ -51,6 +34,7 @@ let assert_trees_equal tree1 tree2 = OUnit2.assert_equal ~cmp:base_tree_equal ~pp_diff tree1 tree2 let tests = + let open AccessPathTestUtils in let x_base = make_base "x" in let y_base = make_base "y" in let z_base = make_base "z" in @@ -71,7 +55,7 @@ let tests = let zFG = AccessPath.Exact (make_access_path "z" ["f"; "g"]) in let xArrF = - let accesses = IList.rev (make_accesses [array] ["f"]) in + let accesses = [array; make_field_access "f"] in AccessPath.Exact (make_base "x", accesses) in let a_star = AccessPath.Abstracted (make_access_path "a" []) in