Exemple #1
0
  def testBraceExpand(self):
    arena = test_lib.MakeArena('<cmd_eval_test.py>')
    c_parser = test_lib.InitCommandParser('echo _{a,b}_', arena=arena)
    node = c_parser._ParseCommandLine()
    print(node)

    cmd_ev = test_lib.InitCommandEvaluator(arena=arena)
Exemple #2
0
  def testPipeline2(self):
    cmd_ev = test_lib.InitCommandEvaluator(arena=_ARENA, ext_prog=_EXT_PROG)

    Banner('ls | cut -d . -f 1 | head')
    p = process.Pipeline()
    p.Add(_ExtProc(['ls']))
    p.Add(_ExtProc(['cut', '-d', '.', '-f', '1']))

    node = _CommandNode('head', _ARENA)
    p.AddLast((cmd_ev, node))

    fd_state = process.FdState(_ERRFMT, _JOB_STATE)
    print(p.Run(_WAITER, _FD_STATE))

    # Simulating subshell for each command
    node1 = _CommandNode('ls', _ARENA)
    node2 = _CommandNode('head', _ARENA)
    node3 = _CommandNode('sort --reverse', _ARENA)

    p = process.Pipeline()
    p.Add(Process(process.SubProgramThunk(cmd_ev, node1), _JOB_STATE))
    p.Add(Process(process.SubProgramThunk(cmd_ev, node2), _JOB_STATE))
    p.Add(Process(process.SubProgramThunk(cmd_ev, node3), _JOB_STATE))

    last_thunk = (cmd_ev, _CommandNode('cat', _ARENA))
    p.AddLast(last_thunk)

    print(p.Run(_WAITER, _FD_STATE))
Exemple #3
0
    def testPipeline2(self):
        cmd_ev = test_lib.InitCommandEvaluator(arena=self.arena,
                                               ext_prog=self.ext_prog)

        Banner('ls | cut -d . -f 1 | head')
        p = process.Pipeline()
        p.Add(self._ExtProc(['ls']))
        p.Add(self._ExtProc(['cut', '-d', '.', '-f', '1']))

        node = _CommandNode('head', self.arena)
        p.AddLast((cmd_ev, node))

        print(p.Run(self.waiter, self.fd_state))

        # Simulating subshell for each command
        node1 = _CommandNode('ls', self.arena)
        node2 = _CommandNode('head', self.arena)
        node3 = _CommandNode('sort --reverse', self.arena)

        p = process.Pipeline()
        p.Add(
            Process(process.SubProgramThunk(cmd_ev, node1), self.job_state,
                    self.tracer))
        p.Add(
            Process(process.SubProgramThunk(cmd_ev, node2), self.job_state,
                    self.tracer))
        p.Add(
            Process(process.SubProgramThunk(cmd_ev, node3), self.job_state,
                    self.tracer))

        last_thunk = (cmd_ev, _CommandNode('cat', self.arena))
        p.AddLast(last_thunk)

        print(p.Run(self.waiter, self.fd_state))
Exemple #4
0
  def testPipeline(self):
    node = _CommandNode('uniq -c', _ARENA)
    cmd_ev = test_lib.InitCommandEvaluator(arena=_ARENA, ext_prog=_EXT_PROG)
    print('BEFORE', os.listdir('/dev/fd'))

    p = process.Pipeline()
    p.Add(_ExtProc(['ls']))
    p.Add(_ExtProc(['cut', '-d', '.', '-f', '2']))
    p.Add(_ExtProc(['sort']))

    p.AddLast((cmd_ev, node))

    pipe_status = p.Run(_WAITER, _FD_STATE)
    log('pipe_status: %s', pipe_status)

    print('AFTER', os.listdir('/dev/fd'))
Exemple #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)
Exemple #6
0
    def testPipeline(self):
        node = _CommandNode('uniq -c', self.arena)
        cmd_ev = test_lib.InitCommandEvaluator(arena=self.arena,
                                               ext_prog=self.ext_prog)
        print('BEFORE', os.listdir('/dev/fd'))

        p = process.Pipeline()
        p.Add(self._ExtProc(['ls']))
        p.Add(self._ExtProc(['cut', '-d', '.', '-f', '2']))
        p.Add(self._ExtProc(['sort']))

        p.AddLast((cmd_ev, node))

        pipe_status = p.Run(self.waiter, self.fd_state)
        log('pipe_status: %s', pipe_status)

        print('AFTER', os.listdir('/dev/fd'))
Exemple #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)