language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
OCaml
hhvm/hphp/hack/test/integration_ml/test_unbound_name.ml
open Integration_test_base_types module Test = Integration_test_base let a_file_name = "A.php" let b_file_name = "B.php" let a_contents = "<?hh // strict final class A { const mixed C = dict[ 'k' => B::class, ]; } " let b_contents = "<?hh // strict class B {} " let errors = {| File "/A.php", line 5, characters 12-12: Unbound name: `B` (an object type) (Naming[2049]) |} let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(a_file_name, a_contents); (b_file_name, "")] in Test.assert_env_errors env errors; let (env, _) = Test.( run_loop_once env { default_loop_input with disk_changes = [(b_file_name, b_contents)] }) in Test.assert_no_errors env; ignore env; ()
OCaml
hhvm/hphp/hack/test/integration_ml/test_unbound_name_2.ml
open Integration_test_base_types module Test = Integration_test_base let a_file_name = "A.php" let b_file_name = "B.php" let a_contents = "<?hh // strict type my_shape = shape( 'outer' => shape( B::KEY => string ), ); " let b_contents = "<?hh // strict class B { const string KEY = \"KEY\"; } " let errors = {| File "/A.php", line 5, characters 5-5: Unbound name: `B` (an object type) (Naming[2049]) |} let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(a_file_name, a_contents); (b_file_name, "")] in Test.assert_env_errors env errors; let (env, _) = Test.( run_loop_once env { default_loop_input with disk_changes = [(b_file_name, b_contents)] }) in Test.assert_no_errors env; ignore env; ()
OCaml
hhvm/hphp/hack/test/integration_ml/test_unbound_name_3.ml
open Integration_test_base_types module Test = Integration_test_base let a_file_name = "A.php" let b_file_name = "B.php" let c_file_name = "C.php" let a_contents = "<?hh new module foo {} " let b_contents = "<?hh new module foo {} " let c_contents = "<?hh module foo; class Foo {} " let errors = {| File "/B.php", line 2, characters 12-14: Name already bound: `foo` (Naming[2012]) File "/A.php", line 2, characters 14-16: Previous definition is here |} let test () = let env = Test.setup_server () in let env = Test.setup_disk env [ (a_file_name, a_contents); (b_file_name, b_contents); (c_file_name, c_contents); ] in Test.assert_env_errors env errors; let (env, _) = Test.( run_loop_once env { default_loop_input with disk_changes = [(b_file_name, "")] }) in Test.assert_no_errors env; ignore env; ()
hhvm/hphp/hack/test/integration_ml/ide/dune
(library (name test_all_ide) (wrapped false) (modules test_added_parent_ide test_auto_ns_aliasing test_diagnostics_in_closed_file test_error_pos test_error_throttling test_error_throttling_open_file test_exception_handling test_failed_naming_ide test_hhi_phpstdlib test_ide_check test_ide_close test_ide_consistency test_ide_disk test_ide_file_sync test_identify_symbol test_ide_parsing_errors test_ide_redecl test_ide_status test_ide_typing_deps test_max_errors test_naming_errors test_override test_remove_function test_remove_parent test_status_single test_unsaved_changes) (libraries integration_test_base)) (rule (alias identify_symbol) (deps ../test_all.exe) (action (run ../test_all.exe ide/identify_symbol))) (rule (alias ide_file_sync) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_file_sync))) (rule (alias ide_consistency) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_consistency))) (rule (alias ide_disk) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_disk))) (rule (alias ide_check) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_check))) (rule (alias ide_status) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_status))) (rule (alias ide_parsing_errors) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_parsing_errors))) (rule (alias ide_close) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_close))) (rule (alias ide_typing_deps) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_typing_deps))) (rule (alias added_parent) (deps ../test_all.exe) (action (run ../test_all.exe ide/added_parent))) (rule (alias auto_ns_aliasing) (deps ../test_all.exe) (action (run ../test_all.exe ide/auto_ns_aliasing))) (rule (alias remove_function) (deps ../test_all.exe) (action (run ../test_all.exe ide/remove_function))) (rule (alias diagnostics_in_closed_file) (deps ../test_all.exe) (action (run ../test_all.exe ide/diagnostics_in_closed_file))) (rule (alias error_throttling) (deps ../test_all.exe) (action (run ../test_all.exe ide/error_throttling))) (rule (alias max_errors) (deps ../test_all.exe) (action (run ../test_all.exe ide/max_errors))) (rule (alias naming_errors) (deps ../test_all.exe) (action (run ../test_all.exe ide/naming_errors))) (rule (alias override) (deps ../test_all.exe) (action (run ../test_all.exe ide/override))) (rule (alias remove_parent) (deps ../test_all.exe) (action (run ../test_all.exe ide/remove_parent))) (rule (alias failed_naming) (deps ../test_all.exe) (action (run ../test_all.exe ide/failed_naming))) (rule (alias unsaved_changes) (deps ../test_all.exe) (action (run ../test_all.exe ide/unsaved_changes))) (rule (alias hhi_phpstdlib) (deps ../test_all.exe) (action (run ../test_all.exe ide/hhi_phpstdlib))) (rule (alias ide_redecl) (deps ../test_all.exe) (action (run ../test_all.exe ide/ide_redecl))) (rule (alias error_throttling_open_file) (deps ../test_all.exe) (action (run ../test_all.exe ide/error_throttling_open_file))) (rule (alias error_pos) (deps ../test_all.exe) (action (run ../test_all.exe ide/error_pos))) (rule (alias exception_handling) (deps ../test_all.exe) (action (run ../test_all.exe ide/exception_handling))) (rule (alias status_single) (deps ../test_all.exe) (action (run ../test_all.exe ide/status_single))) (alias (name runtest) (deps (alias identify_symbol) (alias ide_file_sync) (alias ide_consistency) (alias ide_disk) (alias ide_check) (alias ide_status) (alias ide_parsing_errors) (alias ide_close) (alias ide_typing_deps) (alias added_parent) (alias auto_ns_aliasing) (alias remove_function) (alias diagnostics_in_closed_file) (alias error_throttling) (alias naming_errors) (alias override) (alias remove_parent) (alias failed_naming) (alias unsaved_changes) (alias hhi_phpstdlib) (alias ide_redecl) (alias error_throttling_open_file) (alias error_pos) (alias exception_handling) (alias status_single)))
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_added_parent_ide.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = "<?hh // strict class Foo { /* HH_FIXME[4110] */ public function f() : string { } } " let foo_child_name = "foo_child.php" let foo_child_contents = "<?hh // strict /* HH_FIXME[2049] */ /* HH_FIXME[4123] */ class FooChild extends Foo {} " let bar_name = "bar.php" let bar_contents = "<?hh // strict function take_int(int $x) : void {} function test(FooChild $foo_child) : void { take_int($foo_child->f()); } " let bar_diagnostics = " /bar.php: File \"/bar.php\", line 6, characters 12-26: Invalid argument (Typing[4110]) File \"/bar.php\", line 3, characters 19-21: Expected int File \"/foo.php\", line 5, characters 25-30: But got string " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [ (foo_name, ""); (foo_child_name, foo_child_contents); (bar_name, bar_contents); ] in let env = Test.connect_persistent_client env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_output; let env = Test.open_file env foo_name in let env = Test.open_file env bar_name in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_output; let (env, _) = Test.edit_file env foo_name foo_contents in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output bar_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_auto_ns_aliasing.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_contents = "<?hh // strict namespace HH\\LongName\\ShortName; function foo() : void {} " let autocomplete_contents0 = "<?hh // strict function testTypecheck(): void { ShortName\\foAUTO332; } " let autocomplete_contents1 = "<?hh function testTypecheck(): void { \\ShortName\\foAUTO332; } " let autocomplete_contents2 = "<?hh // strict function testTypecheck(): void { HH\\LongName\\ShortName\\foAUTO332; } " let autocomplete_contents3 = "<?hh // strict function testTypecheck(): void { \\HH\\LongName\\ShortName\\foAUTO332; } " let autocomplete_contents4 = "<?hh // strict namespace Test; function testTypecheck(): void { HH\\LongName\\ShortName\\foAUTO332; } " let autocomplete_contents5 = "<?hh // strict namespace Test; function testTypecheck(): void { \\HH\\LongName\\ShortName\\foAUTO332; } " let autocomplete_contents6 = "<?hh // strict namespace Test; function testTypecheck(): void { ShortName\\foAUTO332; } " let autocomplete_contents7 = "<?hh // strict namespace Test; function testTypecheck(): void { \\ShortName\\foAUTO332; } " let test () = let global_opts : GlobalOptions.t = GlobalOptions.set ~tco_saved_state:GlobalOptions.default_saved_state ~po_auto_namespace_map:[("ShortName", "HH\\LongName\\ShortName")] ~po_deregister_php_stdlib:true GlobalOptions.default in let custom_config = ServerConfig.default_config in let custom_config = ServerConfig.set_tc_options custom_config global_opts in let custom_config = ServerConfig.set_parser_options custom_config global_opts in let env = Test.setup_server ~custom_config () in let env = Test.setup_disk env [("foo.php", foo_contents)] in let env = let get_name i = "test" ^ string_of_int i ^ ".php" in Test.setup_disk env @@ List.mapi (fun i contents -> let clean_contents = Str.global_replace (Str.regexp_string "AUTO332") "" contents in (get_name i, clean_contents)) [ autocomplete_contents0; autocomplete_contents1; autocomplete_contents2; autocomplete_contents3; autocomplete_contents4; autocomplete_contents5; autocomplete_contents6; autocomplete_contents7; ] in let env = Test.connect_persistent_client env in let test_ide env contents i expected = let path = "test" ^ string_of_int i ^ ".php" in let offset = String_utils.substring_index AutocompleteTypes.autocomplete_token contents in let position = File_content.offset_to_position contents offset in let line = position.File_content.line in let column = position.File_content.column in let (_, loop_output) = Test.ide_autocomplete env (path, line, column) in Test.assert_ide_autocomplete loop_output expected in (* Note that autocomplete now hides namespaces when you've already typed them! * This means that all tests will simply return "foo" as long as you're in * the correct namespace when autocomplete is triggered. *) test_ide env autocomplete_contents0 0 ["foo"]; test_ide env autocomplete_contents1 1 []; test_ide env autocomplete_contents2 2 ["foo"]; test_ide env autocomplete_contents3 3 ["foo"]; test_ide env autocomplete_contents4 4 []; test_ide env autocomplete_contents5 5 ["foo"]; test_ide env autocomplete_contents6 6 ["foo"]; test_ide env autocomplete_contents7 7 []; ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_diagnostics_in_closed_file.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = Printf.sprintf "<?hh // strict /* HH_FIXME[4336] */ function foo() : %s { } " let foo_returns_int = foo_contents "int" let foo_returns_string = foo_contents "string" let bar_name = "bar.php" let bar_contents = "<?hh // strict function test(): int { return foo(); } " let bar_diagnostics = " /bar.php: File \"/bar.php\", line 5, characters 10-14: Invalid return type (Typing[4110]) File \"/bar.php\", line 4, characters 18-20: Expected `int` File \"/foo.php\", line 4, characters 18-23: But got `string` " let bar_clear = " /bar.php: " let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4336 allowed_decl_fixme_codes = 4336 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let env = Test.setup_disk env [(foo_name, foo_returns_int); (bar_name, bar_contents)] in let env = Test.connect_persistent_client env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_errors env; Test.assert_no_diagnostics loop_output; (* Open both files and make an edit to foo that results in errors in bar *) let env = Test.open_file env foo_name in let env = Test.open_file env bar_name in let (env, _) = Test.edit_file env foo_name foo_returns_string in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output bar_diagnostics; (* Close bar, make sure that errors is still there, not cleared *) let (env, _) = Test.close_file env bar_name in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output bar_diagnostics; (* Fix foo, check that the error in bar was cleared - even though the * file is not currently open in IDE *) let (env, _) = Test.edit_file env foo_name foo_returns_int in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output bar_clear
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_error_pos.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = Printf.sprintf "<?hh // strict %s /* HH_FIXME[4336] */ function foo(): string { }" let bar_name = Printf.sprintf "bar%d.php" let bar_contents = Printf.sprintf "<?hh function bar%d (): int { return foo(); } " let create_bar i = (bar_name i, bar_contents i) let bar_106_name = bar_name 106 let bar_107_name = bar_name 107 let rec create_bars acc = function | 0 -> acc | i -> create_bars (create_bar i :: acc) (i - 1) let assert_10_diagnostics loop_output = let error_count = SMap.fold (fun _key errors count -> count + List.length errors) (Test.get_diagnostics loop_output) 0 in if error_count <> 10 then Test.fail @@ Printf.sprintf "Expected 10 push diagnostics but got %d." error_count let bar_107_foo_line_3_diagnostics = {| /bar107.php: File "/bar107.php", line 4, characters 10-14: Invalid return type (Typing[4110]) File "/bar107.php", line 3, characters 21-23: Expected `int` File "/foo.php", line 4, characters 17-22: But got `string` |} let bar_107_foo_line_5_diagnostics = {| /bar107.php: File "/bar107.php", line 4, characters 10-14: Invalid return type (Typing[4110]) File "/bar107.php", line 3, characters 21-23: Expected `int` File "/foo.php", line 6, characters 17-22: But got `string` |} let bar106_cleared = {| /bar106.php: |} let bar107_cleared = {| /bar107.php: |} let bar_108_foo_line_5_diagnostics = {| /bar108.php: File "/bar108.php", line 4, characters 10-14: Invalid return type (Typing[4110]) File "/bar108.php", line 3, characters 21-23: Expected `int` File "/foo.php", line 6, characters 17-22: But got `string` |} let bar_109_foo_line_3_diagnostics = {| /bar109.php: File "/bar109.php", line 4, characters 10-14: Invalid return type (Typing[4110]) File "/bar109.php", line 3, characters 21-23: Expected `int` File "/foo.php", line 4, characters 17-22: But got `string` |} let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4336 allowed_decl_fixme_codes = 4336 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in (* 200 files with errors *) let disk_contents = [(foo_name, foo_contents "")] in let disk_contents = create_bars disk_contents 200 in let env = Test.setup_disk env disk_contents in let env = Test.connect_persistent_client env in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_in loop_output ~filename:bar_107_name bar_107_foo_line_3_diagnostics; (* Move foo 2 lines down *) let env = Test.open_file env foo_name ~contents:(foo_contents "\n\n") in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in assert_10_diagnostics loop_output; let (env, loop_output) = Test.full_check_status env in Test.assert_diagnostics_in loop_output ~filename:bar_107_name bar_107_foo_line_5_diagnostics; Test.assert_diagnostics_in loop_output ~filename:(bar_name 108) bar_108_foo_line_5_diagnostics; (* Fix one of the errors *) let (env, _) = Test.edit_file env bar_107_name "" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output bar107_cleared; (* Edit foo back to test "edit already opened file" scenario too. *) let (env, _) = Test.edit_file env foo_name (foo_contents "") in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in assert_10_diagnostics loop_output; let (env, _) = Test.edit_file env bar_106_name "" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_in loop_output ~filename:bar_106_name bar106_cleared; (* Notice that foo position is back to line 3 *) Test.assert_diagnostics_in loop_output ~filename:(bar_name 109) bar_109_foo_line_3_diagnostics; ignore env
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_error_throttling.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Reordered_argument_collections module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = Printf.sprintf "<?hh /* HH_FIXME[4336] */ function foo(): %s { } " let foo_returns_int = foo_contents "int" let foo_returns_string = foo_contents "string" let bar_name = Printf.sprintf "bar%d.php" let bar_contents = Printf.sprintf "<?hh function bar%d (): int { return foo(); } " let baz_name = "baz.php" let baz_contents = "<?hh { " let create_bar i = (bar_name i, bar_contents i) let get_diagnostics_map = Integration_test_base.get_diagnostics let get_files_with_errors diagnostics_map = SSet.of_list (SMap.keys diagnostics_map) let rec create_bars acc = function | 0 -> acc | i -> create_bars (create_bar i :: acc) (i - 1) let bar_10_clear_diagnostics = " /bar10.php: " let bar_106_diagnostics = {| /bar106.php: File "/bar106.php", line 4, characters 10-14: Invalid return type (Typing[4110]) File "/bar106.php", line 3, characters 21-23: Expected `int` File "/foo.php", line 3, characters 17-22: But got `string` |} let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4336 allowed_decl_fixme_codes = 4336 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let disk_contests = [(foo_name, foo_returns_int)] in let disk_contests = create_bars disk_contests 200 in let env = Test.setup_disk env disk_contests in let env = Test.connect_persistent_client env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_errors env; Test.assert_no_diagnostics loop_output; (* Change a definition that introduces error in all 200 files, and also * make another error in other open file *) let env = Test.open_file env foo_name ~contents:foo_returns_string in let env = Test.open_file env baz_name ~contents:baz_contents in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in (* Make sure that the open file is among the errors *) let diagnostics_map = get_diagnostics_map loop_output in let files_with_errors = get_files_with_errors diagnostics_map in let baz_name = Test.prepend_root baz_name in if not @@ SSet.mem files_with_errors baz_name then Test.fail "Expected diagnostics for baz.php"; (* Trigger global recheck *) let (env, loop_output) = Test.full_check_status env in Test.assert_diagnostics_in loop_output ~filename:(bar_name 106) bar_106_diagnostics; (* Fix one of the remaining errors *) let bar_10_name = bar_name 10 in let (env, _) = Test.edit_file env bar_10_name "" in let env = Test.wait env in let (_env, loop_output) = Test.(run_loop_once env default_loop_input) in (* Check that the errors from bar10 are removed *) Test.assert_diagnostics_string loop_output bar_10_clear_diagnostics; ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_error_throttling_open_file.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) (** * Ensure that errors in open file are never filtered, even if we are * throttling errors in other files to avoid overloading the editor. *) open Reordered_argument_collections module Test = Integration_test_base let foo_name = Printf.sprintf "foo%d.php" let foo_contents = Printf.sprintf "<?hh // strict function foo%d (): string { return 4;} " let create_foo i = (foo_name i, foo_contents i) let rec create_foos acc = function | 0 -> acc | i -> create_foos (create_foo i :: acc) (i - 1) let get_diagnostics_map = Integration_test_base.get_diagnostics let get_files_with_errors diagnostics_map = SSet.of_list (SMap.keys diagnostics_map) let f123_diagnostics = {|/foo123.php: File "/foo123.php", line 3, characters 37-37: Invalid return type (Typing[4110]) File "/foo123.php", line 3, characters 21-26: Expected `string` File "/foo123.php", line 3, characters 37-37: But got `int` |} let test () = (* Initialize a repo with errors in 200 files *) let env = Test.setup_server () in let disk_contests = create_foos [] 200 in let env = Test.setup_disk env disk_contests in (* After connecting, errors for 10 of them will be pushed to editor *) let env = Test.connect_persistent_client env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in let (f123_name, _) = create_foo 123 in Test.assert_diagnostics_in loop_output ~filename:f123_name f123_diagnostics; ignore env
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_exception_handling.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in let (_env, _) = Test.( run_loop_once env { default_loop_input with persistent_client_request = Some (UncleanDisconect (ServerCommandTypes.STATUS { ignore_ide = false; remote = false; max_errors = None })); }) in match Ide_info_store.get () with | None -> () | Some _ -> failwith "expected persistent client to be disconnected"
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_failed_naming_ide.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo1_name = "foo1.php" let foo2_name = "foo2.php" let foo_contents = "<?hh // strict function foo() : void {} " let bar_contents = "<?hh // strict function test(): void { foo(); } " let init_errors = {| File "/foo2.php", line 3, characters 10-12: Name already bound: `foo` (Naming[2012]) File "/foo1.php", line 3, characters 10-12: Previous definition is here |} let init_diagnostics = {| /foo2.php: File "/foo2.php", line 3, characters 10-12: Name already bound: `foo` (Naming[2012]) File "/foo1.php", line 3, characters 10-12: Previous definition is here |} let final_diagnostics = {| /foo2.php: |} let test () = let env = Test.setup_server () in let env = Test.setup_disk env [ (foo1_name, foo_contents); (foo2_name, foo_contents); ("bar.php", bar_contents); ] in Test.assert_env_errors env init_errors; let env = Test.connect_persistent_client env in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output init_diagnostics; (* Replace one of the duplicate definitions with a parsing error *) let env = Test.open_file env foo2_name ~contents:"<?hh // strict \n {" in (* Trigger a lazy recheck *) let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in (* Files with parsing errors are not redeclared during lazy recheck, so * failed_naming should remain unchanged *) let failed = Errors.get_failed_files env.ServerEnv.errorl in let found = Relative_path.Set.mem failed (Relative_path.from_root ~suffix:foo1_name) || Relative_path.Set.mem failed (Relative_path.from_root ~suffix:foo2_name) in if not found then Test.fail "File missing from failed"; (* Remove the parsing error - there should be no errors after that *) let (env, _) = Test.edit_file env foo2_name "<?hh // strict" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output final_diagnostics; (* Trigger a global recheck just to be sure *) let (env, _) = Test.status env in Test.assert_no_errors env
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_hhi_phpstdlib.ml
(* Autocomplete for when po_deregister_php_stdlib is on *) module Test = Integration_test_base let foo_contents = "<?hh // strict function idz() : string { return \"\"; } function testTypecheck(): string { return \"\"; } " let autocomplete_contents = "<?hh // strict function testTypecheck2(): string { return idAUTO332; } " let hhi_contents = "<?hh // strict <<__PHPStdLib>> function idx(int $x): string { return 5; } function idy() : string { return \"hello\"; } " let hhi_name = "hhi.php" let test () = let hhi_files = [(hhi_name, hhi_contents)] in let env = Test.setup_server ~hhi_files () in let env = Test.setup_disk env [("foo.php", foo_contents)] in Test.assert_no_errors env; let env = Test.setup_disk env [("test.php", autocomplete_contents)] in let env = Test.connect_persistent_client env in let (_, _loop_output) = Test.ide_autocomplete env ("test.php", 4, 12) in (* idy and idz should be found, but idx should be missing *) (*Test.assert_ide_autocomplete loop_output ["idy"; "idz"]*) ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_identify_symbol.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let foo_contents = "<?hh function foo() { } " let bar_contents = "<?hh function test() { foo(); }" let identify_foo_request = ServerCommandTypes.IDENTIFY_FUNCTION ("", ServerCommandTypes.FileContent bar_contents, 4, 4) let check_identify_foo_response = function | Some [(_, Some def)] -> let string_pos = Pos.string def.SymbolDefinition.pos in let expected_pos = "File \"/foo.php\", line 3, characters 10-12:" in Test.assertEqual expected_pos string_pos | _ -> Test.fail "Expected to find exactly one definition" let test () = let env = Test.setup_server () in let env = Test.setup_disk env [("foo.php", foo_contents)] in let (env, loop_output) = Test.( run_loop_once env { default_loop_input with new_client = Some (RequestResponse identify_foo_request); }) in check_identify_foo_response loop_output.new_client_response; let env = Test.connect_persistent_client env in let (_, loop_output) = Test.( run_loop_once env { default_loop_input with persistent_client_request = Some (Request identify_foo_request); }) in check_identify_foo_response loop_output.persistent_client_response
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_check.ml
(** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let a_name = "a.php" let a_contents1 = "<?hh // strict class A { public function foo() : void {} } " (* Parsing error *) let a_contents2 = "<?hh // strict { " (* Replace foo with bar, and also introduce local typing error *) let a_contents3 = "<?hh // strict class A { public function bar(int $x) : void { $x + 'a'; // bug } } " let a_contents3_diagnostics = "/a.php: File \"/a.php\", line 4, characters 10-12: Typing error (Typing[4110]) File \"/a.php\", line 4, characters 5-12: Expected `num` because this is used in an arithmetic operation File \"/a.php\", line 4, characters 10-12: But got `string`" let b_name = "b.php" let b_contents = "<?hh // strict class B extends A { public function test() : void { $this->foo(); // this will be an error after we remove A::foo } } " let final_global_diagnostics = " /a.php: File \"/a.php\", line 4, characters 10-12: Typing error (Typing[4110]) File \"/a.php\", line 4, characters 5-12: Expected `num` because this is used in an arithmetic operation File \"/a.php\", line 4, characters 10-12: But got `string` /b.php: File \"/b.php\", line 4, characters 12-14: No instance method `foo` in `B` (Typing[4053]) File \"/a.php\", line 3, characters 19-21: Did you mean `bar` instead? File \"/b.php\", line 2, characters 7-7: This is why I think it is an object of type B File \"/b.php\", line 2, characters 7-7: Declaration of `B` is here " let autocomplete_contents = "<?hh function test(B $b) : void { $b->AUTO332; // this should return bar() after we do the edit } " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(a_name, a_contents1); (b_name, b_contents)] in let env = Test.connect_persistent_client env in (* Open a file and send two edits, both with errors, in quick succession. *) let env = Test.open_file env a_name in let (env, loop_output) = Test.edit_file env a_name a_contents2 in (* See that we don't compute diagnostics immediately, but batch them * with delay *) Test.assert_no_diagnostics loop_output; let (env, loop_output) = Test.edit_file env a_name a_contents3 in (* As above *) Test.assert_no_diagnostics loop_output; (* Wait for push diagnostics *) let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in (* Expect diagnostics only for the most recent version of the file *) Test.assert_diagnostics_string loop_output a_contents3_diagnostics; (* Check that edit is reflected in autocomplete results let env = Test.open_file env "test.php" ~contents:autocomplete_contents in let (env, loop_output) = Test.ide_autocomplete env ("test.php", 3, 7) in Test.assert_ide_autocomplete loop_output ["test"; "bar"]; *) (* Trigger global analysis *) let (_, loop_output) = Test.( run_loop_once env { default_loop_input with disk_changes = [ (* The actual change doesn't matter - saving anything to disk just * happens to currently be a trigger for global recheck *) ("x.php", ""); ]; }) in (* Global recheck produces full list of errors, including errors in b.php *) Test.assert_diagnostics_string loop_output final_global_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_close.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open ServerEnv open Hh_prelude module Test = Integration_test_base let foo_name = "foo.php" let foo_disk_contents = "<?hh // strict function foo(string $x) : void {} function test() : void { foo(4); } " let foo_disk_errors = " File \"/foo.php\", line 6, characters 7-7: Invalid argument (Typing[4110]) File \"/foo.php\", line 3, characters 14-19: Expected `string` File \"/foo.php\", line 6, characters 7-7: But got `int` " let foo_disk_diagnostics = " /foo.php: File \"/foo.php\", line 6, characters 7-7: Invalid argument (Typing[4110]) File \"/foo.php\", line 3, characters 14-19: Expected `string` File \"/foo.php\", line 6, characters 7-7: But got `int` " let foo_ide_contents = "<?hh { " let foo_ide_errors = [ " File \"/foo.php\", line 3, characters 2-2: A right brace `}` is expected here. (Parsing[1002]) "; " File \"/foo.php\", line 3, characters 1-1: Hack does not support top level statements. Use the `__EntryPoint` attribute on a function instead (Parsing[1002]) "; ] let foo_ide_diagnostics = " /foo.php: File \"/foo.php\", line 3, characters 1-1: Hack does not support top level statements. Use the `__EntryPoint` attribute on a function instead (Parsing[1002]) File \"/foo.php\", line 3, characters 2-2: A right brace `}` is expected here. (Parsing[1002]) " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(foo_name, foo_disk_contents)] in let env = Test.connect_persistent_client env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assertSingleError foo_disk_errors (Errors.get_error_list env.errorl); Test.assert_diagnostics_string loop_output foo_disk_diagnostics; let env = Test.open_file env foo_name in let (env, _) = Test.edit_file env foo_name foo_ide_contents in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in (* Force update to global error list *) let (env, _) = Test.status env in begin match List.zip foo_ide_errors (Errors.get_error_list env.errorl) with | List.Or_unequal_lengths.Ok errs -> List.iter ~f:(fun (expected, err) -> Test.assertSingleError expected [err]) errs | List.Or_unequal_lengths.Unequal_lengths -> Test.fail "Expected 2 errors.\n" end; Test.assert_diagnostics_string loop_output foo_ide_diagnostics; (* Close the file and check that error lists are back to reflecting disk * contents *) let (env, _) = Test.close_file env foo_name in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in let (env, _) = Test.status env in Test.assertSingleError foo_disk_errors (Errors.get_error_list env.errorl); Test.assert_diagnostics_string loop_output foo_disk_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_consistency.ml
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = "<?hh class C { public function foo() { } } " let foo_contents_with_parse_error = "<?hh class C { public function bar() {PARSE_ERROR } } " let bar_name = "bar.php" let bar_contents = "<?hh function test() { (new C())->f } " let run_and_check_autocomplete env expected_rechecked expected = (* Simulate time passing to trigger recheck *) let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in if loop_output.total_changed_files_count != expected_rechecked then Test.fail (Printf.sprintf "Expected %d files to be rechecked" expected_rechecked); let (env, loop_output) = Test.ide_autocomplete env (bar_name, 3, 15) in Test.assert_ide_autocomplete loop_output expected; (env, loop_output) let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in (* Create and put content in two files *) let env = Test.open_file env foo_name ~contents:foo_contents in let env = Test.open_file env bar_name ~contents:bar_contents in (* Check that autocompletions in one file are aware of definitions in * another one*) let (env, _) = run_and_check_autocomplete env 2 ["foo"] in let (env, _) = Test.edit_file env foo_name foo_contents_with_parse_error in (* If C had parse errors, we'll not update it's declarations, so * the result will not change *) let _ = run_and_check_autocomplete env 1 ["bar"] in ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_diagnostic_subscription.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let diagnostic_subscription_id = 223 let foo_name = "foo.php" let foo_contents = "<?hh { " let foo_diagnostics = " /foo.php: File \"/foo.php\", line 2, characters 1-1: Hack does not support top level statements. Use the `__EntryPoint` attribute on a function instead (Parsing[1002]) File \"/foo.php\", line 2, characters 2-2: A right brace `}` is expected here. (Parsing[1002])" let foo_clear_diagnostics = " /foo.php: " let bar_name = "bar.php" let bar_contents = "<?hh // strict function test() {} // missing return type " let bar_diagnostics = " /bar.php: File \"/bar.php\", line 2, characters 10-13: Was expecting a return type hint (Typing[4030])" let assert_no_push_message loop_outputs = match loop_outputs.push_messages with | _ :: _ -> Test.fail "Unexpected push message" | [] -> () let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in (* Initially there is a single typing error in bar.php *) let (env, loop_outputs) = Test.change_files env [(bar_name, bar_contents)] in (* Initial list of errors is pushed after subscribing *) Test.assert_diagnostics_string loop_outputs bar_diagnostics; (* Open and edit file to have errors *) let env = Test.open_file env foo_name ~contents:foo_contents in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_outputs foo_diagnostics; let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in assert_no_push_message loop_outputs; (* Fix the errors in file *) let (env, _) = Test.edit_file env foo_name "" in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_outputs foo_clear_diagnostics; let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in assert_no_push_message loop_outputs; (* Change the file, but still no new errors *) let (env, _) = Test.edit_file env foo_name "<?hh\n" in let env = Test.wait env in let (_, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_outputs
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_disk.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types open ServerEnv module Test = Integration_test_base let foo_name = "foo.php" let foo_no_errors = "<?hh function foo(): void { } " let foo_with_errors = "<?hh {" let bar_name = "bar.php" let foo2_definition = "function foo2(): void {}\n" let bar_contents = "<?hh function test(): void { fo } " let check_has_no_errors env = match Errors.get_error_list env.errorl with | [] -> () | es -> let buf = Buffer.create 256 in Buffer.add_string buf "Expected to have no errors, but instead got: "; List.iter (fun e -> Buffer.add_string buf "\n - "; let str = Errors.to_string (User_error.to_absolute e) in Buffer.add_string buf str) es; let msg = Buffer.contents buf in Test.fail msg let check_has_errors env = match Errors.get_error_list env.errorl with | [] -> Test.fail "Expected to have errors" | _ -> () let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(foo_name, foo_no_errors)] in let env = Test.connect_persistent_client env in (* There are no errors initially *) check_has_no_errors env; (* Open pre-existing file in editor *) let env = Test.open_file env foo_name in (* Update disk contents to contain errors *) let (env, loop_output) = Test.( run_loop_once env { default_loop_input with disk_changes = [(foo_name, foo_with_errors)] }) in assert loop_output.did_read_disk_changes; (* But since file is open in editor, contents from disk are ignored *) check_has_no_errors env; Test.assert_no_diagnostics loop_output; (* We edit the file to content with errors *) let (env, _) = Test.edit_file env foo_name foo_with_errors in (* Sending a command just schedules a recheck, but it doesn't happen * immediately *) check_has_no_errors env; Test.assert_no_diagnostics loop_output; (* Simulate time passing since last command to trigger a recheck *) let env = Test.wait env in (* Next iteration executes the recheck and generates the errors *) let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_has_diagnostics loop_output; (* Edit file back to have no errors *) let (env, _) = Test.edit_file env foo_name foo_no_errors in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in Test.assert_has_diagnostics loop_output; check_has_no_errors env; (* We close the file, disk contents should be taken into account again *) let (env, _) = Test.close_file env foo_name in let env = Test.wait env in (* TODO: this should be unnecessary, closing the file should recheck the disk * contents automatically *) let (env, _) = Test.( run_loop_once env { default_loop_input with disk_changes = [(foo_name, foo_with_errors)] }) in assert loop_output.did_read_disk_changes; (* Disk errors are now reflected *) check_has_errors env
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_file_sync.ml
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_no_errors = "<?hh function foo() { } " let foo_with_errors = "<?hh {" let bar_name = "bar.php" let bar_contents = "<?hh function test() { fo } " let bar_new_contents = "<?hh function foo2() {} function test() { fo } " let build_code_edit st_line st_column ed_line ed_column text = Ide_api_types. { range = Some { st = { line = st_line; column = st_column }; ed = { line = ed_line; column = ed_column }; }; text; } let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(foo_name, foo_no_errors)] in let env = Test.connect_persistent_client env in (* Open a new file in editor *) let env = Test.open_file env bar_name ~contents:"" in (* Start typing in the new file *) let (env, _) = Test.edit_file env bar_name bar_contents in (* Request completions *) let (env, loop_output) = Test.ide_autocomplete env (bar_name, 3, 5) in Test.assert_ide_autocomplete loop_output ["foo"]; (* Add a new definition to the file and save it *) let (env, _) = Test.edit_file env bar_name bar_new_contents in let (env, _) = Test.save_file env bar_name bar_new_contents in (* Check that new definition is among the completions *) let (_, loop_output) = Test.ide_autocomplete env (bar_name, 4, 5) in Test.assert_ide_autocomplete loop_output ["foo"; "foo2"]
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_parsing_errors.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_parent_name = "foo_parent.php" let foo_parent_contents1 = "<?hh // strict class FooParent { public function lol() : void {} } " let foo_parent_contents2 = "<?hh // strict class FooParent {} " let foo_name = "foo.php" let foo_contents1 = "<?hh // strict class Foo extends FooParent { public function bar() : void { } } " let foo_contents2 = "<?hh // strict class Fo " let foo_diagnostics = " /foo.php: File \"/foo.php\", line 3, characters 9-9: A left brace `{` is expected here. (Parsing[1002]) " let autocomplete_contents = "<?hh function test(Foo $foo) { $foo->AUTO332 } " let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in let env = Test.open_file env foo_parent_name ~contents:foo_parent_contents1 in let env = Test.open_file env foo_name ~contents:foo_contents1 in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_output; (* Introduce an irrecoverable parsing error in Foo definition - if we would * proceed to try to redeclare foo.php, Foo will no longer exist *) let (env, _) = Test.edit_file env foo_name foo_contents2 in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output foo_diagnostics; (* Change the Foo parent to trigger invalidating Foo *) let (env, _) = Test.edit_file env foo_parent_name foo_parent_contents2 in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in (* Check that Foo definiton is still available for querying *) let env = Test.open_file env "test.php" ~contents:autocomplete_contents in let (_, loop_output) = Test.ide_autocomplete env ("test.php", 4, 9) in Test.assert_ide_autocomplete_does_not_contain loop_output ["bar"]
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_redecl.ml
(* Delete a file that still has dangling references *) open Integration_test_base_types module Test = Integration_test_base let foo_contents = "<?hh // strict class Food { public function f(): void {} } " let foo2_contents = "<?hh // strict class Food { public function f(): void {} } " let bar_contents = "<?hh // strict class Bar extends Food { public function test() : void { $this->f(); } } " let bar2_contents = "<?hh // strict class Bar extends Foo { public function test() : string { return $this->g(); } } " let assert_no_push_message loop_outputs = match loop_outputs.push_messages with | _ :: _ -> Test.fail "Unexpected push message" | [] -> () let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in (* Initially there is a single typing error in bar.php *) let env = Test.setup_disk env [("foo.php", foo_contents); ("bar.php", bar_contents)] in (* Edit foo, which causes bar.php to be added to "lazy_decl_later" *) let (env, _) = Test.(run_loop_once env default_loop_input) in let env = Test.open_file env "foo.php" ~contents:foo_contents in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in assert_no_push_message loop_outputs; let (env, _) = Test.edit_file env "foo.php" foo2_contents in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in (* Edit bar once *) let env = Test.open_file env "bar.php" ~contents:bar_contents in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in let (env, _) = Test.edit_file env "bar.php" bar2_contents in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in (* Edit bar a second time, causing it to be oldified twice *) let env = Test.open_file env "bar.php" ~contents:bar_contents in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in let (env, _) = Test.edit_file env "bar.php" bar_contents in let env = Test.wait env in let (_, _) = Test.(run_loop_once env default_loop_input) in ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_status.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_takes_int_contents = "<?hh // strict function foo(int $x) : void {} " let foo_takes_string_contents = "<?hh // strict function foo(string $x) : void {} " let bar_name = "bar.php" let bar_contents = "<?hh // strict function test(): void { foo(4); } " let full_diagnostics = " /bar.php: File \"/bar.php\", line 4, characters 7-7: Invalid argument (Typing[4110]) File \"/foo.php\", line 3, characters 14-19: Expected `string` File \"/bar.php\", line 4, characters 7-7: But got `int` " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [ (foo_name, foo_takes_int_contents); (bar_name, bar_contents); (* no errors *) ] in let env = Test.connect_persistent_client env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_outputs; (* no diagnostics initially *) let env = Test.open_file env foo_name in let (env, _) = Test.edit_file env foo_name foo_takes_string_contents in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in (* Change introduces an error in bar.php, but this file is not open in IDE * so we don't recheck it immediately. *) Test.assert_no_diagnostics loop_outputs; (* Asking for global error list will trigger recheck of bar.php *) let (_, loop_outputs) = Test.full_check_status env in Test.assert_diagnostics_string loop_outputs full_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_ide_typing_deps.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let take_int_name = "take_int.php" let take_int_contents = "<?hh // strict function take_int(int $x) : void {} " let foo_name = "foo.php" let foo_contents = Printf.sprintf "<?hh // strict class Foo { /* HH_FIXME[4336] */ public function f() : %s { } } " let foo_child_name = "foo_child.php" let foo_child_contents = "<?hh // strict class FooChild extends Foo {} " let bar_name = "bar.php" let bar_contents = "<?hh // strict function test_foo(Foo $foo) : void { take_int($foo->f()); } " let baz_name = "baz.php" let baz_contents = "<?hh // strict function test_foo_child(FooChild $foo_child) : void { take_int($foo_child->f()); } " let diagnostics = " /bar.php: File \"/bar.php\", line 4, characters 12-20: Invalid argument (Typing[4110]) File \"/take_int.php\", line 3, characters 19-21: Expected `int` File \"/foo.php\", line 5, characters 25-30: But got `string` /baz.php: File \"/baz.php\", line 4, characters 12-26: Invalid argument (Typing[4110]) File \"/take_int.php\", line 3, characters 19-21: Expected `int` File \"/foo.php\", line 5, characters 25-30: But got `string` " let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4336 allowed_decl_fixme_codes = 4336 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let env = Test.setup_disk env [ (take_int_name, take_int_contents); (foo_name, foo_contents "int"); (foo_child_name, foo_child_contents); (bar_name, bar_contents); (baz_name, baz_contents); ] in let env = Test.connect_persistent_client env in let env = Test.open_file env foo_name in let env = Test.open_file env bar_name in let env = Test.open_file env baz_name in let env = Test.wait env in let (env, _) = Test.(run_loop_once env default_loop_input) in let (env, _) = Test.edit_file env foo_name (foo_contents "string") in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_max_errors.ml
(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = Printf.sprintf "<?hh /* HH_FIXME[4336] */ function foo(): %s { } " let foo_returns_int = foo_contents "int" let foo_returns_string = foo_contents "string" let bar_name = Printf.sprintf "bar%d.php" let bar_contents = Printf.sprintf "<?hh function bar%d (): int { return foo(); } " let baz_name = "baz.php" let baz_contents = "<?hh { " let create_bar i = (bar_name i, bar_contents i) let rec create_bars acc = function | 0 -> acc | i -> create_bars (create_bar i :: acc) (i - 1) let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4336 allowed_decl_fixme_codes = 4336 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let disk_contests = [(foo_name, foo_returns_int)] in let disk_contests = create_bars disk_contests 2 in let env = Test.setup_disk env disk_contests in let env = Test.connect_persistent_client env in let (env, _) = Test.(run_loop_once env default_loop_input) in Test.assert_no_errors env; let (env, loop_output) = Test.status env in Test.assert_error_count loop_output ~expected_count:0; let (env, loop_output) = Test.status ~max_errors:(Some 2) env in Test.assert_error_count loop_output ~expected_count:0; (* Introduce a few errors *) let env = Test.open_file env foo_name ~contents:foo_returns_string in let env = Test.open_file env baz_name ~contents:baz_contents in let env = Test.wait env in let (env, _) = Test.full_check_status env in let (env, loop_output) = Test.status env in Test.assert_error_count loop_output ~expected_count:4; let (env, loop_output) = Test.status ~max_errors:(Some 2) env in Test.assert_error_count loop_output ~expected_count:2; let (env, loop_output) = Test.status env in Test.assert_error_count loop_output ~expected_count:4; ignore env
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_naming_errors.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let test () = let root = "/" in Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set (Filename.concat root ".hhconfig") ""; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let env = Test.connect_persistent_client env in (* Two bar files use `foo` which is still unbound. *) let env = Test.open_file env "bar_expects_int.php" ~contents:"<?hh\nfunction bar_int(): int { return foo(); }\n" in let env = Test.open_file env "bar_expects_string.php" ~contents:"<?hh\nfunction bar_string(): string { return foo(); }\n" in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics loop_outputs (SMap.of_list [ ( "/bar_expects_int.php", SSet.of_list [ "File \"/bar_expects_int.php\", line 2, characters 34-36:\nUnbound name: `foo` (a global function) (Naming[2049])"; "File \"/bar_expects_int.php\", line 2, characters 34-36:\nUnbound name (typing): `foo` (Typing[4107])"; ] ); ( "/bar_expects_string.php", SSet.of_list [ "File \"/bar_expects_string.php\", line 2, characters 40-42:\nUnbound name: `foo` (a global function) (Naming[2049])"; "File \"/bar_expects_string.php\", line 2, characters 40-42:\nUnbound name (typing): `foo` (Typing[4107])"; ] ); ]); (* Now create `foo` in foo_string.php which returns string. *) let env = Test.open_file env "foo_returns_string_name.php" ~contents:"<?hh\nfunction foo() : string { return \"\"; }\n" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output " /bar_expects_int.php: File \"/bar_expects_int.php\", line 2, characters 34-38:\nInvalid return type (Typing[4110]) File \"/bar_expects_int.php\", line 2, characters 21-23:\n Expected `int` File \"/foo_returns_string_name.php\", line 2, characters 18-23:\n But got `string` /bar_expects_string.php: "; (* Create another `foo` in foo_int.php which returns int. *) let env = Test.open_file env "foo_returns_int.php" ~contents:"<?hh\nfunction foo() : int { return 1; }\n" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_in loop_output ~filename:"foo_returns_int.php" " /foo_returns_int.php: File \"/foo_returns_int.php\", line 2, characters 10-12:\nName already bound: `foo` (Naming[2012]) File \"/foo_returns_string_name.php\", line 2, characters 10-12:\n Previous definition is here "; (* Erase foo_string.php. *) let env = Test.open_file env "foo_returns_string_name.php" ~contents:"" in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output " /bar_expects_int.php: /bar_expects_string.php: File \"/bar_expects_string.php\", line 2, characters 40-44:\nInvalid return type (Typing[4110]) File \"/bar_expects_string.php\", line 2, characters 24-29:\n Expected `string` File \"/foo_returns_int.php\", line 2, characters 18-20:\n But got `int` /foo_returns_int.php: "
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_override.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let a_name = "A.php" let a_with_foo_contents = "<?hh // strict interface A { public function foo(): void; } " let a_without_foo_contents = "<?hh // strict interface A { } " let b_name = "B.php" let b_contents = "<?hh // strict abstract class B implements A {} " let c_name = "C.php" let c_contents = "<?hh // strict class C extends B { <<__Override>> public function foo(): void {} } " let c_errors = " File \"/C.php\", line 5, characters 19-21: `C` has no parent class with a method `foo` to override (Typing[4087]) " let c_diagnostics = " /C.php: File \"/C.php\", line 5, characters 19-21: `C` has no parent class with a method `foo` to override (Typing[4087]) " let c_clear_diagnostics = " /C.php: " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [ (a_name, a_with_foo_contents); (b_name, b_contents); (c_name, c_contents); ] in Test.assert_no_errors env; let env = Test.connect_persistent_client env in let env = Test.open_file env a_name ~contents:a_without_foo_contents in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_output; let (env, loop_output) = Test.full_check_status env in Test.assert_env_errors env c_errors; Test.assert_diagnostics_string loop_output c_diagnostics; let (env, _) = Test.edit_file env a_name a_with_foo_contents in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output c_clear_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_remove_function.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_contents = "<?hh // strict function foo() : void {} " let bar_name = "bar.php" let bar_contents = "<?hh // strict function test(): void { foo(); } " let full_diagnostics = " /bar.php: File \"/bar.php\", line 4, characters 3-5: Unbound name (typing): `foo` (Typing[4107]) File \"/bar.php\", line 4, characters 3-5: Unbound name: `foo` (a global function) (Naming[2049]) " let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(foo_name, foo_contents); (bar_name, bar_contents) (* no errors *)] in let env = Test.connect_persistent_client env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_outputs; (* no diagnostics initially *) let env = Test.open_file env foo_name in (* Delete foo() *) let (env, _) = Test.edit_file env foo_name "" in let env = Test.wait env in let (env, loop_outputs) = Test.(run_loop_once env default_loop_input) in (* Change introduces an error in bar.php, but this file is not open in IDE * so we don't recheck it immediately. *) Test.assert_no_diagnostics loop_outputs; (* Asking for global error list will trigger recheck of bar.php *) let (_, loop_outputs) = Test.full_check_status env in Test.assert_diagnostics_string loop_outputs full_diagnostics
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_remove_parent.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_parent_name = "foo_parent.php" let foo_parent_contents = "<?hh // strict class FooParent { public function lol() : void {} } " let foo_name = "foo.php" let foo_contents = "<?hh // strict class Foo extends FooParent { public function test() : void { $this->lol(); } } " let foo_parent_missing_diagnostics : Test.error_messages_per_file = SMap.of_list [ ( "/foo.php", SSet.of_list [ "File \"/foo.php\", line 3, characters 19-27: Unbound name: `FooParent` (an object type) (Naming[2049])"; "File \"/foo.php\", line 5, characters 12-14: No instance method `lol` in `Foo` (Typing[4053]) File \"/foo.php\", line 4, characters 19-22: Did you mean `test` instead? File \"/foo.php\", line 3, characters 7-9: This is why I think it is an object of type Foo File \"/foo.php\", line 3, characters 7-9: Declaration of `Foo` is here"; ] ); ] let clear_foo_diagnostics = " /foo.php: " let test () = let env = Test.setup_server () in let env = Test.connect_persistent_client env in let env = Test.open_file env foo_parent_name ~contents:foo_parent_contents in let env = Test.open_file env foo_name ~contents:foo_contents in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_no_diagnostics loop_output; let (env, _) = Test.edit_file env foo_parent_name "" in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics loop_output foo_parent_missing_diagnostics; let (env, _) = Test.edit_file env foo_parent_name foo_parent_contents in let env = Test.wait env in let (env, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics_string loop_output clear_foo_diagnostics; let (env, _) = Test.edit_file env foo_parent_name "" in let env = Test.wait env in let (_, loop_output) = Test.(run_loop_once env default_loop_input) in Test.assert_diagnostics loop_output foo_parent_missing_diagnostics; ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_status_single.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) open Integration_test_base_types module Test = Integration_test_base let foo_name = "foo.php" let bar_name = "bar.php" let baz_name = "baz.php" let foo_contents = {|<?hh //strict function foo(): int { /* HH_FIXME[4110] */ return "4"; } |} let bar_contents = {|<?hh function bar(): int { return "4"; } |} let baz_contents = {|<?hh function baz(): bool { return "4"; } |} let bar_error = {| /bar.php: File "/bar.php", line 3, characters 10-12: Invalid return type (Typing[4110]) File "/bar.php", line 2, characters 17-19: Expected `int` File "/bar.php", line 3, characters 10-12: But got `string` |} let baz_error = {| /baz.php: File "/baz.php", line 3, characters 10-12: Invalid return type (Typing[4110]) File "/baz.php", line 2, characters 17-20: Expected `bool` File "/baz.php", line 3, characters 10-12: But got `string` |} let status_single_request_foo = ServerCommandTypes.( STATUS_SINGLE { file_names = [FileName "/foo.php"]; max_errors = None }) let check_status_single_response_foo = function | None -> Test.fail "Expected STATUS_SINGLE response" | Some ([], _) -> () | Some _ -> Test.fail "Expected no errors" let status_single_request_bar_and_baz = ServerCommandTypes.( STATUS_SINGLE { file_names = [FileName "/bar.php"; FileName "/baz.php"]; max_errors = None; }) let check_status_single_response_bar_and_baz loop_outputs = Test.assert_diagnostics_in loop_outputs ~filename:bar_name bar_error; Test.assert_diagnostics_in loop_outputs ~filename:baz_name baz_error let root = "/" let hhconfig_filename = Filename.concat root ".hhconfig" let hhconfig_contents = " allowed_fixme_codes_strict = 4110 " let test () = Relative_path.set_path_prefix Relative_path.Root (Path.make root); TestDisk.set hhconfig_filename hhconfig_contents; let options = ServerArgs.default_options ~root in let (custom_config, _) = ServerConfig.load ~silent:false options in let env = Test.setup_server ~custom_config () in let env = Test.setup_disk env [(foo_name, foo_contents)] in let env = Test.connect_persistent_client env in Test.assert_no_errors env; let (env, loop_output) = Test.( run_loop_once env { default_loop_input with new_client = Some (RequestResponse status_single_request_foo); }) in check_status_single_response_foo loop_output.new_client_response; let env = Test.open_file env bar_name ~contents:bar_contents in let env = Test.open_file env baz_name ~contents:baz_contents in let env = Test.wait env in let (env, loop_output) = Test.( run_loop_once env { default_loop_input with new_client = Some (RequestResponse status_single_request_bar_and_baz); }) in check_status_single_response_bar_and_baz loop_output; ignore env; ()
OCaml
hhvm/hphp/hack/test/integration_ml/ide/test_unsaved_changes.ml
(* * Copyright (c) 2017, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * *) module Test = Integration_test_base let foo_name = "foo.php" let foo_takes_int_contents = "<?hh // strict function foo(int $x) : void {} " let foo_takes_string_contents = "<?hh // strict function foo(string $x) : void {} " let bar_name = "bar.php" let bar_contents = "<?hh // strict function test(mixed $x): void { foo($x); } " let disk_diagnostics = {| File "/bar.php", line 4, characters 7-8: Invalid argument (Typing[4110]) File "/foo.php", line 3, characters 14-16: Expected `int` File "/bar.php", line 3, characters 15-19: But got `mixed` |} let ide_diagnostics = {| File "/bar.php", line 4, characters 7-8: Invalid argument (Typing[4110]) File "/foo.php", line 3, characters 14-19: Expected `string` File "/bar.php", line 3, characters 15-19: But got `mixed` |} let test () = let env = Test.setup_server () in let env = Test.setup_disk env [(bar_name, bar_contents); (foo_name, foo_takes_int_contents)] in let (env, loop_output) = Test.status env in Test.assert_status loop_output disk_diagnostics; let env = Test.connect_persistent_client env in let env = Test.open_file env foo_name ~contents:foo_takes_string_contents in let (env, _) = Test.full_check_status env in let (env, loop_output) = Test.status env in Test.assert_status loop_output ide_diagnostics; let (env, loop_output) = Test.status ~ignore_ide:true env in Test.assert_status loop_output disk_diagnostics; let (env, _) = Test.full_check_status env in let (env, loop_output) = Test.status ~ignore_ide:false env in Test.assert_status loop_output ide_diagnostics; ignore env
PHP
hhvm/hphp/hack/test/json/run_json_on_file.php
<?hh // @format function run_json_on_file(bool $x): void { if ($x == true) { return; } //should provide quickfixes } function run_json_on_file_example_2(bool $x): void { if (true == $x) { return; } //should provide quickfixes } function run_json_on_file_example_1_false(bool $x): void { if ($x === false) { return; } //should provide quickfixes } function run_json_on_file_example_2_false(bool $x): void { if (false === $x) { return; } //should provide quickfixes }
PHP
hhvm/hphp/hack/test/json/test_missing_override.php
<?hh class MyParent { public function foo(): void {} } class MyChild extends MyParent { public function foo(): void {} }
PHP
hhvm/hphp/hack/test/json/test_missing_override_existing_attribute.php
<?hh class MyParent { <<__Memoize>> public function foo(): void {} } class MyChild extends MyParent { <<__Memoize>> public function foo(): void {} }
PHP
hhvm/hphp/hack/test/json/test_quickfix_lint_code_5644.php
<?hh function foo1(int $x): void { if ($x > 3 && true) { return; } //should provide quickfixes } function foo2(int $x): void { if (true || $x > 3) { return; } //should provide quickfixes } function foo3(int $x): void { if ($x > 3 && true || $x < 2) { return; } //should provide quickfixes } function foo4(int $x): void { if ($x > 3 || $x < 2 && $x > 3 || false || $x < 2 && $x < 4) { return; } //should provide quickfixes }
PHP
hhvm/hphp/hack/test/json/test_quickfix_redundant_unsafe_cast.php
<?hh function takes_arraykey(arraykey $_) : void {} function redundant_cast(int $x): void { takes_arraykey(HH\FIXME\UNSAFE_CAST<mixed, arraykey>($x)); } function useful_but_loose_cast(?int $x): void { takes_arraykey(HH\FIXME\UNSAFE_CAST<mixed,arraykey>($x)); } function useful_and_accurate_cast(?int $x): void { takes_arraykey(HH\FIXME\UNSAFE_CAST<?int,arraykey>($x)); }
PHP
hhvm/hphp/hack/test/json/test_quickfix_unsafe_cast.php
<?hh function nullable_str(): ?string { return null; } function demo(): void { $_ = HH\FIXME\UNSAFE_CAST<mixed, string>(nullable_str()); }
PHP
hhvm/hphp/hack/test/lint/accidental_null_as_nonnull.php
<?hh function accidental_null_as_nonnull(shape(?'name' => string) $s): void { $s['name'] ?? null as nonnull }
PHP
hhvm/hphp/hack/test/lint/array_sgrep.php
<?hh function test() { array_merge(FOO); array_replace($X, FOO); array_push(Xxx, Yyy); head_UNTYPED(array_values(Xxx)); head_UNTYPED(array_keys(Xxx)); array_create_set_from_values(array_keys(Xxx)); idx(Xxx, Yyy, null); } function test_syntax() { $x = X + Y; $y = $x + varray[Y]; $x = array_concat($x, Y); $X = array_concat($x, Y); $X = array_merge_by_key($X, Y); } function test2() { first(array_values(Xxx)); firstx(array_values(Xxx)); first(array_keys(Xxx)); firstx(array_keys(Xxx)); }
PHP
hhvm/hphp/hack/test/lint/async_lambda_bad.php
<?hh async function async_lambda_bad1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], $x ==> async_lambda_bad1($x), ); } async function async_lambda_bad2(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], $x ==> { return async_lambda_bad2($x); }, ); } async function async_lambda_bad3(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], function($x) { return async_lambda_bad3($x); } ); }
PHP
hhvm/hphp/hack/test/lint/async_lambda_good.php
<?hh async function async_lambda_good1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async $x ==> await async_lambda_good1($x), ); } async function async_lambda_good2(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async $x ==> async_lambda_good2($x), ); } async function async_lambda_good3(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async $x ==> { return await async_lambda_good3($x); }, ); } function async_lambda_good4(int $x): void { $_ = HH\Lib\Vec\map( vec[], $x ==> async_lambda_good4($x), ); } async function async_lambda_good5(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async function($x) { return await async_lambda_good5($x); } ); }
PHP
hhvm/hphp/hack/test/lint/as_always_succeeds1.php
<?hh abstract class A { public function f(): void {} } class B extends A {} function test(B $b): void { $b as A; }
PHP
hhvm/hphp/hack/test/lint/as_invalid_type.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. enum HackAsInvalidTypeStringEnum: string { VALUE = 'zero'; } final class HackAsWithInvalidTypeLintRuleTest { private static function bool(): bool { return false; } private static function int(): int { return 0; } private static function string(): string { return "0"; } private static function float(): float { return 0.0; } private static function arraykey(): arraykey { return "0"; } private static function num(): num { return 0; } private static function mixed(): mixed { return false; } private static function nullable<T>(T $thing): ?T { return $thing; } private static function null(): null { return null; } private static function stringEnum(): HackAsInvalidTypeStringEnum { return HackAsInvalidTypeStringEnum::VALUE; } public static function foo(): void { $_ = self::int() as bool; // error, never succeeds $_ = self::bool() as bool; // error, always succeeds $_ = self::float() as num; // error, always succeeds $_ = self::num() as float; $_ = self::float() as int; // error, never succeeds $_ = self::arraykey() as num; $_ = self::string() as arraykey; // error, always succeeds $_ = self::string() as int; // error, never succeeds $_ = self::mixed() as int; $_ = self::int() as mixed; // error, always succeeds $_ = self::nullable(self::string()) as arraykey; $_ = self::nullable(self::string()) as ?string; // error, always succeeds $_ = self::nullable(self::string()) as ?int; $_ = self::stringEnum() as string; $_ = self::stringEnum() as ?string; $_ = self::stringEnum() as int; $_ = self::null() as mixed; // error, always succeeds $_ = self::null() as null; // error, always succeeds $_ = self::null() as ?int; // error, always succeeds $_ = self::nullable(self::int()) as null; $_ = self::null() as int; // error, always succeeds $_ = self::int() as null; // error, never succeeds } }
PHP
hhvm/hphp/hack/test/lint/as_valid_type_with_opaque_alias.php
//// my_alias.php <?hh newtype MyIntID_of = int; //// use_it.php <?hh function foo(?MyIntID_of $x): void { // Might throw, might not. The lint shouldn't fire here, because we // only report unconditional throw situations. $x as int; }
PHP
hhvm/hphp/hack/test/lint/awaitable_awaitable_bad.php
<?hh async function awaitable_awaitable_bad1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], // should not trigger ASYNC_AWAIT_LAMBDA, but should trigger AWAITABLE_AWAITABLE async $x ==> awaitable_awaitable_bad1($x), // should trigger rule ); } async function awaitable_awaitable_bad2(int $x): Awaitable<void> { $f = async (int $x, int $y) ==> awaitable_awaitable_bad2($x + $y); $_ = await $f(0, 0); }
PHP
hhvm/hphp/hack/test/lint/awaitable_awaitable_good.php
<?hh async function awaitable_awaitable_good1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async $x ==> await awaitable_awaitable_good1($x), // should not trigger rule ); } async function awaitable_awaitable_good2(int $x): Awaitable<void> { // annotated inline lambda, should not trigger rule $_ = await HH\Lib\Vec\map_async( vec[], async ($x): Awaitable<Awaitable<void>> ==> awaitable_awaitable_good2($x), ); } async function awaitable_awaitable_good3(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], // no nested Awaitable here $x ==> { return awaitable_awaitable_good3($x); }, ); } async function gen_map<Ta, Tb>( Traversable<Ta> $_, (function(Ta): Awaitable<Tb>) $_, ): Awaitable<Vector<Tb>> { return Vector {}; } async function awaitable_awaitable_good4(int $x): Awaitable<void> { // compound lambda with Awaitable<T>, should not trigger rule $candidate_ids = vec[1, 2, 3, 4, 5]; $_ = await gen_map( $candidate_ids, async ($candidate_id) ==> { return Pair {$candidate_id, 0.0}; }, ); } async function awaitable_awaitable_good5(int $x): Awaitable<void> { // annotated compound lambda, should not trigger rule $f = async (int $x): Awaitable<Awaitable<void>> ==> { $y = 1; if ($x === 2) { return awaitable_awaitable_good5($x); } else { return awaitable_awaitable_good5($x + $y); } }; $_ = await $f(0); }
PHP
hhvm/hphp/hack/test/lint/await_as_an_expression.php
<?hh async function await_as_an_expression(): Awaitable<int> { $gen1 = async { return 42; }; $gen2 = async { return 42; }; $x = (await async { return 42; }) + (await $gen1); $y = (await async { return 42; }) + (await async { return 42; }); return $x; }
PHP
hhvm/hphp/hack/test/lint/await_in_loop.php
<?hh async function await_in_loop($k, $n) { foreach ($k as $v) { await $v; } $test_array = varray[]; foreach ($k as $v) { $test_array[] = await $v; } while (true) { await $n; } if (true) { await $n; } while (true) { if (true) { await $n; } } } async function loop_in_async_block($n) { return await async { while (true) { await $n; } }; } async function loop_in_async_block_in_loop($k, $n) { $blocks = vec[]; foreach ($k as $v) { $blocks[] = async { while (true) { await $v; } }; } return await Vec\gen($blocks); } // Negative examples below async function async_blocks_in_loop($k, $n) { $blocks = vec[]; foreach ($k as $v) { $blocks[] = async { await $v; await $v; // Make sure the linter doesn't trip over multiple awaits }; } foreach ($k await as $v) { await $v; } return await Vec\gen($blocks); } // Negative examples for named functions with awaits async function async_fun_helper($v) { return await $v; } async function named_async_fun_blocks_in_loop($k, $n) { $blocks = vec[]; foreach ($k as $v) { $blocks[] = async_fun_helper($v); } return await Vec\gen($blocks); } // Negative example for a looped synchronous function call with an await // We might want this to be a positive case? function sync_fun_helper($v) { return await $v; } async function named_blocking_fun_in_loop($k) { foreach ($k as $v) { sync_fun_helper($v); } }
PHP
hhvm/hphp/hack/test/lint/basic_sgrep.php
<?hh function test() { if (foo() && bar()) { // Empty if should be flagged. } if (foo() && bar()) { print("foo") } else { // Empty else should be flagged. } if ($x == null) { print("This should be flagged"); } if ($x != null) { print("This should be flagged"); } if ($x === null) { print("This should not be flagged"); } if (!$x) { print("This should be flagged"); } } function empty_isset_test($y) { $y = isset($x); }
PHP
hhvm/hphp/hack/test/lint/bool_literal_eq_in_if_condition.php
<?hh function check1(bool $x): int { if ($x == true) { return 1; } } function check2(bool $y): int { if ($y == false) { return 2; } } function check3(bool $x): int { if (true == $x) { return 2; } } function check4(bool $x): int { if (false == $x) { return 2; } } function check5(bool $y): int { if ($y === true) { return 1; } } function check6(bool $x): int { if ($x === false) { return 2; } } function check7(bool $x): int { if (true === $x) { return 2; } } function check8(bool $x): int { if (false === $x) { return 2; } } function check9(bool $x): int { if (($x > 1) === true) { return 1; } } function check10(mixed $x): int { if ($x == true) { return 1; } } function check11(bool $x, int $i): int { while ($x == true) { $i++; } } function check12(bool $x, int $i): int { do { $i++; } while ($x == false); } function check13(bool $x, int $i): int { for ($j = 0; $x == true; ++$j) { $i++; } } function check14(bool $x, bool $y, int $i): int { $y = $x === true; } function check15(bool $x, bool $y, int $i): int { foo($x === true); }
PHP
hhvm/hphp/hack/test/lint/bool_method.php
<?hh class Foo { public function __bool(): void {} } // A second definition to silence the lint about the name of files // with a single definition. function bar(): void {}
PHP
hhvm/hphp/hack/test/lint/branches_returning_same_success.php
<?hh enum MyExitCode: int { SUCCESS = 0; FAILURE = 1; } function main_function_early_terminate(): int { if (1 === 1) { return 0; } return 0; } function main_function_early_terminate_enum(): int { if (1 === 1) { return MyExitCode::SUCCESS; } return MyExitCode::SUCCESS; }
PHP
hhvm/hphp/hack/test/lint/branches_returning_same_value.php
<?hh const int global_const = 1; enum DebugFlag: int { ON = 1; OFF = 0; } //function tests function return_same_int(bool $x): int { if ($x) { return 123; } else { return 123; //should produce lint } } function return_same_string(bool $x): string { if ($x) { return "hello"; } else { return "hello"; //should produce lint } } function return_same_float(bool $x): float { if ($x) { return 1.5; } else { return 1.5; //should produce lint } } function return_same_bool(bool $x): bool { if ($x) { $y = 2; return true; } else { $y = 3; return true; //should produce lint } } function return_same_global_constant(bool $x): int { if ($x) { return global_const; } else { return global_const; //should produce lint } } function return_same_enum_constant(bool $x): DebugFlag { if ($x) { return DebugFlag::ON; } else { return DebugFlag::ON; //should produce lint } } function return_same_function_call(bool $x): int { if ($x) { return return_different_string($x); } else { return return_different_string($x); // should not produce lint } } function return_different_enum_constant(bool $x): DebugFlag { if ($x) { return DebugFlag::ON; } else { return DebugFlag::OFF; //should not produce lint } } function return_different_float(bool $x): float { if ($x) { return 1.0; } else { return 1.5; //should not produce lint } } function return_different_string(bool $x): string { if ($x) { return "hello1"; } else { return "hello2"; //should not produce lint } } function return_while(bool $x): int { while ($x) { return 123; } return 123; } function return_same_string_else_if(bool $x): string { if ($x) { return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should produce lint } } function return_different_string_else_if(bool $x): string { if ($x) { $y = 2; return "hello1"; } else if (!$x) { return "hello"; } else { $y = 3; return "hello1"; //should not produce lint } } function return_string_lambda_efun(string $x, bool $y): string { if ($y) { $y = 2; return "hello"; } $lambda = function($x) { return "different"; }; return "hello"; //should produce lint } function return_string_lambda_lfun(string $x, bool $y): string { if ($y) { $y = 2; return "hello"; } $lambda = ($x) ==> { return "different"; }; return "hello"; //should produce lint } function return_same_string_nested_if(bool $x): string { if ($x) { if ($x) { return "hello"; } return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should produce lint } } function return_different_string_nested_if(bool $x): string { if ($x) { if ($x) { return "hello1"; } return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should not produce lint } } //method tests class Foo { public function returnSameInt(bool $x): int { if ($x) { return 123; } else { return 123; //should produce lint } } public function returnSameString(bool $x): string { if ($x) { return "hello"; } else { return "hello"; //should produce lint } } public function returnSameFloat(bool $x): float { if ($x) { return 1.5; } else { return 1.5; //should produce lint } } public function returnSameBool(bool $x): bool { if ($x) { $y = 2; return true; } else { $y = 3; return true; //should produce lint } } public function returnSameGlobalConstant(bool $x): int { if ($x) { return global_const; } else { return global_const; //should produce lint } } public function returnSameEnumConstant(bool $x): DebugFlag { if ($x) { return DebugFlag::ON; } else { return DebugFlag::ON; //should produce lint } } function returnSameFunctionCall(bool $x): int { if ($x) { return this->returnDifferentString($x); } else { return this->returnDifferentString($x); // should not produce lint } } public function returnDifferentEnumConstant(bool $x): DebugFlag { if ($x) { return DebugFlag::ON; } else { return DebugFlag::OFF; //should not produce lint } } public function returnDifferentFloat(bool $x): float { if ($x) { return 1.0; } else { return 1.5; //should not produce lint } } public function returnDifferentString(bool $x): string { if ($x) { return "hello1"; } else { return "hello2"; //should not produce lint } } public function returnSameStringElseIf(bool $x): string { if ($x) { return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should produce lint } } public function returnDifferentStringElseIf(bool $x): string { if ($x) { $y = 2; return "hello1"; } else if (!$x) { return "hello"; } else { $y = 3; return "hello1"; //should not produce lint } } public function returnStringLambdaEfun(string $x, bool $y): string { if ($y) { $y = 2; return "hello"; } $lambda = function($x) { return "different"; }; return "hello"; //should produce lint } public function returnStringLambdaLfun(string $x, bool $y): string { if ($y) { $y = 2; return "hello"; } $lambda = ($x) ==> { return "different"; }; return "hello"; //should produce lint } public function returnWhile(bool $x): int { while ($x) { return 123; } return 123; } public function returnSameStringNestedIf(bool $x): string { if ($x) { if ($x) { return "hello"; } return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should produce lint } } public function returnDifferentStringNestedIf(bool $x): string { if ($x) { if ($x) { return "hello1"; } return "hello"; } else if (!$x) { return "hello"; } else { return "hello"; //should not produce lint } } }
PHP
hhvm/hphp/hack/test/lint/cast_non_primitive_bad.php
<?hh final class C {} final class D {} final class E {} final class F {} function cast_non_primitive_bad1(): void { (int) (Vector {}); } function cast_non_primitive_bad2(): void { (int) (vec[]); } function cast_non_primitive_bad3(): void { (int) (new C()); } function test_non_primitive_bad4(bool $test): void { if ($test) { $x = 'test'; } else { $x = vec[]; } (int) $x; } function test_non_primitive_bad5(bool $test): void { if ($test) { $x = 'test'; } else { $x = new C(); } (int) $x; } function cast_non_primitive_bad6(bool $test): void { if ($test) { $x = vec[]; } else { $x = new C(); } (int) $x; } function cast_non_primitive_bad7(Stringish $test): void { (int) $test; } function cast_non_primitive_bad8( bool $test1, bool $test2, bool $test3, ): void { if ($test1) { $a = new C(); } else { $a = new D(); } if ($test2) { $b = new E(); } else { $b = new F(); } if ($test3) { $c = $a; } else { $c = $b; } (int) $c; } function cast_non_primitive_bad9( vec<string> $vec, dict<string, string> $dict, keyset<string> $keyset, vec<string> $varray, dict<string, string> $darray, vec_or_dict<string> $varray_or_darray, ): void { (int)$vec; (int)$dict; (int)$keyset; (int)$varray; (int)$darray; (int)$varray_or_darray; }
PHP
hhvm/hphp/hack/test/lint/cast_non_primitive_good.php
//// a.php newtype SomeNewtype = int; //// b.php <?hh function cast_non_primitive_good1(): void { (string) 7; } function cast_non_primitive_good2(?string $bar): void { (int) $bar; } function cast_non_primitive_good3(bool $test): void { if ($test) { $x = 'test'; } else { $x = false; } (string) $x; } enum E : int { A = 42; } function cast_non_primitive_good4(E $e): void { (string) $e; (int) E::A; } function cast_non_primitive_good5(): void { (string) idx(dict[], 'banana'); } function cast_non_primitive_good6(SomeNewtype $x): void { (string) $x; } function cast_non_primitive_good7(mixed $test): void { (string) $test; } function cast_non_primitive_good8(mixed $test): void { (string) idx($test as KeyedContainer<_, _>, 'banana'); } function cast_non_primitive_good9( bool $test1, bool $test2, bool $test3, ): void { if ($test1) { $a = 'a'; } else { $a = false; } if ($test2) { $b = 12; } else { $b = 12.4; } if ($test3) { $c = $a; } else { $c = $b; } (int)$c; } function cast_non_primitive_good10_helper(): dict<string, mixed> { return dict[]; } function cast_non_primitive_good10(): ?string { return (string) idx(cast_non_primitive_good10_helper(), 'foo'); } function cast_non_primitive_good11( HH\FormatString<Str\SprintfFormat> $x, ): void { (string) $x; } function cast_non_primitive_good12( vec<string> $vec, dict<string, string> $dict, keyset<string> $keyset, vec<string> $varray, dict<string, string> $darray, vec_or_dict<string> $varray_or_darray, ): void { (bool) $vec; (bool) $dict; (bool) $keyset; (bool) $varray; (bool) $darray; (bool) $varray_or_darray; }
PHP
hhvm/hphp/hack/test/lint/cast_non_primitive_ugly.php
<?hh // This file is for the test cases of the non-primitive cast linter where there // should be a lint but doing so would lead to too much noise. It would be // desirable to eventually start producing lints for the test cases in this // file. function cast_non_primitive_ugly1<<<__Explicit>> T>(T $t): void { (int) $t; } function cast_non_primitive_ugly2(dynamic $dyn): void { (int) $dyn; } function cast_non_primitive_ugly3(mixed $m): void { (int) $m; } abstract class AC { abstract const type TRet; abstract public function make(): this::TRet; } function cast(AC $obj): void { (int) $obj->make(); }
PHP
hhvm/hphp/hack/test/lint/classname_sgrep.php
<?hh function test($y, $fd) { Classes::get('clazz', $y); $fd->enumeration(A, B, 'clazz', $y); new EnumParam('clazz'); new EnumValueParam('clazz'); }
PHP
hhvm/hphp/hack/test/lint/class_overrides_trait_methods_abstract_ok.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait MyTrait { abstract public function foo(): int; abstract static public function bar(): int; } class MyClass { use MyTrait; <<__Override>> public function foo(): int { return 2; } <<__Override>> static public function bar(): int { return 2; } }
PHP
hhvm/hphp/hack/test/lint/class_overrides_trait_methods_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait MyTrait2 { static public function bar(): int { return 1; } } trait MyTrait { use MyTrait2; public function foo(): int { return 1; } } class MyClass { use MyTrait; <<__Override>> public function foo(): int { return 2; } <<__Override>> static public function bar(): int { return 2; } }
PHP
hhvm/hphp/hack/test/lint/class_overrides_trait_properties_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait MyTrait2 { public int $bar = 1; } trait MyTrait { use MyTrait2; public static int $foo = 1; } class MyClass { use MyTrait; public static int $foo = 1; public int $bar = 1; }
PHP
hhvm/hphp/hack/test/lint/cleanup_sgrep.php
<?hh function test($x, $y) { $_ = await $x ? Y : null; $_ = await $x ? null : $y; $_ = await $x ?: null; await $x ? $y : null; await $x ? null : $y; await $x ?: null; // Note: invariant is automatically rewritten to invariant_violation invariant(false, $y); }
PHP
hhvm/hphp/hack/test/lint/clone_usage.php
<?hh class CloneUsageTest { public function test(): void { $x = Vector {}; $y = clone $x; $y->add(3); } }
PHP
hhvm/hphp/hack/test/lint/collections_sgrep.php
<?hh function test() { new Vector(null); new Map(null); new Set(null); new ImmVector(null); new ImmMap(null); new ImmSet(null); new Vector(varray[]); new Map(varray[]); new Set(varray[]); new ImmVector(varray[]); new ImmMap(varray[]); new ImmSet(varray[]); new Set(array_keys(X)); new Vector(array_keys(X)); new Set(array_values(X)); new Vector(array_values(X)); new Map(); new Set(); new Vector(); new ImmMap(); new ImmSet(); new ImmVector(); }
PHP
hhvm/hphp/hack/test/lint/concurrent_fn.php
<?hh async function concurrent_fn(): Awaitable<int> { $gen1 = async { return 42; }; $gen2 = async { return 42; }; concurrent { $x = await async { return 42; }; $y = await $gen1; await async {}; } return $y; }
PHP
hhvm/hphp/hack/test/lint/csprintf_argument_unpacking.php
<?hh function test(string $_cmd){ $_test = csprintf("test %S", "abc123"); $_test = csprintf( "extremely long string that the 80-cols linter will complain about". " therefore I decided to split into the concatenation of constant". " strings", ); }
PHP
hhvm/hphp/hack/test/lint/dead_statement.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. final class TestUnreachableCode { public function testContinue(): void { for($i = 0; $i < 100; $i++) { continue; echo 'O Romeo, Romeo! wherefore art thou Romeo?'; } } public function testReturn(): string { echo 'If music be the food of love, play on,'. 'Give me excess of it; that surfeiting,'. 'The appetite may sicken, and so die.'; return 'He said, in a low tremulous voice...'; echo 'This is never reached, the farthest distance in the world.'; } public function testYield(string $input): Generator<int, string, void> { yield break; yield 'is when I have laptop, but no Wifi connection'; // unreached } public function testSwitch(int $i): string { switch ($i) { case 1: $t = 'hello'; return 'WoRlD iN LaTeX'; // FALLTHROUGH -- this is a Hack annotation default: $t = 'i is unknown'; break; } return $t; } } function unreachable_function(): string { return "I had a lover's quarrel with the world"; } function test_unreachable_function(): string { return "Remember: all I'm offering is the truth. Nothing more."; echo unreachable_function(); } function test_unreachable_if(): string { if (false) { return "Unreachable"; } else { return "OK"; } } function test_unreachable_else(): string { if (true) { return "OK"; } else { return "Unreachable"; } } function test_unreachable_if_with_nop(): string { if (false) { // Lint warning } else { return "OK"; } } function test_unreachable_else_with_nop(): string { if (true) { return "OK"; } else { // Lint warning } } function test_unreachable_after_if_true(): string { if (true) { return "OK"; } return "Unreachable"; } function test_unreachable_after_join_1(): string { if (HH\Lib\PseudoRandom\int(0,10) === 1) { echo "Option 1"; } else { return "Option 2"; } return "OK"; } function test_unreachable_after_join_2(): string { if (HH\Lib\PseudoRandom\int(0,10) === 1) { return "Option 1"; } else { echo "Option 2"; } return "OK"; } function test_unreachable_after_join_3(): string { if (HH\Lib\PseudoRandom\int(0,10) === 1) { return "Option 1"; } else { return "Option 2"; } return "Unreachable"; } function test_unreachable_echo_1(): string { if (false) { echo "Unreachable"; } return "OK"; } function test_unreachable_echo_2(): string { if (true) { echo "OK"; } return "OK"; }
PHP
hhvm/hphp/hack/test/lint/diamond_properties_enum_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. // HHVM fatals because it cannot prove that $x, inherited via two different // paths, is always initialised to 1. enum E : int as int { V = 1; } trait T0 { public int $x = E::V+1; } trait T1 { use T0; } class C { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/diamond_properties_enum_good.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. // HHVM fatals because it cannot prove that $x, inherited via two different // paths, is always initialised to 1. enum E : int as int { V = 1; } trait T0 { public int $x = E::V; } class C { use T0; } trait T1 { require extends C; } class D extends C { use T1; }
PHP
hhvm/hphp/hack/test/lint/disjoint_equality_newtype.php
////main.php <?hh function good(NTIntA $a, NTIntB $b): void { if ($a === $b) { echo 'can happen'; } } function bad(NTIntA $a, NTStringB $b): void { if ($a === $b) { echo 'cannot happen'; } } ////a.php <?hh newtype NTIntA = int; ////b.php <?hh newtype NTStringB = string; newtype NTIntB = int;
hhvm/hphp/hack/test/lint/dune
(rule (alias lint) (deps %{exe:../../src/hh_single_type_check.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh %{project_root}/hack/test/hhi/XHPTest.hhi (glob_files %{project_root}/hack/test/lint/HH_FLAGS) (glob_files %{project_root}/hack/test/lint/*.php) (glob_files %{project_root}/hack/test/lint/*.exp) (glob_files %{project_root}/hack/test/lint/error_formatting_highlighted/*.php) (glob_files %{project_root}/hack/test/lint/error_formatting_highlighted/*.exp) (glob_files %{project_root}/hack/test/lint/error_formatting_highlighted/HH_FLAGS)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/lint --program %{exe:../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias lint)))
PHP
hhvm/hphp/hack/test/lint/duplicated_properties_enum_2_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. enum E : int as int { V = 1; } trait T0 { public int $x = E::V; } trait T1 { public int $x = E::V; } trait T2 { public int $x = 1; } trait T3 { public int $x = 1; } class C { use T0; use T1; use T2; use T3; }
PHP
hhvm/hphp/hack/test/lint/duplicated_properties_enum_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. enum E : int as int { V = 1; } trait T0 { public int $x = E::V; } trait T1 { public int $x = E::V; } class C { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/duplicated_properties_enum_good.php
<?hh enum E : string as string { FOO = 'foo'; } abstract class A { protected E $x = E::FOO; } abstract class B extends A {} trait T0 { require extends A; } trait T1 { require extends A; } class C extends B { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/duplicated_properties_enum_good_2.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. enum E : string as string { FOO = 'foo'; } abstract class A { protected E $x = E::FOO; } trait T0 { require extends A; } class C extends A { use T0; }
PHP
hhvm/hphp/hack/test/lint/duplicate_key.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function f1(): array<string, int> { return darray[ 'a' => 1, 'b' => 2, ]; } function f2(): array<string, int> { return darray[ 'a' => 1, 'a' => 2, ]; } function f3(): Map<string, int> { return Map { 'p' => 1, 'q' => 2, 'r' => 3, }; } function f4(): Map<string, int> { return Map { 'p' => 1, 'p' => 2, 'p' => 3, }; } function f5(): ImmMap<string, int> { return ImmMap { 'x' => 1, 'y' => 2, 'z' => 3, }; } function f6(): ImmMap<string, int> { return ImmMap { 'x' => 1, 'x' => 2, 'x' => 3, }; }
PHP
hhvm/hphp/hack/test/lint/duplicate_properties_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait T0 { public int $y; public int $z; } trait T1 { use T0; public int $x = 3; public int $y; } trait T2 { public int $x = 2+1; } class C { use T1; use T2; public int $z = 3; }
PHP
hhvm/hphp/hack/test/lint/duplicate_properties_class_constant_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class D { const int V = 1; } trait T0 { public int $x = D::V; } trait T1 { public int $x = D::V; } class C { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/duplicate_properties_class_name_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class D { } trait T0 { public int $x = D::class; } trait T1 { public int $x = D::class; } class C { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/duplicate_properties_class_name_good.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class D { } trait T0 { public int $x = D::class; } trait T1 { use T0; } class C { use T0; use T1; }
PHP
hhvm/hphp/hack/test/lint/duplicate_properties_diamond_good.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait T0 { public int $y; } trait T1 { use T0; } class C { use T1; use T2; }
PHP
hhvm/hphp/hack/test/lint/empty_if.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function empty_if(): void { $foo = true; if ($foo) {} }
PHP
hhvm/hphp/hack/test/lint/enum.php
<?hh // strict class TestStringEnum extends Enum<string> { const A = 'A'; } class TestIntEnum extends Enum<int> { const ONE = 1; } class TestStringApiEnum extends ApiEnum<string> { const A = 'A'; } class TestIntApiEnum extends ApiEnum<int> { const ONE = 1; } class TestRootClass { } class TestSubclassingOtherClass extends TestRootClass { } enum TestModernEnumString: string { A = 'A'; } enum TestModernEnumInt: int { ONE = 1; }
PHP
hhvm/hphp/hack/test/lint/expression_tree.php
<?hh function foo(): void { $x = ExampleDsl`() ==> { $x = 1; if (true) { $x = 2; } }`; } function bar(): void {}
PHP
hhvm/hphp/hack/test/lint/foreach_shadow.php
<?hh function f1(vec<int> $xs): int { $x = 0; foreach ($xs as $x) { $x++; } return $x; } function f2(vec<int> $xs): int { $x = 1; $x = $x - 1; foreach ($xs as $x) { $x++; } return $x; } function f3(dict<int, int> $xs): int { $x = 0; foreach ($xs as $x => $_) { $x++; } return $x; } function f4(dict<int, int> $xs): int { $x = 0; foreach ($xs as $_ => $x) { $x++; } return $x; } function f5(dict<int, (int, int)> $xs): int { $x = 0; foreach ($xs as $_ => list($x, $_)) { $x++; } return $x; } function f6(vec<int> $xs): int { $x = 0; if (true) { foreach ($xs as $x) { $x++; } } return $x; } function f7(vec<vec<int>> $xss): int { $s = 0; foreach ($xss as $xs) { $x = 0; foreach ($xs as $x) { $x++; } $s += $x; } return $x; } function f8(vec<int> $xs): vec<(int, int)> { $result = vec[]; foreach ($xs as $x) { $x1 = $x; foreach ($xs as $x) { $x2 = $x; $result[] = tuple($x1, $x2); } } return $result; } function f9(vec<int> $xs): int { list($x, $_) = vec[0, 0]; foreach ($xs as $x) { $x++; } return $x; } function f10(vec<int> $xs): int { $s = 0; try { throw new Exception(); } catch (Exception $x) { echo $x->getMessage(); foreach ($xs as $x) { $s += $x; } } return $s; } function f11(vec<int> $xs): int { $s = 0; // The loop variable $x doesn't shadow $x defined after the loop. foreach ($xs as $x) { $s += $x; } $x = 0; $s += $x; return $s; } function f12(vec<int> $xs): int { if (1 === 2) { $x = 0; $s = $x; } else { $s = 0; // The loop variable $x doesn't shadow $x defined in the other // branch of if. foreach ($xs as $x) { $s += $x; } } return $s; } function f13(dict<int, vec<int>> $xss): int { $s = 0; foreach ($xss as $_ => $xs) { // Variables named $_ are ignored foreach ($xs as $_) { $s += 1; } } return $s; }
PHP
hhvm/hphp/hack/test/lint/foreach_shadow_lambda.php
<?hh function foo(): void { $x = 0; $f = () ==> { // This does not shadow the local in the outer scope, as the outer // $x is not affected. foreach (vec[] as $x) { } }; } // A second function to silence the naming lint about single definition files. function bar(): void {}
PHP
hhvm/hphp/hack/test/lint/good_switch.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function each( Traversable<shape('name' => string)> $xs, (function (shape('name' => string)): void) $f, ): void { foreach ($xs as $x) { $f($x); } } type ShapeWithString = vec<shape( 'name' => string, )>; final abstract class SwitchTest { public static function withLoop(ShapeWithString $inputs): void { foreach ($inputs as $input) { switch ($input['name']) { case 'case1': break; case 'case2': break; default: } } } public static function withLambda(ShapeWithString $inputs): void { each($inputs, $input ==> { $x = $input['name']; switch ($x) { case 'case1': break; case 'case2': break; default: } }); } }
PHP
hhvm/hphp/hack/test/lint/include_use.php
<?hh // bad include 'test.php'; include_once 'test.php'; // ok require 'test.php'; require_once 'test.php';
PHP
hhvm/hphp/hack/test/lint/invalid_contains_check.php
<?hh // strict function should_delete_assoc( dict<int, Map<string, mixed>> $table_data, Map<string, mixed> $assoc, ): bool { return !HH\Lib\C\contains($table_data, (int)$assoc['id1']); } final class Foo {} class Bar {} final class Baz extends Bar {} function bad1(vec<Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad2(dict<int, Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad3(Traversable<Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad4(KeyedTraversable<int, Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad5(Container<Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad6(KeyedContainer<int, Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad7(Iterator<Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad8(IteratorAggregate<Foo> $x, int $i): bool { return HH\Lib\C\contains($x, $i); } function bad9(vec<Foo> $x, Baz $i): bool { return HH\Lib\C\contains($x, $i); } function bad10(vec<Foo> $x, Bar $i): bool { return HH\Lib\C\contains($x, $i); } function bad11(vec<Bar> $x, Foo $i): bool { return HH\Lib\C\contains($x, $i); } function good1(vec<Foo> $x, Foo $i): bool { return HH\Lib\C\contains($x, $i); } function good2(vec<Bar> $x, Baz $i): bool { return HH\Lib\C\contains($x, $i); } function good3(vec<Baz> $x, Bar $i): bool { return HH\Lib\C\contains($x, $i); }
PHP
hhvm/hphp/hack/test/lint/invalid_disjoint_check.php
<?hh // strict function contains<<<__NonDisjoint>> T1, <<__NonDisjoint>> T2>(Traversable<T1> $_t, T2 $_v):bool { return false; } function should_delete_assoc( dict<int, Map<string, mixed>> $table_data, Map<string, mixed> $assoc, ): bool { return !contains($table_data, (int)$assoc['id1']); } final class Foo {} class Bar {} final class Baz extends Bar {} function bad1(vec<Foo> $x, int $i): bool { return contains($x, $i); } function bad2(dict<int, Foo> $x, int $i): bool { return contains($x, $i); } function bad3(Traversable<Foo> $x, int $i): bool { return contains($x, $i); } function bad4(KeyedTraversable<int, Foo> $x, int $i): bool { return contains($x, $i); } function bad5(Container<Foo> $x, int $i): bool { return contains($x, $i); } function bad6(KeyedContainer<int, Foo> $x, int $i): bool { return contains($x, $i); } function bad7(Iterator<Foo> $x, int $i): bool { return contains($x, $i); } function bad8(IteratorAggregate<Foo> $x, int $i): bool { return contains($x, $i); } function bad9(vec<Foo> $x, Baz $i): bool { return contains($x, $i); } function bad10(vec<Foo> $x, Bar $i): bool { return contains($x, $i); } function bad11(vec<Bar> $x, Foo $i): bool { return contains($x, $i); } function good1(vec<Foo> $x, Foo $i): bool { return contains($x, $i); } function good2(vec<Bar> $x, Baz $i): bool { return contains($x, $i); } function good3(vec<Baz> $x, Bar $i): bool { return contains($x, $i); } enum OpaqueEnumInt : int { OFOO = 1; } enum OpaqueEnumString : string { OBAR = 'a'; } enum EnumInt : int as int { FOO = 1; } enum EnumString : string as string { BAR = 'a'; } // These are handled differently by the linter_equality_check function goodish1(vec<int> $x, OpaqueEnumInt $y): bool { return contains($x, $y); } function goodish2(vec<string> $x, OpaqueEnumInt $y): bool { return contains($x, $y); } function goodish3(vec<int> $x, EnumInt $y): bool { return contains($x, $y); } function goodish4(vec<OpaqueEnumInt> $x, OpaqueEnumInt $y): bool { return contains($x, $y); } function goodish5(vec<OpaqueEnumInt> $x, OpaqueEnumString $y): bool { return contains($x, $y); } function badenum(vec<string> $x, EnumInt $y): bool { return contains($x, $y); }
PHP
hhvm/hphp/hack/test/lint/invalid_opaque_enum_equality_check_against_backing_type.php
<?hh // strict enum Foo : int { FOO = 1; } function test1(Foo $f, int $i): void { // This is invalid, but may evaluate to true at runtime. The user should // satisfy the typechecker by using `Foo::assert` or `Foo::coerce` before // comparing. if ($f === $i) { var_dump($f); } } function test2(vec<Foo> $f, vec<int> $i): void { // This is invalid, but may evaluate to true at runtime. if ($f === $i) { var_dump($f); } } function test3(vec<int> $is, Foo $f): void { // This is invalid, but may evaluate to true at runtime. if (HH\Lib\C\contains($is, $f)) { var_dump($f); } } function test4(keyset<int> $is, Foo $f): void { // This is invalid, but may evaluate to true at runtime. if (HH\Lib\C\contains_key($is, $f)) { var_dump($f); } }
PHP
hhvm/hphp/hack/test/lint/invalid_opaque_enum_equality_check_against_incompatible_type.php
<?hh // strict enum Foo : int { FOO = 1; } function test1(Foo $f, string $s): void { // This is invalid and will always evaluate to false at runtime. if ($f === $s) { var_dump($f); } } function test2(vec<Foo> $f, vec<string> $s): void { // This is invalid and will always evaluate to false at runtime (unless the // vecs are both empty). if ($f === $s) { var_dump($f); } } function test3(vec<string> $strs, Foo $f): void { // This is invalid and will always evaluate to false at runtime. if (HH\Lib\C\contains($strs, $f)) { var_dump($f); } } function test4(keyset<string> $strs, Foo $f): void { // This is invalid and will always evaluate to false at runtime. if (HH\Lib\C\contains_key($strs, $f)) { var_dump($f); } }
PHP
hhvm/hphp/hack/test/lint/invalid_opaque_enum_equality_check_against_opaque_enum_with_different_backing_type.php
<?hh // strict enum Foo : int { FOO = 1; } enum Bar : string { BAR = 'BAR'; } function test1(Foo $f, Bar $b): void { // This is invalid and will always evaluate to false at runtime. if ($f === $b) { var_dump($f); } } function test2(vec<Foo> $f, vec<Bar> $b): void { // This is invalid and will always evaluate to false at runtime (unless the // vecs are both empty). if ($f === $b) { var_dump($f); } } function test3(vec<Bar> $bs, Foo $f): void { // This is invalid and will always evaluate to false at runtime. if (HH\Lib\C\contains($bs, $f)) { var_dump($f); } } function test4(keyset<Bar> $bs, Foo $f): void { // This is invalid and will always evaluate to false at runtime. if (HH\Lib\C\contains_key($bs, $f)) { var_dump($f); } }
PHP
hhvm/hphp/hack/test/lint/invalid_opaque_enum_equality_check_against_opaque_enum_with_same_backing_type.php
<?hh // strict enum Foo : int { FOO = 1; } enum Bar : int { BAR = 1; BAZ = 2; } function test1(Foo $f, Bar $b): void { // This is invalid, but may evaluate to true at runtime. if ($f === $b) { var_dump($f); } } function test2(vec<Bar> $bs, Foo $f): void { // This is invalid, but may evaluate to true at runtime. if (HH\Lib\C\contains($bs, $f)) { var_dump($f); } } function test3(keyset<Bar> $bs, Foo $f): void { // This is invalid, but may evaluate to true at runtime. if (HH\Lib\C\contains_key($bs, $f)) { var_dump($f); } } function test4(vec<Foo> $f, vec<Bar> $b): void { // This is invalid, but may evaluate to true at runtime. if ($f === $b) { var_dump($f); } }
PHP
hhvm/hphp/hack/test/lint/invariant.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test_invariant_fail1(): void { invariant(true, 'This should cause lint error'); } function test_invariant_fail2(): void { invariant(!!true, 'This should cause lint error'); } function test_invariant_fail3(): void { invariant(!true, 'This should cause lint error'); } function test_invariant_fail4(): void { // invariant(false) is a special case // it is converted directly into the call to invariant_violation invariant(false, 'This should not cause lint error'); } function test_invariant_ok(bool $cond): void { invariant($cond, 'This should not cause lint error'); }
PHP
hhvm/hphp/hack/test/lint/invariant_violation.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test_invariant(): void { invariant('false', 'This will never crash'); } function test_not_invariant(): void { invariant(!'false', 'This will always crash'); } function test_if(): void { if ('false') { printf('This will always happen'); } } function test_if_not(): void { if (!'false') { printf('This will never happen'); } } function test_double_not(): void { if (!!'false') { printf('This will always happen'); } } // negative examples below function test_if_var(): void { $false = false; if ($false) { invariant_violation('this should never happen'); } } function test_invariant_violation(): void { invariant_violation('This shouldn\'t cause a lint error'); } function test_function_on_string(): void { if (is_foo('foo')) { invariant_violation(''); } }
PHP
hhvm/hphp/hack/test/lint/is_always_false.php
<?hh // strict class A {} abstract class B {} class C extends B { public function f(): void {} } function test(A $a): void { if ($a is C) { $a->f(); } }
PHP
hhvm/hphp/hack/test/lint/is_always_false_2.php
<?hh interface I { public function bar():void { } } final class A { public function f(): void {} } function test(A $a): void { if ($a is I) { $a->f(); } }
PHP
hhvm/hphp/hack/test/lint/is_always_true0.php
<?hh // strict class A { public function f(): void {} } function test(A $a): void { if ($a is A) { $a->f(); } }
PHP
hhvm/hphp/hack/test/lint/is_always_true1.php
<?hh // strict abstract class A { public function f(): void {} } class B extends A {} function test(B $b): void { if ($b is A) { $b->f(); } }
PHP
hhvm/hphp/hack/test/lint/is_always_true2.php
<?hh // strict interface I { public function f(): void; } class A implements I { <<__Override>> public function f(): void {} } function test(A $a): void { if ($a is I) { $a->f(); } }