From f8c37a5fce1203c97747ea237f257484f2f7ca6d Mon Sep 17 00:00:00 2001
From: Greg Anderson <greg.1.anderson@greenknowe.org>
Date: Tue, 28 May 2013 10:37:29 -0700
Subject:  Greg Anderson: Generated with Drush iq

---
 includes/backend.inc  |    2 +-
 tests/backendTest.php |   26 ++++++++++++++++++++------
 tests/unit.drush.inc  |    5 +++++
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/includes/backend.inc b/includes/backend.inc
index 67074d0..a4bd562 100644
--- a/includes/backend.inc
+++ b/includes/backend.inc
@@ -543,7 +543,7 @@ function drush_backend_parse_packets(&$string, &$remainder, $backend_options) {
       }
     }

-    $string = rtrim(preg_replace("/$packet_regex/s", '', $string), "\n");
+    $string = preg_replace("/$packet_regex/s", '', $string);
   }
   // Check to see if there is potentially a partial packet remaining.
   // We only care about the last null; if there are any nulls prior
diff --git a/tests/backendTest.php b/tests/backendTest.php
index 5378885..db3f13d 100644
--- a/tests/backendTest.php
+++ b/tests/backendTest.php
@@ -226,13 +226,27 @@ EOD;
       'backend' => NULL,
       'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
     );
-    $php = "\$values = drush_invoke_process('@none', 'unit-return-options', array('value'), array('x' => 'y', 'data' => array('a' => 1, 'b' => 2)), array('method' => 'GET', '#process-read-size' => 16)); return array_key_exists('object', \$values) ? \$values['object'] : 'no result';";
-    $this->drush('php-eval', array($php), $options);
-    $parsed = parse_backend_output($this->getOutput());
-    // assert that $parsed has 'x' but not 'data'
-    $this->assertEquals("array (
-  'x' => 'y',
+    $read_sizes_to_test = array(128, 64, 16);
+    foreach ($read_sizes_to_test as $read_size) {
+      $log_message="";
+      for ($i = 1; $i <= 16; $i++) {
+        $log_message .= "X";
+        $php = "\$values = drush_invoke_process('@none', 'unit-return-options', array('value'), array('log-message' => '$log_message', 'x' => 'y$read_size', 'data' => array('a' => 1, 'b' => 2)), array('method' => 'GET', '#process-read-size' => $read_size)); return array_key_exists('object', \$values) ? \$values['object'] : 'no result';";
+        $this->drush('php-eval', array($php), $options);
+        $parsed = parse_backend_output($this->getOutput());
+        // assert that $parsed has 'x' but not 'data'
+        $all_warnings=array();
+        foreach ($parsed['log'] as $log) {
+          if ($log['type'] == 'warning') {
+            $all_warnings[] = $log['message'];
+          }
+        }
+        $this->assertEquals("$log_message,done", implode(',', $all_warnings), 'Log reconstruction with read_size ' . $read_size);
+        $this->assertEquals("array (
+  'x' => 'y$read_size',
 )", var_export($parsed['object'], TRUE));
+      }
+    }
   }
 }

diff --git a/tests/unit.drush.inc b/tests/unit.drush.inc
index fbd7a3c..e130885 100644
--- a/tests/unit.drush.inc
+++ b/tests/unit.drush.inc
@@ -135,6 +135,11 @@ function drush_unit_return_options() {
   foreach (drush_get_global_options() as $key => $info) {
     unset($all_option_values[$key]);
   }
+  if (isset($all_option_values['log-message'])) {
+    drush_log($all_option_values['log-message'], 'warning');
+    drush_log("done", 'warning');
+    unset($all_option_values['log-message']);
+  }
   return $all_option_values;
 }

--
1.7.9.5

