Esempio n. 1
0
    def testParseCommand(self):
        c_parser = test_lib.InitCommandParser('ls foo')
        node = c_parser.ParseCommand()
        self.assertEqual(2, len(node.words))
        print(node)

        c_parser = test_lib.InitCommandParser('fun() { echo hi; }')
        node = c_parser.ParseCommand()
        print(node)
        self.assertEqual(command_e.ShFunction, node.tag)
Esempio n. 2
0
  def testBraceExpand(self):
    arena = test_lib.MakeArena('<cmd_exec_test.py>')
    c_parser = test_lib.InitCommandParser('echo _{a,b}_', arena=arena)
    node = c_parser._ParseCommandLine()
    print(node)

    ex = test_lib.InitExecutor(arena=arena)
Esempio n. 3
0
def _assert_ParseCommandListError(test, code_str):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)

    try:
        node = c_parser._ParseCommandLine()
    except error.Parse as e:
        ui.PrettyPrintError(e, arena)
    else:
        print('UNEXPECTED:')
        node.PrettyPrint()
        test.fail("Expected %r to fail" % code_str)
Esempio n. 4
0
  def testShellFuncExecution(self):
    arena = test_lib.MakeArena('testShellFuncExecution')
    c_parser = test_lib.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """, arena=arena)
    func_node = c_parser.ParseLogicalLine()
    print(func_node)

    ex = test_lib.InitExecutor(arena=arena)

    a = completion.ShellFuncAction(ex, func_node)
    comp = self._MakeComp(['f'], 0, 'f')
    matches = list(a.Matches(comp))
    self.assertEqual(['f1', 'f2'], matches)
Esempio n. 5
0
  def testShellFuncExecution(self):
    arena = test_lib.MakeArena('testShellFuncExecution')
    c_parser = test_lib.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """, arena=arena)
    node = c_parser.ParseLogicalLine()
    proc = Proc(node.name, node.spids[1], proc_sig.Open(), node.body, [], True)

    cmd_ev = test_lib.InitCommandEvaluator(arena=arena)

    comp_lookup = completion.Lookup()
    a = completion.ShellFuncAction(cmd_ev, proc, comp_lookup)
    comp = self._CompApi(['f'], 0, 'f')
    matches = list(a.Matches(comp))
    self.assertEqual(['f1', 'f2'], matches)
Esempio n. 6
0
def _assertParseMethod(test, code_str, method, expect_success=True):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)
    m = getattr(c_parser, method)
    try:
        node = m()

    except error.Parse as e:
        ui.PrettyPrintError(e, arena)
        if expect_success:
            test.fail('%r failed' % code_str)
        node = None
    else:
        node.PrettyPrint()
        if not expect_success:
            test.fail('Expected %r to fail ' % code_str)

    return node
Esempio n. 7
0
    def testShellFuncExecution(self):
        arena = test_lib.MakeArena('testShellFuncExecution')
        c_parser = test_lib.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """,
                                              arena=arena)
        func_node = c_parser.ParseLogicalLine()
        print(func_node)

        cmd_ev = test_lib.InitCommandEvaluator(arena=arena)

        comp_lookup = completion.Lookup()
        a = completion.ShellFuncAction(cmd_ev, func_node, comp_lookup)
        comp = self._CompApi(['f'], 0, 'f')
        matches = list(a.Matches(comp))
        self.assertEqual(['f1', 'f2'], matches)
Esempio n. 8
0
def _assertParseMethod(test, code_str, method, expect_success=True):
    arena = test_lib.MakeArena('<cmd_parse_test>')
    c_parser = test_lib.InitCommandParser(code_str, arena=arena)
    m = getattr(c_parser, method)
    try:
        if method == 'ParseSimpleCommand':
            node = m([])  # required cur_aliases arg
        else:
            node = m()

    except util.ParseError as e:
        ui.PrettyPrintError(e, arena, sys.stdout)
        if expect_success:
            test.fail('%r failed' % code_str)
        node = None
    else:
        ast_lib.PrettyPrint(node)
        if not expect_success:
            test.fail('Expected %r to fail ' % code_str)

    return node
Esempio n. 9
0
def _CommandNode(code_str, arena):
  c_parser = test_lib.InitCommandParser(code_str, arena=arena)
  return c_parser.ParseLogicalLine()