Port ML tests from partial to strict
[hiphop-php.git] / hphp / hack / test / incremental / test_enum_exhaustiveness.ml
blobd6acf2873e10327bb2b222233a999ff9f9d1ca39
1 open Integration_test_base_types
2 open ServerEnv
3 module Test = Integration_test_base
5 let init_base_content =
6 "<?hh
7 enum DynamicTemplateField : string {
8 BRAND = 'brand';
9 DESCRIPTION = 'description';
10 // NAME = 'name';
13 let err_base_content =
14 "<?hh
15 enum DynamicTemplateField : string {
16 BRAND = 'brand';
17 DESCRIPTION = 'description';
18 NAME = 'name';
21 let make_disk_changes base_content =
23 ("base.php", base_content);
24 ( "test.php",
25 "<?hh // strict
27 function test(
28 DynamicTemplateField $field,
29 ): string {
30 // Switch enforces enum exhaustiveness
31 switch ($field) {
32 case DynamicTemplateField::BRAND:
33 return 'Brand';
34 case DynamicTemplateField::DESCRIPTION:
35 return 'Description';
41 let errors_to_string errors =
42 List.fold_left
43 (fun str error -> str ^ Errors.(error |> to_absolute |> to_string))
45 @@ errors
47 let () =
48 let env = Test.setup_server () in
49 (* Initially we expect no errors *)
50 let (env, _) =
51 Test.(
52 run_loop_once
53 env
55 default_loop_input with
56 disk_changes = make_disk_changes init_base_content;
59 let errors = Errors.get_sorted_error_list env.errorl in
60 if errors <> [] then
61 Test.fail ("Expected no errors. Got:\n" ^ errors_to_string errors);
63 (* We expect errors when we change base.php to err_base_content *)
64 let (env, _) =
65 Test.(
66 run_loop_once
67 env
69 default_loop_input with
70 disk_changes = make_disk_changes err_base_content;
73 let expected_errors = Errors.get_sorted_error_list env.errorl in
74 if expected_errors = [] then Test.fail "Expected there to be errors!";
76 (* We reset the disk changes to the initial state. Should be no errors *)
77 let (env, _) =
78 Test.(
79 run_loop_once
80 env
82 default_loop_input with
83 disk_changes = make_disk_changes init_base_content;
86 let errors = Errors.get_sorted_error_list env.errorl in
87 if errors <> [] then
88 Test.fail ("Expected no errors. Got:\n" ^ errors_to_string errors);
90 (* We now change only base.php. We expect the same errors as before *)
91 let (env, _) =
92 Test.(
93 run_loop_once
94 env
96 default_loop_input with
97 disk_changes = [("base.php", err_base_content)];
100 let incremental_errors = Errors.get_sorted_error_list env.errorl in
101 if incremental_errors <> expected_errors then
102 Test.fail
103 ("Incremental mode gave different errors than a full type check.\n\n"
104 ^ "Full Type Check Errors:\n"
105 ^ errors_to_string expected_errors
106 ^ "\n"
107 ^ "Incremental Mode Errors:\n"
108 ^ errors_to_string incremental_errors)