8295814: jdk/jshell/CommandCompletionTest.java fails with "lists don't have the same size expected [2] but found [1]"

Reviewed-by: jlahoda
This commit is contained in:
Adam Sotona 2022-11-15 12:09:59 +00:00
parent d0fae43e89
commit a45c9af124
2 changed files with 20 additions and 35 deletions

View File

@ -35,7 +35,6 @@ jdk/jshell/UserJdiUserRemoteTest.java
jdk/jshell/UserInputTest.java 8169536 generic-all
jdk/jshell/ToolBasicTest.java 8265357 macosx-aarch64
jdk/jshell/HighlightUITest.java 8284144 generic-all
jdk/jshell/CommandCompletionTest.java 8295814 linux-all
###########################################################################
#

View File

@ -36,18 +36,15 @@
*/
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.testng.SkipException;
import org.testng.annotations.Test;
@ -76,6 +73,16 @@ public class CommandCompletionTest extends ReplToolTesting {
}
}
public void assertCompletion(boolean after, String code, int minElements) {
if (!after) {
setCommandInput("\n");
} else {
List<String> completions = computeCompletions(code, false);
assertTrue(completions.size() >= minElements, "Command: " + code + ", output: " +
completions.toString() + ", expected output with at least " + minElements + " elements");
}
}
public void assertCompletion(boolean after, String code, boolean isSmart, String... expected) {
if (!after) {
setCommandInput("\n");
@ -86,8 +93,9 @@ public class CommandCompletionTest extends ReplToolTesting {
public void assertCompletion(String code, boolean isSmart, String... expected) {
List<String> completions = computeCompletions(code, isSmart);
assertEquals(completions, Arrays.asList(expected), "Command: " + code + ", output: " +
completions.toString());
List<String> expectedL = Arrays.asList(expected);
assertEquals(completions, expectedL, "Command: " + code + ", output: " +
completions.toString() + ", expected: " + expectedL.toString());
}
private List<String> computeCompletions(String code, boolean isSmart) {
@ -272,16 +280,12 @@ public class CommandCompletionTest extends ReplToolTesting {
testNoStartUp(
a -> assertCompletion(a, "/o|", false, "/open ")
);
List<String> p1 = listFiles(Paths.get(""));
getRootDirectories().forEach(s -> p1.add(s.toString()));
Collections.sort(p1);
testNoStartUp(
a -> assertCompletion(a, "/open |", false, p1.toArray(new String[p1.size()]))
a -> assertCompletion(a, "/open |", 1)
);
Path classDir = compiler.getClassDir();
List<String> p2 = listFiles(classDir);
testNoStartUp(
a -> assertCompletion(a, "/open " + classDir + "/|", false, p2.toArray(new String[p2.size()]))
a -> assertCompletion(a, "/open " + classDir + "/|", 1)
);
}
@ -291,20 +295,13 @@ public class CommandCompletionTest extends ReplToolTesting {
testNoStartUp(
a -> assertCompletion(a, "/s|", false, "/save ", "/set ")
);
List<String> p1 = listFiles(Paths.get(""));
Collections.addAll(p1, "-all ", "-history ", "-start ");
getRootDirectories().forEach(s -> p1.add(s.toString()));
Collections.sort(p1);
testNoStartUp(
a -> assertCompletion(a, "/save |", false, p1.toArray(new String[p1.size()]))
a -> assertCompletion(a, "/save |", 4)
);
Path classDir = compiler.getClassDir();
List<String> p2 = listFiles(classDir);
testNoStartUp(
a -> assertCompletion(a, "/save " + classDir + "/|",
false, p2.toArray(new String[p2.size()])),
a -> assertCompletion(a, "/save -all " + classDir + "/|",
false, p2.toArray(new String[p2.size()]))
a -> assertCompletion(a, "/save " + classDir + "/|", 1),
a -> assertCompletion(a, "/save -all " + classDir + "/|", 1)
);
}
@ -376,9 +373,6 @@ public class CommandCompletionTest extends ReplToolTesting {
@Test
public void testSet() throws IOException {
List<String> p1 = listFiles(Paths.get(""));
getRootDirectories().forEach(s -> p1.add(s.toString()));
Collections.sort(p1);
String[] modes = {"concise ", "normal ", "silent ", "verbose "};
String[] options = {"-command", "-delete", "-quiet"};
@ -389,7 +383,7 @@ public class CommandCompletionTest extends ReplToolTesting {
// /set editor
a -> assertCompletion(a, "/set e|", false, "editor "),
a -> assertCompletion(a, "/set editor |", false, p1.toArray(new String[p1.size()])),
a -> assertCompletion(a, "/set editor |", 1),
// /set feedback
a -> assertCompletion(a, "/set fe|", false, "feedback "),
@ -413,7 +407,7 @@ public class CommandCompletionTest extends ReplToolTesting {
// /set start
a -> assertCompletion(a, "/set st|", false, "start "),
a -> assertCompletion(a, "/set st |", false, p1.toArray(new String[p1.size()])),
a -> assertCompletion(a, "/set st |", 1),
// /set truncation
a -> assertCompletion(a, "/set tr|", false, "truncation "),
@ -447,12 +441,4 @@ public class CommandCompletionTest extends ReplToolTesting {
file.getFileName().toString().endsWith(".jar") ||
file.getFileName().toString().endsWith(".zip"));
private static Iterable<? extends Path> getRootDirectories() {
return StreamSupport.stream(FileSystems.getDefault()
.getRootDirectories()
.spliterator(),
false)
.filter(p -> Files.exists(p))
.collect(Collectors.toList());
}
}