Beispiel #1
0
    def test_options_cmd(self):
        """
        Make sure we are invoking the server_options_cmd with the right flags
        """
        args_file = os.path.join(self.saved_state_dir, 'cmd_args')
        with open(os.path.join(self.repo_dir, 'server_options.sh'), 'w') as f:
            f.write(r"""
#! /bin/sh
echo "$1" > {out}
echo "$2" >> {out}
            """.format(out=args_file))
            os.fchmod(f.fileno(), 0o700)

        with open(os.path.join(self.repo_dir, '.hhconfig'), 'w') as f:
            f.write(r"""
# some comment
load_script = %s
            """ % os.path.join(self.repo_dir, 'server_options.sh'))

        proc_call([
            self.hh_client,
            'start',
            self.repo_dir
        ])

        version = proc_call([
            self.hh_server,
            '--version'
        ])

        with open(args_file) as f:
            self.assertEqual(f.read().splitlines(), [self.repo_dir, version])
Beispiel #2
0
    def test_options_cmd(self):
        """
        Make sure we are invoking the server_options_cmd with the right flags
        """
        args_file = os.path.join(self.saved_state_dir, 'cmd_args')
        with open(os.path.join(self.repo_dir, 'server_options.sh'), 'w') as f:
            f.write(r"""
#! /bin/sh
echo "$1" > {out}
echo "$2" >> {out}
            """.format(out=args_file))
            os.fchmod(f.fileno(), 0o700)

        with open(os.path.join(self.repo_dir, '.hhconfig'), 'w') as f:
            f.write(r"""
# some comment
server_options_cmd = %s
            """ % os.path.join(self.repo_dir, 'server_options.sh'))

        proc_call([
            self.hh_client,
            'start',
            self.repo_dir
        ])

        version = proc_call([
            self.hh_server,
            self.repo_dir,
            '--version'
        ])

        with open(args_file) as f:
            self.assertEqual(f.read().splitlines(), [self.repo_dir, version])
Beispiel #3
0
    def test_ide_tools(self):
        """
        Test hh_client --search, --find-refs, --find-class-refs, --type-at-pos,
        and --list-files

        We *could* break this up into multiple tests, but starting the server
        takes time and this test is slow enough already
        """

        write_load_config(
            self.repo_dir,
            os.path.join(self.saved_state_dir, 'foo'))

        # adding flags to hh_client check disables the autostart behavior, so
        # we start up hh_server manually
        proc_call([
            self.hh_client,
            'start',
            self.repo_dir
        ])

        self.check_cmd([
            'File "{root}foo_3.php", line 9, characters 18-40: some_long_function_name, function'
            ], options=['--search', 'some_lo'])

        self.check_cmd([
            'File "{root}foo_3.php", line 11, characters 13-13: h',
            '1 total results'
            ], options=['--find-refs', 'h'])

        self.check_cmd([
            'File "{root}foo_3.php", line 10, characters 17-19: Foo::__construct',
            '1 total results'
            ], options=['--find-class-refs', 'Foo'])

        self.check_cmd([
            'string'
            ], options=['--type-at-pos', '{root}foo_3.php:11:13'])

        self.check_cmd([
            '{root}foo_1.php',
            '{root}foo_3.php',
            ], options=['--list-files'])

        self.check_cmd([
            # the doubled curly braces are because this string gets passed
            # through format()
            '[{{"name":"some_long_function_name",'
            '"type":"(function(): _)",'
            '"pos":{{"filename":"{root}foo_3.php",'
            '"line":9,"char_start":18,"char_end":40}},'
            '"func_details":{{"min_arity":0,"return_type":"_","params":[]}},'
            '"expected_ty":false}}]'
            ],
            # test the --json output because the non-json one doesn't contain
            # the filename, and we are especially interested in testing file
            # paths
            options=['--auto-complete', '--json'],
            stdin='<?hh function f() { some_AUTO332\n')
