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

Improving tests #220

Merged
merged 2 commits into from
Mar 28, 2023
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
11 changes: 11 additions & 0 deletions .github/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jdt.debug_.github</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
18 changes: 18 additions & 0 deletions .github/workflows/checkMergeCommits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on: pull_request

name: Check for merge commits

permissions:
pull-requests: read

jobs:
message-check:
name: Block Merge Commits

runs-on: ubuntu-latest

steps:
- name: Block Merge Commits
uses: Morishiri/block-merge-commits-action@a4554c78def8d874966a8d1e20e2971121443755
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import org.eclipse.jdt.debug.tests.ui.DebugHoverTests;
import org.eclipse.jdt.debug.tests.ui.DebugViewTests;
import org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests;
import org.eclipse.jdt.debug.tests.ui.JavaSnippetEditorTest;
import org.eclipse.jdt.debug.tests.ui.OpenFromClipboardTests;
import org.eclipse.jdt.debug.tests.ui.ViewManagementTests;
import org.eclipse.jdt.debug.tests.ui.presentation.ModelPresentationTests;
Expand Down Expand Up @@ -322,6 +323,9 @@ public AutomatedSuite() {
// Test was not stable, see bug 516024, the hope is that fix for bug 535686 helps
addTest(new TestSuite(DebugViewTests.class));

// Scrapbook editor tests
addTest(new TestSuite(JavaSnippetEditorTest.class));

// Debug hover tests
addTest(new TestSuite(DebugHoverTests.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ protected static void sync(Runnable r) throws RuntimeException {
catch (Exception t) {
error.set(t);
}
catch (Throwable t) {
error.set(new RuntimeException(t));
}
});
if (error.get() != null) {
throwException(error.get());
Expand Down Expand Up @@ -273,7 +276,7 @@ private static <T> T callInUi(Callable<T> callable) throws RuntimeException {
if (Display.getCurrent() != null) {
try {
return callable.call();
} catch (Exception e) {
} catch (Throwable e) {
throwException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2023 Andrey Loskutov (loskutov@gmx.de) and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrey Loskutov (loskutov@gmx.de) - initial API and implementation
*******************************************************************************/

package org.eclipse.jdt.debug.tests.ui;

import java.io.ByteArrayInputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.debug.ui.snippeteditor.JavaSnippetEditor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.test.OrderedTestSuite;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;

import junit.framework.Test;

public class JavaSnippetEditorTest extends AbstractDebugUiTests {

public static Test suite() {
return new OrderedTestSuite(JavaSnippetEditorTest.class);
}

private static final String EXPRESSION = "2 + 2";

private IJavaProject project;

private IFile scrapbook;

public JavaSnippetEditorTest(String name) {
super(name);
}

@Override
protected IJavaProject getProjectContext() {
return get18Project();
}

@Override
public void setUp() throws Exception {
super.setUp();
closeAllEditors();
project = getProjectContext();
scrapbook = project.getProject().getFile("scrapbook.jpage");
scrapbook.create(new ByteArrayInputStream(EXPRESSION.getBytes()), true, null);
}

@Override
public void tearDown() throws Exception {
closeAllEditors();
scrapbook.delete(true, null);
super.tearDown();
}

/**
* Tests if we can open scrapbook editor and evaluate 2+2 expression
*/
public void testEvaluation() throws Exception {
JavaSnippetEditor snippetEditor = (JavaSnippetEditor) openEditor(scrapbook);
processUiEvents();
IDocumentProvider documentProvider = snippetEditor.getDocumentProvider();
IDocument document = documentProvider.getDocument(new FileEditorInput(scrapbook));
String originalText = document.get();
assertEquals("Unexpected content", EXPRESSION, originalText);

// Select expression and trigger evaluation
sync(() -> {
ISelectionProvider selectionProvider = snippetEditor.getSelectionProvider();
selectionProvider.setSelection(new TextSelection(0, EXPRESSION.length()));
processUiEvents();
TextSelection selection = (TextSelection) selectionProvider.getSelection();
assertEquals("Wrong selection offset", 0, selection.getOffset());
assertEquals("Wrong selection line", 0, selection.getStartLine());
assertEquals("Wrong selection length", EXPRESSION.length(), selection.getLength());

// Starts evaluation that is supposed to write result directly to the editor
snippetEditor.evalSelection(JavaSnippetEditor.RESULT_DISPLAY);
});

// Evaluation runs in a separated thread (not a job), so let wait for it
long start = System.currentTimeMillis();
while (snippetEditor.isEvaluating() && System.currentTimeMillis() - start < 60_000) {
processUiEvents(1000);
}

String newText = document.get();
assertEquals("Editor should show evaluation result", EXPRESSION + "(int) 4", newText);
}

}
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Export-Package: org.eclipse.jdt.debug.ui,
org.eclipse.jdt.internal.debug.ui.monitors;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.propertypages;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.search;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.snippeteditor;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.snippeteditor;x-friends:="org.eclipse.jdt.debug.tests",
org.eclipse.jdt.internal.debug.ui.sourcelookup;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.threadgroups;x-internal:=true,
org.eclipse.jdt.internal.debug.ui.variables;x-internal:=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class JavaSnippetEditor extends AbstractDecoratedTextEditor implements ID
public final static int RESULT_RUN= 2;
public final static int RESULT_INSPECT= 3;

private int fResultMode; // one of the RESULT_* constants
private volatile int fResultMode; // one of the RESULT_* constants

private IJavaProject fJavaProject;
private IEvaluationContext fEvaluationContext;
Expand All @@ -150,9 +150,9 @@ public class JavaSnippetEditor extends AbstractDecoratedTextEditor implements ID
private IVMInstall fLaunchedVM;
private List<ISnippetStateChangedListener> fSnippetStateListeners;

private boolean fEvaluating;
private volatile boolean fEvaluating;
private IJavaThread fThread;
private boolean fStepFiltersSetting;
private volatile boolean fStepFiltersSetting;

private int fSnippetStart;
private int fSnippetEnd;
Expand Down