Use conditionals in sync_functions instead of section blocks
[hiphop-php.git] / hphp / hack / test / incremental / test_enum_exhaustiveness.ml
blobf52f9d420a5c304e2c55b3b5b3d218952e67af5f
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 ->
44 str ^ (error |> User_error.to_absolute |> Errors.to_string))
46 @@ errors
48 let () =
49 let env = Test.setup_server () in
50 (* Initially we expect no errors *)
51 let (env, _) =
52 Test.(
53 run_loop_once
54 env
56 default_loop_input with
57 disk_changes = make_disk_changes init_base_content;
60 let errors = Errors.get_sorted_error_list env.errorl in
61 if errors <> [] then
62 Test.fail ("Expected no errors. Got:\n" ^ errors_to_string errors);
64 (* We expect errors when we change base.php to err_base_content *)
65 let (env, _) =
66 Test.(
67 run_loop_once
68 env
70 default_loop_input with
71 disk_changes = make_disk_changes err_base_content;
74 let expected_errors = Errors.get_sorted_error_list env.errorl in
75 if expected_errors = [] then Test.fail "Expected there to be errors!";
77 (* We reset the disk changes to the initial state. Should be no errors *)
78 let (env, _) =
79 Test.(
80 run_loop_once
81 env
83 default_loop_input with
84 disk_changes = make_disk_changes init_base_content;
87 let errors = Errors.get_sorted_error_list env.errorl in
88 if errors <> [] then
89 Test.fail ("Expected no errors. Got:\n" ^ errors_to_string errors);
91 (* We now change only base.php. We expect the same errors as before *)
92 let (env, _) =
93 Test.(
94 run_loop_once
95 env
97 default_loop_input with
98 disk_changes = [("base.php", err_base_content)];
101 let incremental_errors = Errors.get_sorted_error_list env.errorl in
102 if incremental_errors <> expected_errors then
103 Test.fail
104 ("Incremental mode gave different errors than a full type check.\n\n"
105 ^ "Full Type Check Errors:\n"
106 ^ errors_to_string expected_errors
107 ^ "\n"
108 ^ "Incremental Mode Errors:\n"
109 ^ errors_to_string incremental_errors)