Beispiel #4
0
    def test_ide_tools(self):
        """
        Test hh_client --search, --find-refs, --find-class-refs, --type-at-pos,
        and --list-files

        We *could* break this up into multiple tests, but starting the server
        takes time and this test is slow enough already
        """

        write_load_config(
            self.repo_dir,
            os.path.join(self.saved_state_dir, 'foo'))

        # adding flags to hh_client check disables the autostart behavior, so
        # we start up hh_server manually
        proc_call([
            self.hh_client,
            'start',
            self.repo_dir
        ])

        self.check_cmd([
            'File "{root}foo_3.php", line 9, characters 18-40: some_long_function_name, function'
            ], options=['--search', 'some_lo'])

        self.check_cmd([
            'File "{root}foo_3.php", line 11, characters 13-13: h',
            '1 total results'
            ], options=['--find-refs', 'h'])

        self.check_cmd([
            'File "{root}foo_3.php", line 10, characters 17-19: Foo::__construct',
            '1 total results'
            ], options=['--find-class-refs', 'Foo'])

        self.check_cmd([
            'string'
            ], options=['--type-at-pos', '{root}foo_3.php:11:13'])

        self.check_cmd([
            '{root}foo_1.php',
            '{root}foo_3.php',
            ], options=['--list-files'])

        self.check_cmd([
            # the doubled curly braces are because this string gets passed
            # through format()
            '[{{"name":"some_long_function_name",'
            '"type":"(function(): _)",'
            '"pos":{{"filename":"{root}foo_3.php",'
            '"line":9,"char_start":18,"char_end":40}},'
            '"func_details":{{"min_arity":0,"return_type":"_","params":[]}},'
            '"expected_ty":false}}]'
            ],
            # test the --json output because the non-json one doesn't contain
            # the filename, and we are especially interested in testing file
            # paths
            options=['--auto-complete', '--json'],
            stdin='<?hh function f() { some_AUTO332\n')
Beispiel #5
0
 def check_cmd(self, expected_output, stdin=None, options=None):
     options = [] if options is None else options
     root = self.repo_dir + os.path.sep
     output = proc_call(
         [hh_client, 'check', '--retries', '20', self.repo_dir] +
         list(map(lambda x: x.format(root=root), options)),
         env={'HH_LOCALCONF_PATH': self.repo_dir},
         stdin=stdin)
     log_file = proc_call([hh_client, '--logname', self.repo_dir]).strip()
     with open(log_file) as f:
         logs = f.read()
         self.assertIn('Mini-state loading worker took', logs)
     self.assertCountEqual(
         map(lambda x: x.format(root=root), expected_output),
         output.splitlines())
Beispiel #6
0
    def test_options_cmd(self):
        """
        Make sure we are invoking the server_options_cmd with the right flags
        """
        args_file = os.path.join(self.saved_state_dir, "cmd_args")
        with open(os.path.join(self.repo_dir, "server_options.sh"), "w") as f:
            f.write(
                r"""
#! /bin/sh
echo "$1" > {out}
echo "$2" >> {out}
            """.format(
                    out=args_file
                )
            )
            os.fchmod(f.fileno(), 0o700)

        with open(os.path.join(self.repo_dir, ".hhconfig"), "w") as f:
            f.write(
                r"""
# some comment
load_script = %s
            """
                % os.path.join(self.repo_dir, "server_options.sh")
            )

        self.check_cmd(self.initial_errors)

        version = proc_call([self.hh_server, "--version"])

        with open(args_file) as f:
            self.assertEqual(f.read().splitlines(), [self.repo_dir, version])
Beispiel #7
0
 def check_cmd(self, expected_output, stdin=None, options=[]):
     root = self.repo_dir + os.path.sep
     output = proc_call(
         [self.hh_client, "check", "--retries", "20", self.repo_dir]
         + list(map(lambda x: x.format(root=root), options)),
         stdin=stdin,
     )
     self.assertCountEqual(map(lambda x: x.format(root=root), expected_output), output.splitlines())
 def check_cmd(self, expected_output, stdin=None, options=[]):
     root = self.repo_dir + os.path.sep
     output = proc_call(
         [self.hh_client, 'check', '--retries', '20', self.repo_dir] +
         list(map(lambda x: x.format(root=root), options)),
         stdin=stdin)
     self.assertCountEqual(
         map(lambda x: x.format(root=root), expected_output),
         output.splitlines())
