3 from __future__
import absolute_import
, division
, print_function
, unicode_literals
8 from typing
import List
, Optional
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
22 expected_output
: Optional
[List
[str]],
23 stdin
: Optional
[str] = None,
24 options
: Optional
[List
[str]] = None,
26 assert_loaded_saved_state
: bool = False,
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(
46 + list(map(lambda x
: x
.format(root
=root
), options
)),
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)
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()
64 def assertEqualString(
65 self
, first
: str, second
: str, msg
: Optional
[str] = 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
):
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
:
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) {
91 /* HH_FIXME[4099] We can delete this one */
92 /* HH_FIXME[4098] We can delete this one */
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
:
110 function foo(?string $s): void {
111 /* HH_FIXME[4110] Keep errors discovered by new_inference */