Skip to content

Commit

Permalink
8295814: jdk/jshell/CommandCompletionTest.java fails with "lists don'…
Browse files Browse the repository at this point in the history
…t have the same size expected [2] but found [1]"

Reviewed-by: jlahoda
  • Loading branch information
asotona committed Nov 15, 2022
1 parent d0fae43 commit a45c9af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
1 change: 0 additions & 1 deletion test/langtools/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

###########################################################################
#
Expand Down
54 changes: 20 additions & 34 deletions test/langtools/jdk/jshell/CommandCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +73,16 @@ protected void testRawRun(Locale locale, String[] args) {
}
}

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");
Expand All @@ -86,8 +93,9 @@ public void assertCompletion(boolean after, String code, boolean isSmart, String

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) {
Expand Down Expand Up @@ -272,16 +280,12 @@ public void testOpen() throws IOException {
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)
);
}

Expand All @@ -291,20 +295,13 @@ public void testSave() throws IOException {
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)
);
}

Expand Down Expand Up @@ -376,9 +373,6 @@ public void testUserHome() throws IOException {

@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"};
Expand All @@ -389,7 +383,7 @@ public void testSet() throws IOException {

// /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 "),
Expand All @@ -413,7 +407,7 @@ public void testSet() throws IOException {

// /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 "),
Expand Down Expand Up @@ -447,12 +441,4 @@ private List<String> listFiles(Path path, Predicate<? super Path> filter) throws
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());
}
}

1 comment on commit a45c9af

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.