예제 #1
0
파일: process_test.py 프로젝트: jyn514/oil
    def testPipeline2(self):
        arena = test_lib.MakeArena('testPipeline')
        ex = test_lib.InitExecutor(arena=arena)

        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((ex, node))

        fd_state = process.FdState()
        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(ex, node1)))
        p.Add(Process(process.SubProgramThunk(ex, node2)))
        p.Add(Process(process.SubProgramThunk(ex, node3)))

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

        print(p.Run(_WAITER, _FD_STATE))
예제 #2
0
파일: process_test.py 프로젝트: shamrin/oil
    def testPipeline2(self):
        ex = test_lib.InitExecutor(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((ex, 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(ex, node1), _JOB_STATE))
        p.Add(Process(process.SubProgramThunk(ex, node2), _JOB_STATE))
        p.Add(Process(process.SubProgramThunk(ex, node3), _JOB_STATE))

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

        print(p.Run(_WAITER, _FD_STATE))
예제 #3
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)
예제 #4
0
  def testBraceExpand(self):
    # TODO: Move this to test_lib?
    c_parser = InitCommandParser('echo _{a,b}_')
    node = c_parser._ParseCommandLine()
    print(node)

    arena = test_lib.MakeArena('<cmd_exec_test.py>')
    ex = test_lib.InitExecutor(arena)
예제 #5
0
    def testPrompt(self):
        arena = test_lib.MakeArena('<ui_test.py>')
        ex = test_lib.InitExecutor(arena=arena)

        p = ui.Prompt(arena, ex.parse_ctx, ex)

        # Rgression for caching bug!
        self.assertEqual('foo', p.EvalPrompt(runtime.Str('foo')))
        self.assertEqual('foo', p.EvalPrompt(runtime.Str('foo')))
예제 #6
0
파일: prompt_test.py 프로젝트: jyn514/oil
  def testEvaluator(self):
    arena = test_lib.MakeArena('<ui_test.py>')
    mem = state.Mem('', [], {}, arena)

    ex = test_lib.InitExecutor(arena=arena)

    p = prompt.Evaluator('osh', arena, ex.parse_ctx, ex, mem)

    # Rgression for caching bug!
    self.assertEqual('foo', p.EvalPrompt(value.Str('foo')))
    self.assertEqual('foo', p.EvalPrompt(value.Str('foo')))
예제 #7
0
    def testShellFuncExecution(self):
        arena, c_parser = cmd_parse_test.InitCommandParser("""\
    f() {
      COMPREPLY=(f1 f2)
    }
    """)
        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)
예제 #8
0
파일: process_test.py 프로젝트: shamrin/oil
    def testPipeline(self):
        node = _CommandNode('uniq -c', _ARENA)
        ex = test_lib.InitExecutor(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((ex, node))

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

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

        comp_lookup = completion.Lookup()
        a = completion.ShellFuncAction(ex, func_node, comp_lookup)
        comp = self._CompApi(['f'], 0, 'f')
        matches = list(a.Matches(comp))
        self.assertEqual(['f1', 'f2'], matches)
예제 #10
0
 def setUpClass(cls):
     arena = test_lib.MakeArena('<ui_test.py>')
     mem = state.Mem('', [], {}, arena)
     ex = test_lib.InitExecutor(arena=arena)
     cls.p = prompt.Evaluator('osh', arena, ex.parse_ctx, ex, mem)