21
21
* questions.
22
22
*/
23
23
24
+ import java .io .Writer ;
24
25
import java .lang .reflect .Method ;
25
26
import java .nio .file .Files ;
26
27
import java .nio .file .Path ;
33
34
import org .junit .jupiter .api .Assumptions ;
34
35
import org .junit .jupiter .api .BeforeAll ;
35
36
import org .junit .jupiter .api .Nested ;
37
+ import org .junit .jupiter .api .Test ;
36
38
import org .junit .jupiter .api .condition .EnabledOnOs ;
37
39
import org .junit .jupiter .api .condition .OS ;
38
40
import org .junit .jupiter .api .extension .AfterTestExecutionCallback ;
48
50
49
51
/*
50
52
* @test
51
- * @bug 8305457
53
+ * @bug 8305457 8342936
52
54
* @summary java.io.IO tests
53
55
* @library /test/lib
54
56
* @run junit IO
@@ -131,22 +133,26 @@ public void inputTestInteractive(String console, String prompt) throws Exception
131
133
var testSrc = System .getProperty ("test.src" , "." );
132
134
var command = new ArrayList <String >();
133
135
command .add (expect .toString ());
134
- command .add (Path .of (testSrc , "input.exp" ).toAbsolutePath ().toString ());
136
+ String expectInputName = PROMPT_NONE .equals (prompt ) ? "input-no-prompt"
137
+ : "input" ;
138
+ command .add (Path .of (testSrc , expectInputName + ".exp" ).toAbsolutePath ().toString ());
135
139
command .add (System .getProperty ("test.jdk" ) + "/bin/java" );
136
140
command .add ("--enable-preview" );
137
141
if (console != null )
138
142
command .add ("-Djdk.console=" + console );
139
143
command .add (Path .of (testSrc , "Input.java" ).toAbsolutePath ().toString ());
140
- command .add (prompt == null ? "0" : "1" );
144
+ command .add (prompt == null ? "0" : PROMPT_NONE . equals ( prompt ) ? "2" : "1" );
141
145
command .add (String .valueOf (prompt ));
142
146
OutputAnalyzer output = ProcessTools .executeProcess (command .toArray (new String []{}));
143
147
output .reportDiagnosticSummary ();
144
148
assertEquals (0 , output .getExitValue ());
145
149
}
146
150
151
+ private static final String PROMPT_NONE = "prompt-none" ;
152
+
147
153
public static Stream <Arguments > args () {
148
154
// cross product: consoles x prompts
149
- return Stream .of (null , "gibberish" ).flatMap (console -> Stream .of (null , "?" , "%s" )
155
+ return Stream .of (null , "gibberish" ).flatMap (console -> Stream .of (null , "?" , "%s" , PROMPT_NONE )
150
156
.map (prompt -> new String []{console , prompt }).map (Arguments ::of ));
151
157
}
152
158
}
@@ -172,6 +178,33 @@ public void printTest(String mode) throws Exception {
172
178
out .substring (out .length () / 2 ));
173
179
}
174
180
181
+ @ Test //JDK-8342936
182
+ public void printlnNoParamsTest () throws Exception {
183
+ var file = Path .of ("PrintlnNoParams.java" );
184
+ try (Writer w = Files .newBufferedWriter (file )) {
185
+ w .write ("""
186
+ void main() {
187
+ print("1 ");
188
+ print("2 ");
189
+ print("3 ");
190
+ println();
191
+ System.console().print("1 ");
192
+ System.console().print("2 ");
193
+ System.console().print("3 ");
194
+ System.console().println();
195
+ }
196
+ """ );
197
+ }
198
+ var pb = ProcessTools .createTestJavaProcessBuilder ("--enable-preview" , file .toString ());
199
+ OutputAnalyzer output = ProcessTools .executeProcess (pb );
200
+ assertEquals (0 , output .getExitValue ());
201
+ assertTrue (output .getStderr ().isEmpty ());
202
+ output .reportDiagnosticSummary ();
203
+ String out = output .getStdout ();
204
+ String nl = System .getProperty ("line.separator" );
205
+ assertEquals ("1 2 3 " + nl + "1 2 3 " + nl , out );
206
+ }
207
+
175
208
176
209
@ ParameterizedTest
177
210
@ ValueSource (strings = {"println" , "print" , "input" })
0 commit comments