Typecheck hierarchy and common tests.
[hiphop-php.git] / hphp / hack / test / integration / test_fresh_init.py
blob0c051a3ab1c695295e4bc0b8f3c7c24cd527a76c
1 # pyre-strict
3 from __future__ import absolute_import, division, print_function, unicode_literals
5 import os
6 import time
7 import unittest
8 from typing import List, Optional
10 import common_tests
11 from hh_paths import hh_client
14 class FreshInitTestDriver(common_tests.CommonTestDriver):
15 def write_load_config(self, use_saved_state: bool = False) -> None:
16 # Fresh init tests don't care about which files changed, so we can
17 # just use the default .hhconfig in the template repo
18 pass
20 def check_cmd(
21 self,
22 expected_output: Optional[List[str]],
23 stdin: Optional[str] = None,
24 options: Optional[List[str]] = None,
25 retries: int = 30,
26 assert_loaded_saved_state: bool = False,
27 ) -> str:
28 if options is None:
29 options = []
30 time.sleep(2) # wait for Hack to catch up with file system changes
32 root = self.repo_dir + os.path.sep
33 (output, err, retcode) = self.proc_call(
35 hh_client,
36 "check",
37 "--retries",
38 "60",
39 "--no-load",
40 "--error-format",
41 "raw",
42 "--config",
43 "max_workers=2",
44 self.repo_dir,
46 + list(map(lambda x: x.format(root=root), options)),
47 stdin=stdin,
50 if (retcode == 6 or retcode == 7) and retries > 0:
51 # 6 = "No_server_running_should_retry" or "Server_hung_up_should_retry"
52 # 7 = "Out_of_time" or "Out_of_retries"
53 return self.check_cmd(expected_output, stdin, options, retries - 1)
54 if retcode == 7:
55 raise unittest.SkipTest("Hack server exit code 7 - out of time/retries")
56 self.assertIn(retcode, [0, 2])
58 if expected_output is not None:
59 self.assertCountEqual(
60 map(lambda x: x.format(root=root), expected_output), output.splitlines()
62 return err
64 def assertEqualString(
65 self, first: str, second: str, msg: Optional[str] = None
66 ) -> None:
67 root = self.repo_dir + os.path.sep
68 second = second.format(root=root)
69 self.assertEqual(first, second, msg)
72 class TestFreshInit(common_tests.CommonTests):
73 @classmethod
74 def get_test_driver(cls) -> common_tests.CommonTestDriver:
75 return common_tests.CommonTestDriver()
77 def test_remove_dead_fixmes(self) -> None:
78 with open(os.path.join(self.test_driver.repo_dir, "foo_4.php"), "w") as f:
79 f.write(
80 """<?hh // strict
81 function foo(?string $s): void {
82 /* HH_FIXME[4010] We can delete this one */
83 /* HH_FIXME[4089] We need to keep this one */
84 /* HH_FIXME[4110] Keep errors discovered by new_inference */
85 /* HH_FIXME[4099] We can delete this one */
86 if (/* HH_FIXME[4011] We can delete this one */ $s) {
87 print "hello";
88 } else {
89 print "world";
91 /* HH_FIXME[4099] We can delete this one */
92 /* HH_FIXME[4098] We can delete this one */
93 print "done\n";
95 """
98 self.test_driver.start_hh_server(
99 changed_files=["foo_4.php"], args=["--no-load"]
101 self.test_driver.check_cmd(
102 expected_output=None, options=["--remove-dead-fixmes"]
105 with open(os.path.join(self.test_driver.repo_dir, "foo_4.php")) as f:
106 out = f.read()
107 self.assertEqual(
108 out,
109 """<?hh // strict
110 function foo(?string $s): void {
111 /* HH_FIXME[4110] Keep errors discovered by new_inference */
112 if ($s) {
113 print "hello";
114 } else {
115 print "world";
117 print "done\n";
119 """,