Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail on Windows #1661

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,11 @@ public static String toGlobPattern(IPath path, boolean recursive) {
return globPattern;
}

public static String dos2Unix(String str) {
if (str != null && Platform.OS_WIN32.equals(Platform.getOS())) {
str = str.replaceAll("\\r", "");
}
return str;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public class OverrideMethodsTestCase extends AbstractSourceTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
fCuA.delete(true, null);

ICompilationUnit cu = fPackageP.getCompilationUnit("A.java");
ICompilationUnit cu = fCuA;
fClassA = cu.createType("public abstract class A {\n}\n", null, true, null);
fClassA.createMethod("public abstract void a();\n", null, true, null);
fClassA.createMethod("public abstract void b(java.util.Vector<java.util.Date> v);\n", null, true, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.TextEditUtil;
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler;
import org.eclipse.jdt.ls.core.internal.handlers.DiagnosticsHandler;
Expand Down Expand Up @@ -207,6 +208,7 @@ public void assertEquivalent(Either<Command, CodeAction> action) throws Exceptio
assertEquals(title + " has the wrong kind ", kind, action.getRight().getKind());
}
String actionContent = evaluateCodeActionCommand(action);
actionContent = ResourceUtils.dos2Unix(actionContent);
assertEquals(title + " has the wrong content ", content, actionContent);
}
}
Expand Down Expand Up @@ -301,9 +303,9 @@ protected String evaluateCodeActionCommand(Either<Command, CodeAction> codeActio
Assert.assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
WorkspaceEdit we = (WorkspaceEdit) c.getArguments().get(0);
if (we.getDocumentChanges() != null) {
return evaluateChanges(we.getDocumentChanges());
return ResourceUtils.dos2Unix(evaluateChanges(we.getDocumentChanges()));
}
return evaluateChanges(we.getChanges());
return ResourceUtils.dos2Unix(evaluateChanges(we.getChanges()));
}