Beispiel #9
0
    def test_no_state_found(self):
        with open(os.path.join(self.repo_dir, 'server_options.sh'), 'w') as f:
            # exit without printing anything
            f.write(r"#! /bin/sh")
            os.fchmod(f.fileno(), 0o700)

        self.write_local_conf()
        self.write_hhconfig('server_options.sh')

        output = proc_call(
            [hh_client, 'check', '--retries', '20', self.repo_dir],
            env={'HH_LOCALCONF_PATH': self.repo_dir})

        self.assertEqual(output.strip(), 'No errors!')

        log_file = proc_call([hh_client, '--logname', self.repo_dir]).strip()
        with open(log_file) as f:
            logs = f.read()
            self.assertIn('Could not load mini state', logs)
Beispiel #10
0
 def check_cmd(self, expected_output, stdin=None, options=None):
     options = [] if options is None else options
     root = self.repo_dir + os.path.sep
     output = proc_call([
         hh_client,
         'check',
         '--retries',
         '20',
         self.repo_dir
         ] + list(map(lambda x: x.format(root=root), options)),
         env={'HH_LOCALCONF_PATH': self.repo_dir},
         stdin=stdin)
     log_file = proc_call([hh_client, '--logname', self.repo_dir]).strip()
     with open(log_file) as f:
         logs = f.read()
         self.assertIn('Loading deps took', logs)
     self.assertCountEqual(
         map(lambda x: x.format(root=root), expected_output),
         output.splitlines())
Beispiel #11
0
 def check_errors(self, expected_errors):
     output = proc_call([
         self.hh_client,
         'check',
         '--autostart-server',
         'false',
         self.repo_dir
     ])
     self.assertCountEqual(
         expected_errors,
         relativize_error_paths(output.splitlines()))
Beispiel #12
0
 def check_cmd(self, expected_output, options=[]):
     root = self.repo_dir + os.path.sep
     output = proc_call([
         self.hh_client,
         'check',
         '--autostart-server',
         'false',
         self.repo_dir
     ] + list(map(lambda x: x.format(root=root), options)))
     self.assertCountEqual(
         map(lambda x: x.format(root=root), expected_output),
         output.splitlines())
Beispiel #13
0
    def test_no_state_found(self):
        with open(os.path.join(self.repo_dir, 'server_options.sh'), 'w') as f:
            # exit without printing anything
            f.write(r"#! /bin/sh")
            os.fchmod(f.fileno(), 0o700)

        self.write_local_conf()
        self.write_hhconfig('server_options.sh')

        output = proc_call([
            hh_client,
            'check',
            '--retries',
            '20',
            self.repo_dir
            ],
            env={'HH_LOCALCONF_PATH': self.repo_dir})

        self.assertEqual(output.strip(), 'No errors!')

        log_file = proc_call([hh_client, '--logname', self.repo_dir]).strip()
        with open(log_file) as f:
            logs = f.read()
            self.assertIn('Could not load mini state', logs)
Beispiel #14
0
    def test_hhconfig_change(self):
        """
        Start hh_server, then change .hhconfig and check that the server
        restarts itself
        """
        self.write_load_config()
        self.check_cmd(['No errors!'])
        with open(os.path.join(self.repo_dir, '.hhconfig'), 'w') as f:
            f.write(r"""
# some comment
assume_php = true
load_mini_script = %s
""" % os.path.join(self.repo_dir, 'server_options.sh'))

        # this should start a new server
        self.check_cmd(['No errors!'])
        # check how the old one exited
        log_file =\
            proc_call([hh_client, '--logname', self.repo_dir]).strip() + '.old'
        with open(log_file) as f:
            logs = f.read()
            self.assertIn('.hhconfig changed in an incompatible way', logs)
Beispiel #15
0
    def test_hhconfig_change(self):
        """
        Start hh_server, then change .hhconfig and check that the server
        restarts itself
        """
        self.write_load_config()
        self.check_cmd(['No errors!'])
        with open(os.path.join(self.repo_dir, '.hhconfig'), 'w') as f:
            f.write(r"""
# some comment
assume_php = true
load_mini_script = %s
""" % os.path.join(self.repo_dir, 'server_options.sh'))

        # this should start a new server
        self.check_cmd(['No errors!'])
        # check how the old one exited
        log_file =\
            proc_call([hh_client, '--logname', self.repo_dir]).strip() + '.old'
        with open(log_file) as f:
            logs = f.read()
            self.assertIn('.hhconfig changed in an incompatible way', logs)