patch 7.4.1522 v7.4.1522
authorBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2016 19:12:44 +0000 (20:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2016 19:12:44 +0000 (20:12 +0100)
Problem:    Cannot write channel err to a buffer.
Solution:   Implement it.

src/channel.c
src/testdir/test_channel.vim
src/version.c

index dec0c79be19b76c18abd96f0153bd9d13fd867fa..3856dabbc72ae8d268675af07d502536b77f18c6 100644 (file)
@@ -871,7 +871,7 @@ channel_set_job(channel_T *channel, job_T *job, jobopt_T *options)
  * Find a buffer matching "name" or create a new one.
  */
     static buf_T *
-find_buffer(char_u *name)
+find_buffer(char_u *name, int err)
 {
     buf_T *buf = NULL;
     buf_T *save_curbuf = curbuf;
@@ -890,7 +890,8 @@ find_buffer(char_u *name)
        curbuf = buf;
        if (curbuf->b_ml.ml_mfp == NULL)
            ml_open(curbuf);
-       ml_replace(1, (char_u *)"Reading from channel output...", TRUE);
+       ml_replace(1, (char_u *)(err ? "Reading from channel error..."
+                                  : "Reading from channel output..."), TRUE);
        changed_bytes(1, 0);
        curbuf = save_curbuf;
     }
@@ -968,10 +969,27 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
        if (!(opt->jo_set & JO_OUT_MODE))
            channel->ch_part[PART_OUT].ch_mode = MODE_NL;
        channel->ch_part[PART_OUT].ch_buffer =
-                                      find_buffer(opt->jo_io_name[PART_OUT]);
-       ch_logs(channel, "writing to buffer '%s'",
+                               find_buffer(opt->jo_io_name[PART_OUT], FALSE);
+       ch_logs(channel, "writing out to buffer '%s'",
                      (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname);
     }
+
+    if ((opt->jo_set & JO_ERR_IO) && (opt->jo_io[PART_ERR] == JIO_BUFFER
+        || (opt->jo_io[PART_ERR] == JIO_OUT && (opt->jo_set & JO_OUT_IO)
+                                      && opt->jo_io[PART_OUT] == JIO_BUFFER)))
+    {
+       /* writing err to a buffer. Default mode is NL. */
+       if (!(opt->jo_set & JO_ERR_MODE))
+           channel->ch_part[PART_ERR].ch_mode = MODE_NL;
+       if (opt->jo_io[PART_ERR] == JIO_OUT)
+           channel->ch_part[PART_ERR].ch_buffer =
+                                        channel->ch_part[PART_OUT].ch_buffer;
+       else
+           channel->ch_part[PART_ERR].ch_buffer =
+                                find_buffer(opt->jo_io_name[PART_ERR], TRUE);
+       ch_logs(channel, "writing err to buffer '%s'",
+                     (char *)channel->ch_part[PART_ERR].ch_buffer->b_ffname);
+    }
 }
 
 /*
index 061b30c2510df698b0f7e7c13bc841c5fe725d48..7b531c8f0ec4b4542f099d625d05d97808c5ad67 100644 (file)
@@ -633,6 +633,53 @@ func Test_pipe_to_buffer()
   endtry
 endfunc
 
+func Test_pipe_err_to_buffer()
+  if !has('job')
+    return
+  endif
+  call ch_log('Test_pipe_err_to_buffer()')
+  let job = job_start(s:python . " test_channel_pipe.py",
+       \ {'err-io': 'buffer', 'err-name': 'pipe-err'})
+  call assert_equal("run", job_status(job))
+  try
+    let handle = job_getchannel(job)
+    call ch_sendraw(handle, "echoerr line one\n")
+    call ch_sendraw(handle, "echoerr line two\n")
+    call ch_sendraw(handle, "doubleerr this\n")
+    call ch_sendraw(handle, "quit\n")
+    sp pipe-err
+    call s:waitFor('line("$") >= 5')
+    call assert_equal(['Reading from channel error...', 'line one', 'line two', 'this', 'AND this'], getline(1, '$'))
+    bwipe!
+  finally
+    call job_stop(job)
+  endtry
+endfunc
+
+func Test_pipe_both_to_buffer()
+  if !has('job')
+    return
+  endif
+  call ch_log('Test_pipe_both_to_buffer()')
+  let job = job_start(s:python . " test_channel_pipe.py",
+       \ {'out-io': 'buffer', 'out-name': 'pipe-err', 'err-io': 'out'})
+  call assert_equal("run", job_status(job))
+  try
+    let handle = job_getchannel(job)
+    call ch_sendraw(handle, "echo line one\n")
+    call ch_sendraw(handle, "echoerr line two\n")
+    call ch_sendraw(handle, "double this\n")
+    call ch_sendraw(handle, "doubleerr that\n")
+    call ch_sendraw(handle, "quit\n")
+    sp pipe-err
+    call s:waitFor('line("$") >= 7')
+    call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
+    bwipe!
+  finally
+    call job_stop(job)
+  endtry
+endfunc
+
 func Test_pipe_from_buffer()
   if !has('job')
     return
index 5d7a968da0c90c4bef4c87e6d1fb323b4affd682..0c0e5bd0bfaf2cc9844a176760a7e4f326047c96 100644 (file)
@@ -743,6 +743,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1522,
 /**/
     1521,
 /**/