private String evaluateChanges(List<Either<TextDocumentEdit, ResourceOperation>> documentChanges) throws BadLocationException, JavaModelException {
Expand All @@ -313,15 +315,15 @@ private String evaluateChanges(List<Either<TextDocumentEdit, ResourceOperation>>
assertEquals("Only one resource should be modified", 1, uris.size());
String uri = uris.iterator().next();
List<TextEdit> edits = changes.stream().flatMap(e -> e.getEdits().stream()).collect(Collectors.toList());
return evaluateChanges(uri, edits);
return ResourceUtils.dos2Unix(evaluateChanges(uri, edits));
}

protected String evaluateChanges(Map<String, List<TextEdit>> changes) throws BadLocationException, JavaModelException {
Iterator<Entry<String, List<TextEdit>>> editEntries = changes.entrySet().iterator();
Entry<String, List<TextEdit>> entry = editEntries.next();
assertNotNull("No edits generated", entry);
assertEquals("More than one resource modified", false, editEntries.hasNext());
return evaluateChanges(entry.getKey(), entry.getValue());
return ResourceUtils.dos2Unix(evaluateChanges(entry.getKey(), entry.getValue()));
}

private String evaluateChanges(String uri, List<TextEdit> edits) throws BadLocationException, JavaModelException {
Expand All @@ -332,15 +334,15 @@ private String evaluateChanges(String uri, List<TextEdit> edits) throws BadLocat
if (cu.exists()) {
doc.set(cu.getSource());
}
return TextEditUtil.apply(doc, edits);
return ResourceUtils.dos2Unix(TextEditUtil.apply(doc, edits));
}

public Command getCommand(Either<Command, CodeAction> codeAction) {
return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}

public String getTitle(Either<Command, CodeAction> codeAction) {
return getCommand(codeAction).getTitle();
return ResourceUtils.dos2Unix(getCommand(codeAction).getTitle());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void setup() throws Exception{

protected ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException {
ICompilationUnit workingCopy = getCompilationUnit(path);
workingCopy.getWorkingCopy(wcOwner, monitor);
// workingCopy.getWorkingCopy(wcOwner, monitor);
workingCopy.becomeWorkingCopy(monitor);
workingCopy.getBuffer().setContents(source);
workingCopy.makeConsistent(monitor);
return workingCopy;
Expand All @@ -75,5 +76,13 @@ protected int[] findCompletionLocation(ICompilationUnit unit, String completeBeh
@After
public void shutdown() throws Exception {
CoreASTProvider.getInstance().disposeAST();
ICompilationUnit[] workingCopies = JavaCore.getWorkingCopies(wcOwner);
for (ICompilationUnit workingCopy : workingCopies) {
workingCopy.discardWorkingCopy();
}
workingCopies = JavaCore.getWorkingCopies(null);
for (ICompilationUnit workingCopy : workingCopies) {
workingCopy.discardWorkingCopy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand Down Expand Up @@ -92,7 +93,12 @@ public void testClasspathUpdateForMaven() throws Exception {
verify(connection, times(1)).sendEventNotification(argument.capture());
assertEquals(EventType.ClasspathUpdated, argument.getValue().getType());
// Use Paths.get() to normalize the URI: ignore the tailing slash, "/project/path" and "/project/path/" should be the same.
assertEquals(Paths.get(project.getLocationURI().toString()), Paths.get((String) argument.getValue().getData()));
// Paths.get(URI) doesn't work on Windows
assertEquals(Paths.get(project.getLocation().toOSString()), Paths.get(getData(argument)));
}

private String getData(ArgumentCaptor<EventNotification> argument) {
return new org.eclipse.core.runtime.Path(URI.create((String) argument.getValue().getData()).getPath()).toOSString();
}

@Test
Expand All @@ -111,7 +117,7 @@ public void testClasspathUpdateForGradle() throws Exception {
ArgumentCaptor<EventNotification> argument = ArgumentCaptor.forClass(EventNotification.class);
verify(connection, times(1)).sendEventNotification(argument.capture());
assertEquals(EventType.ClasspathUpdated, argument.getValue().getType());
assertEquals(Paths.get(project.getLocationURI().toString()), Paths.get((String) argument.getValue().getData()));
assertEquals(Paths.get(project.getLocation().toOSString()), Paths.get(getData(argument)));
}

@Test
Expand All @@ -128,7 +134,7 @@ public void testClasspathUpdateForEclipse() throws Exception {
ArgumentCaptor<EventNotification> argument = ArgumentCaptor.forClass(EventNotification.class);
verify(connection, times(1)).sendEventNotification(argument.capture());
assertEquals(EventType.ClasspathUpdated, argument.getValue().getType());
assertEquals(Paths.get(project.getLocationURI().toString()), Paths.get((String) argument.getValue().getData()));
assertEquals(Paths.get(project.getLocation().toOSString()), Paths.get(getData(argument)));
}

@Test
Expand All @@ -147,7 +153,7 @@ public void testClasspathUpdateForInvisble() throws Exception {
ArgumentCaptor<EventNotification> argument = ArgumentCaptor.forClass(EventNotification.class);
verify(connection, times(1)).sendEventNotification(argument.capture());
assertEquals(EventType.ClasspathUpdated, argument.getValue().getType());
assertEquals(Paths.get(projectFolder.toURI().toString()), Paths.get((String) argument.getValue().getData()));

assertEquals(Paths.get(projectFolder.getAbsolutePath()), Paths.get(getData(argument)));
// assertEquals(projectFolder.toURI(), URI.create((String) argument.getValue().getData()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void test_filterTypes() throws Exception {
@Test
public void testCodeAction_ignoringOtherDiagnosticWithoutCode() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "import java.sql.*; \n" + "public class Foo {\n" + " void foo() {\n" + " }\n" + "}\n");

//unit.save(new NullProgressMonitor(), true);
CodeActionParams params = new CodeActionParams();
params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
final Range range = CodeActionUtil.getRange(unit, "java.sql");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.JsonMessageHelper;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.TextEditUtil;
import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
import org.eclipse.jdt.ls.core.internal.contentassist.JavadocCompletionProposal;
Expand Down Expand Up @@ -1267,7 +1268,7 @@ public void testSnippet_interface() throws JavaModelException {
CompletionItem item = items.get(9);
assertEquals("interface", item.getLabel());
String te = item.getInsertText();
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic interface Test {\n\n\t${0}\n}", te);
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic interface Test {\n\n\t${0}\n}", ResourceUtils.dos2Unix(te));

//check resolution doesn't blow up (https://github.com/eclipse/eclipse.jdt.ls/issues/675)
assertSame(item, server.resolveCompletionItem(item).join());
Expand Down Expand Up @@ -1366,7 +1367,7 @@ public void testSnippet_class() throws JavaModelException {
CompletionItem item = items.get(8);
assertEquals("class", item.getLabel());
String te = item.getInsertText();
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic class Test {\n\n\t${0}\n}", te);
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic class Test {\n\n\t${0}\n}", ResourceUtils.dos2Unix(te));
}

@Test
Expand Down Expand Up @@ -1477,7 +1478,7 @@ public void testSnippet_record() throws Exception {
CompletionItem item = items.get(11);
assertEquals("record", item.getLabel());
String te = item.getInsertText();
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic record Test(${0}) {\n}", te);
assertEquals("package org.sample;\n\n/**\n * Test\n */\npublic record Test(${0}) {\n}", ResourceUtils.dos2Unix(te));

//check resolution doesn't blow up (https://github.com/eclipse/eclipse.jdt.ls/issues/675)
assertSame(item, server.resolveCompletionItem(item).join());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public void testHoverOnJavadocWithMultipleDifferentTypesOfTags() throws Exceptio
project = WorkspaceHelper.getProject("salut");
handler = new HoverHandler(preferenceManager);
//given
String payload = createHoverRequest("src/main/java/java/Foo2.java", 44, 24);
String payload = createHoverRequest("src/main/java/java/Foo2.java", 44, 25);
TextDocumentPositionParams position = getParams(payload);

// when
Expand Down Expand Up @@ -498,7 +498,7 @@ public void testHoverOnJavadocWithMultipleDifferentTypesOfTags() throws Exceptio
" \\* This is a note";

//@formatter:on
assertMatches(expectedJavadoc, content);
assertMatches(expectedJavadoc, ResourceUtils.dos2Unix(content));
}

@Test
Expand All @@ -508,7 +508,7 @@ public void testHoverWhenLinkDoesNotExist() throws Exception {
handler = new HoverHandler(preferenceManager);

//given
String payload = createHoverRequest("src/main/java/java/Foo2.java", 51, 25);
String payload = createHoverRequest("src/main/java/java/Foo2.java", 51, 26);
TextDocumentPositionParams position = getParams(payload);

// when
Expand Down Expand Up @@ -553,7 +553,9 @@ public void testHoverJavadocWithExtraTags() throws Exception {
" * java.sql.Driver\n" +
" * **@moduleGraph**";
//@formatter:on
assertEquals("Unexpected hover ", expectedJavadoc, hover.getContents().getLeft().get(1).getLeft());
String actual = hover.getContents().getLeft().get(1).getLeft();
actual = ResourceUtils.dos2Unix(actual);
assertEquals("Unexpected hover ", expectedJavadoc, actual);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.TextEditUtil;
import org.eclipse.jdt.ls.core.internal.WorkspaceHelper;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void testWillSaveWaitUntil() throws Exception {

Document doc = new Document();
doc.set(cu.getSource());
assertEquals(TextEditUtil.apply(doc, result), buf.toString());
assertEquals(buf.toString(), ResourceUtils.dos2Unix(TextEditUtil.apply(doc, result)));
}

@Test
Expand Down Expand Up @@ -116,7 +117,7 @@ public void testStaticWillSaveWaitUntil() throws Exception {
List<TextEdit> result = handler.willSaveWaitUntil(params, monitor);
Document doc = new Document();
doc.set(cu.getSource());
assertEquals(expected, TextEditUtil.apply(doc, result));
assertEquals(expected, ResourceUtils.dos2Unix(TextEditUtil.apply(doc, result)));
} finally {
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setJavaCompletionFavoriteMembers(Arrays.asList(favourites));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.Messages;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -244,7 +243,7 @@ public void testProjectLevelMarkers() throws Exception {
List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
Collections.reverse(allCalls);
projectsManager.setConnection(client);
Optional<PublishDiagnosticsParams> projectDiags = allCalls.stream().filter(p -> p.getUri().endsWith("maven/broken")).findFirst();
Optional<PublishDiagnosticsParams>projectDiags=allCalls.stream().filter(p->(p.getUri().endsWith("maven/broken"))||p.getUri().endsWith("maven/broken/")))).findFirst();
assertTrue("No maven/broken errors were found", projectDiags.isPresent());
List<Diagnostic> diags = projectDiags.get().getDiagnostics();
Collections.sort(diags, DIAGNOSTICS_COMPARATOR);
Expand Down Expand Up @@ -300,7 +299,7 @@ public void testMissingNatures() throws Exception {
List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
Collections.reverse(allCalls);
projectsManager.setConnection(client);
Optional<PublishDiagnosticsParams> projectDiags = allCalls.stream().filter(p -> p.getUri().endsWith("eclipse/wtpproject")).findFirst();
Optional<PublishDiagnosticsParams> projectDiags = allCalls.stream().filter(p -> (p.getUri().endsWith("eclipse/wtpproject")) || p.getUri().endsWith("eclipse/wtpproject/")).findFirst();
assertTrue(projectDiags.isPresent());
assertEquals("Unexpected diagnostics:\n" + projectDiags.get().getDiagnostics(), 0, projectDiags.get().getDiagnostics().size());
}
Expand All @@ -326,7 +325,7 @@ public void testProjectConfigurationIsNotUpToDate() throws Exception {
List<PublishDiagnosticsParams> allCalls = captor.getAllValues();
Collections.reverse(allCalls);
projectsManager.setConnection(client);
Optional<PublishDiagnosticsParams> projectDiags = allCalls.stream().filter(p -> p.getUri().endsWith("maven/salut")).findFirst();
Optional<PublishDiagnosticsParams>projectDiags=allCalls.stream().filter(p->(p.getUri().endsWith("maven/salut"))||p.getUri().endsWith("maven/salut/")))).findFirst();
assertTrue("No maven/salut errors were found", projectDiags.isPresent());
List<Diagnostic> diags = projectDiags.get().getDiagnostics();
assertEquals(diags.toString(), 2, diags.size());
Expand Down Expand Up @@ -388,7 +387,7 @@ private void testDiagnostic(List<PublishDiagnosticsParams> allCalls) {
List<Diagnostic> projectDiags = new ArrayList<>();
List<Diagnostic> pomDiags = new ArrayList<>();
for (PublishDiagnosticsParams diag : allCalls) {
if (diag.getUri().endsWith("maven/salut")) {
if (diag.getUri().endsWith("maven/salut") || diag.getUri().endsWith("maven/salut/")) {
projectDiags.addAll(diag.getDiagnostics());
} else if (diag.getUri().endsWith("pom.xml")) {
pomDiags.addAll(diag.getDiagnostics());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.Util;
import org.junit.Test;

Expand Down Expand Up @@ -174,46 +175,46 @@ public void testSeeTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_SEE);
String convertedMarkdown = converter.getAsString();

assertEquals(" * **See Also:**\n \n * [Online docs for java](https://docs.oracle.com/javase/7/docs/api/)", convertedMarkdown);
assertEquals(" * **See Also:**\n \n * [Online docs for java](https://docs.oracle.com/javase/7/docs/api/)", ResourceUtils.dos2Unix(convertedMarkdown));
}

@Test
public void testParamTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_PARAM);
String convertedMarkdown = converter.getAsString();

assertEquals(" * **Parameters:**\n \n * **someString** the string to enter", convertedMarkdown);
assertEquals(" * **Parameters:**\n \n * **someString** the string to enter", ResourceUtils.dos2Unix(convertedMarkdown));
}

@Test
public void testSinceTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_SINCE);
String convertedMarkdown = converter.getAsString();

assertEquals(" * **Since:**\n \n * 0.0.1", convertedMarkdown);
assertEquals(" * **Since:**\n \n * 0.0.1", ResourceUtils.dos2Unix(convertedMarkdown));
}

@Test
public void testVersionTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_VERSION);
String convertedMarkdown = converter.getAsString();

assertEquals(" * @version\n \n * 0.0.1", convertedMarkdown);
assertEquals(" * @version\n \n * 0.0.1", ResourceUtils.dos2Unix(convertedMarkdown));
}

@Test
public void testThrowsTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_THROWS);
String convertedMarkdown = converter.getAsString();

assertEquals(" * **Throws:**\n \n * IOException", convertedMarkdown);
assertEquals(" * **Throws:**\n \n * IOException", ResourceUtils.dos2Unix(convertedMarkdown));
}

@Test
public void testAuthorTag() throws IOException {
JavaDoc2MarkdownConverter converter = new JavaDoc2MarkdownConverter(RAW_JAVADOC_HTML_AUTHOR);
String convertedMarkdown = converter.getAsString();

assertEquals(" * **Author:**\n \n * someAuthor", convertedMarkdown);
assertEquals(" * **Author:**\n \n * someAuthor", ResourceUtils.dos2Unix(convertedMarkdown));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ public void cleanUp() throws Exception {
Platform.removeLogListener(logListener);
logListener = null;
WorkspaceHelper.deleteAllProjects();
FileUtils.forceDelete(getWorkingProjectDirectory());
try {
// https://github.com/eclipse/eclipse.jdt.ls/issues/996
FileUtils.forceDelete(getWorkingProjectDirectory());
} catch (IOException e) {
getWorkingProjectDirectory().deleteOnExit();
}
Job.getJobManager().setProgressProvider(null);
waitForBackgroundJobs();
}
Expand Down
Loading