Port ML tests from partial to strict
[hiphop-php.git] / hphp / hack / test / integration_ml / ide / test_failed_parsing.ml
blobfbda6c95893d235b2dc57b17005e8ee1fc64d5cd
1 (*
2 * Copyright (c) 2016, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
9 *)
11 module Test = Integration_test_base
13 let foo_name = "foo.php"
15 let foo_contents =
16 Printf.sprintf "<?hh // strict
17 /* HH_FIXME[4336] */
18 function foo(): %s {
22 let foo_returns_int_contents = foo_contents "int"
24 let foo_returns_string_contents = foo_contents "string"
26 let bar_name = "bar.php"
28 let bar_contents = "<?hh // strict
30 function bar() : void {
31 foo();
34 let parse_error = "<?hh
38 let bar_parse_error_diagnostics =
40 /bar.php:
41 File \"/bar.php\", line 3, characters 1-1:
42 Toplevel statements are not allowed. Use `__EntryPoint` attribute instead (Parsing[1002])
44 File \"/bar.php\", line 3, characters 2-2:
45 A right brace `}` is expected here. (Parsing[1002])
48 let root = "/"
50 let hhconfig_filename = Filename.concat root ".hhconfig"
52 let hhconfig_contents =
54 allowed_fixme_codes_strict = 4336
55 allowed_decl_fixme_codes = 4336
58 let test () =
59 Relative_path.set_path_prefix Relative_path.Root (Path.make root);
60 TestDisk.set hhconfig_filename hhconfig_contents;
61 let hhconfig_path =
62 Relative_path.create Relative_path.Root hhconfig_filename
64 let options = ServerArgs.default_options ~root in
65 let (custom_config, _) =
66 ServerConfig.load ~silent:false hhconfig_path options
68 let env = Test.setup_server ~custom_config () in
69 let env =
70 Test.setup_disk
71 env
72 [(foo_name, foo_returns_int_contents); (bar_name, bar_contents)]
74 let env = Test.connect_persistent_client env in
75 let env = Test.subscribe_diagnostic env in
76 Test.assert_no_errors env;
78 let env = Test.wait env in
79 let (env, loop_output) = Test.(run_loop_once env default_loop_input) in
80 Test.assert_no_diagnostics loop_output;
82 let env = Test.open_file env bar_name ~contents:parse_error in
83 let env = Test.wait env in
84 let (env, loop_output) = Test.(run_loop_once env default_loop_input) in
85 Test.assert_diagnostics loop_output bar_parse_error_diagnostics;
87 let env = Test.open_file env foo_name ~contents:foo_returns_string_contents in
88 let env = Test.wait env in
89 let (_, loop_output) = Test.(run_loop_once env default_loop_input) in
90 (* Bar depends on foo, so change of foo will trigger recheck of bar.
91 * Verify that doing this doesn't change previous parsing stage errors *)
92 Test.assert_no_diagnostics loop_output