Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8303697: ProcessTools doesn't print last line of process output
Reviewed-by: dholmes, stuefe
- Loading branch information
Showing
2 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
test/lib-test/jdk/test/lib/process/ProcessToolsLastLineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8303697 | ||
* @summary Test verifies that ProcessTools.startProcess() print all lines even the last line doesn't end with '\n' | ||
* @library /test/lib | ||
* @run main ProcessToolsLastLineTest | ||
*/ | ||
|
||
import jdk.test.lib.process.ProcessTools; | ||
import jdk.test.lib.Asserts; | ||
|
||
public class ProcessToolsLastLineTest { | ||
|
||
static void test(String output) throws Exception { | ||
final StringBuffer sb = new StringBuffer(); | ||
Process p = ProcessTools.startProcess("process", | ||
ProcessTools.createJavaProcessBuilder(ProcessToolsLastLineTest.class.getName(), output), | ||
line -> { sb.append(line);}); | ||
p.waitFor(); | ||
String expectedOutput = output.replace("\n", ""); | ||
Asserts.assertEQ(sb.toString(), expectedOutput); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
// The line which exceeds internal StreamPumper buffer (256 bytes) | ||
String VERY_LONG_LINE = "X".repeat(257); | ||
if (args.length > 0) { | ||
System.out.print(args[0]); | ||
} else { | ||
test("\n"); | ||
test("\nARG1"); | ||
test("\nARG1\n"); | ||
test("ARG1\n"); | ||
test("ARG1"); | ||
test("ARG1\nARG2"); | ||
test("ARG1\nARG2\n"); | ||
test("\nARG1\nARG2\n"); | ||
test("\nARG1\n" + VERY_LONG_LINE + "\nARG2\n"); | ||
test("\nARG1\n" + VERY_LONG_LINE); | ||
test("\nARG1\n" + VERY_LONG_LINE + VERY_LONG_LINE + VERY_LONG_LINE + "\nARG2\n"); | ||
test("\nARG1\n" + VERY_LONG_LINE + VERY_LONG_LINE + VERY_LONG_LINE); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8d2ebf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues