2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
11 (* These are basically the same tests as in
12 * test/integration_ml/saved_state/test_naming_table_sqlite_fallback.ml, but
13 * as stripped down to just the basics as possible to make finding the root
14 * cause of test failures easier. *)
18 module Types_pos_asserter
= Asserter.Make_asserter
(struct
19 type t
= FileInfo.pos
* Naming_types.kind_of_type
21 let to_string (pos
, type_of_type
) =
24 (FileInfo.show_pos pos
)
25 (Naming_types.kind_of_type_to_enum type_of_type
)
30 module Pos_asserter
= Asserter.Make_asserter
(struct
33 let to_string pos
= Printf.sprintf
"(%s)" (FileInfo.show_pos pos
)
44 function bar
(): void
{}
54 let write_and_parse_test_files () =
56 List.map
files ~f
:(fun (fn
, contents
) ->
57 (Relative_path.from_root ~suffix
:fn
, contents
))
59 List.iter
files ~f
:(fun (fn
, contents
) ->
60 let fn = Path.make
(Relative_path.to_absolute
fn) in
61 let dir = Path.dirname
fn in
62 Disk.mkdir_p
(Path.to_string dir);
63 Disk.write_file ~file
:(Path.to_string fn) ~contents
);
64 let (file_infos
, errors
, failed_parsing
) =
67 Relative_path.Set.empty
68 ~get_next
:(MultiWorker.next None
(List.map
files ~f
:fst
))
72 if not
(Errors.is_empty errors
) then (
73 Errors.iter_error_list
75 List.iter
(Errors.to_list e
) ~f
:(fun (pos
, msg
) ->
76 eprintf
"%s: %s\n" (Pos.string (Pos.to_absolute pos
)) msg
))
78 failwith
"Expected no errors from parsing."
80 if failed_parsing
<> Relative_path.Set.empty
then
81 failwith
"Expected all files to pass parsing.";
82 Naming_table.create file_infos
85 Tempfile.with_real_tempdir
(fun path
->
86 Relative_path.set_path_prefix
88 (Path.concat path
"root/");
93 heap_size
= 1024 * 1024;
102 let (_
: SharedMem.handle
) = SharedMem.init
config ~num_workers
:0 in
104 Provider_context.empty_for_test
105 ~popt
:ParserOptions.default
106 ~tcopt
:TypecheckerOptions.default
109 let unbacked_naming_table = write_and_parse_test_files () in
110 let db_name = Path.to_string (Path.concat path
"naming_table.sqlite") in
111 let save_results = Naming_table.save
unbacked_naming_table db_name in
112 Asserter.Int_asserter.assert_equals
114 Naming_sqlite.(save_results.files_added
+ save_results.symbols_added
)
115 "Expected to add eight rows (four files and four symbols)";
116 let (_backed_naming_table
: Naming_table.t
) =
117 Naming_table.load_from_sqlite
ctx db_name
122 let test_dep_graph_blob () =
124 Tempfile.with_tempdir
@@ fun dir ->
125 let workers = None
in
126 let delegate_state = Typing_service_delegate.default
in
127 let opts = TypecheckerOptions.default
in
128 let dynamic_view_files = Relative_path.Set.empty
in
129 let memory_cap = None
in
131 Typing_service_types.
136 profile_type_check_duration_threshold
= 0.0;
137 profile_type_check_twice
= false;
141 Provider_context.empty_for_test ~popt
:ParserOptions.default ~tcopt
:opts
144 (* Check reentrancy *)
146 let (errors
, _delegate_state
, _telemetry
) =
147 Typing_check_service.go
151 (Telemetry.create
())
153 [Relative_path.from_root ~suffix
:"baz.php"]
158 Asserter.Bool_asserter.assert_equals
160 (Errors.is_empty errors
)
161 "Unexpected type errors";
163 Asserter.Int_asserter.assert_equals
165 (SharedMem.get_in_memory_dep_table_entry_count
())
166 "Expected the correct # of edges in memory after saving dep table blob";
168 let filename = Path.(to_string (concat
dir "deptable.bin")) in
170 SharedMem.save_dep_table_blob
173 ~reset_state_after_saving
:true
176 Asserter.Int_asserter.assert_equals
179 "Expected # of edges to be correct";
181 Asserter.Int_asserter.assert_equals
183 (SharedMem.get_in_memory_dep_table_entry_count
())
184 "Expected 0 edges in memory after saving dep table blob"
187 let () = Unit_test.run_all
[("test_dep_graph_blob", test_dep_graph_blob)]