33import static org .junit .Assert .assertEquals ;
44import static org .junit .Assume .assumeTrue ;
55
6+ import java .io .BufferedReader ;
67import java .io .ByteArrayInputStream ;
78import java .io .ByteArrayOutputStream ;
89import java .io .IOException ;
@@ -202,8 +203,8 @@ public int exitCode() {
202203 * was produced
203204 */
204205 public String [] lines () {
205- List <String > normalized = normalizeOutputLines (output );
206- return normalized .toArray (new String [0 ]);
206+ List <String > split = readOutputLines (output );
207+ return split .toArray (new String [0 ]);
207208 }
208209
209210 /**
@@ -232,7 +233,7 @@ public void assertExpected() {
232233 return ;
233234 }
234235 if (expectedLines != null ) {
235- List <String > actualLines = normalizeOutputLines (output );
236+ List <String > actualLines = readOutputLines (output );
236237 assertEquals ("Unexpected output for " + description , expectedLines , actualLines );
237238 } else if (expectedOutput != null ) {
238239 assertEquals ("Unexpected output for " + description , expectedOutput , output );
@@ -244,25 +245,22 @@ public void assertExpected() {
244245 }
245246 }
246247
247- private static List <String > normalizeOutputLines (String output ) {
248+ private static List <String > readOutputLines (String output ) {
248249 if (output .isEmpty ()) {
249250 return Collections .emptyList ();
250251 }
251- String normalized = output .replace ("\r \n " , "\n " ).replace ("\r " , "\n " );
252- if (normalized .endsWith ("\n " )) {
253- normalized = normalized .substring (0 , normalized .length () - 1 );
254- }
255- if (normalized .isEmpty ()) {
256- return Collections .singletonList ("" );
252+ List <String > lines = new ArrayList <>();
253+ try (BufferedReader reader = new BufferedReader (new StringReader (output ))) {
254+ String line ;
255+ while ((line = reader .readLine ()) != null ) {
256+ lines .add (line );
257+ }
258+ } catch (IOException ex ) {
259+ throw new UncheckedIOException ("Failed to split captured output" , ex );
257260 }
258- return Arrays . asList ( normalized . split ( " \n " , - 1 ) );
261+ return Collections . unmodifiableList ( lines );
259262 }
260263
261- /**
262- * Returns the expected output configured on the builder.
263- *
264- * @return the expected output or {@code null} when no expectation was set
265- */
266264 public String expectedOutput () {
267265 return expectedOutput ;
268266 }
@@ -897,6 +895,8 @@ protected ActualResult execute(ExecutionEnvironment env) throws Exception {
897895 in ,
898896 new PrintStream (outBytes , true , StandardCharsets .UTF_8 .name ()),
899897 new PrintStream (errBytes , true , StandardCharsets .UTF_8 .name ()));
898+ cli .getSettings ().setDefaultRS ("\n " );
899+ cli .getSettings ().setDefaultORS ("\n " );
900900
901901 List <String > args = new ArrayList <>();
902902 for (Map .Entry <String , Object > entry : assignments .entrySet ()) {
0 commit comments