Skip to content

Commit fd3362f

Browse files
author
Robert James Oxspring
committed
Test checks the displayed output and does so quietly
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130089 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4122fc5 commit fd3362f

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/test/org/apache/commons/cli/BugsTest.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
package org.apache.commons.cli;
1717

18+
import java.io.ByteArrayOutputStream;
19+
import java.io.PrintStream;
20+
import java.io.StringWriter;
21+
1822
import junit.framework.Test;
1923
import junit.framework.TestCase;
2024
import junit.framework.TestSuite;
@@ -274,12 +278,30 @@ public void test13666() {
274278
.hasArg()
275279
.create( 'd' );
276280
options.addOption( dir );
277-
try {
278-
HelpFormatter formatter = new HelpFormatter();
279-
formatter.printHelp( "dir", options );
281+
282+
283+
final PrintStream oldSystemOut = System.out;
284+
try{
285+
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
286+
final PrintStream print = new PrintStream(bytes);
287+
288+
// capture this platform's eol symbol
289+
print.println();
290+
final String eol = bytes.toString();
291+
bytes.reset();
292+
293+
System.setOut(new PrintStream(bytes));
294+
try {
295+
HelpFormatter formatter = new HelpFormatter();
296+
formatter.printHelp( "dir", options );
297+
}
298+
catch( Exception exp ) {
299+
fail( "Unexpected Exception: " + exp.getMessage() );
300+
}
301+
assertEquals("usage: dir"+eol+" -d <arg> dir"+eol,bytes.toString());
280302
}
281-
catch( Exception exp ) {
282-
fail( "Unexpected Exception: " + exp.getMessage() );
303+
finally {
304+
System.setOut(oldSystemOut);
283305
}
284306
}
285307

0 commit comments

Comments
 (0)