Skip to content

Commit

Permalink
tests: take screenshot before dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Oct 17, 2024
1 parent abffd92 commit 66bc2bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ public void testBug371100() {
}

@Rule
public TestWatcher screenshotRule = Screenshots.onFailure();
public TestWatcher screenshotRule = Screenshots.onFailure(null);

@Test
public void testBug372226() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestWatcher;
Expand Down Expand Up @@ -76,22 +76,18 @@
*/
public class TextViewerTest {

@Rule
public TestWatcher screenshotRule= Screenshots.onFailure();

private Shell fShell;

@After
public void tearDown() {
if (fShell != null && !fShell.isDisposed()) {
fShell.dispose();
}
fShell= null;
@Before
public void before() {
fShell= new Shell();
}

@Rule
public TestWatcher screenshotRule= Screenshots.onFailure(() -> fShell);

@Test
public void testSetRedraw_Bug441827() throws Exception {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Document document= new Document("abc");
textViewer.setDocument(document);
Expand All @@ -111,7 +107,6 @@ public void testSetRedraw_Bug441827() throws Exception {

@Test
public void testCaretMoveChangesSelection() throws Exception {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Document document= new Document("abc");
textViewer.setDocument(document);
Expand All @@ -129,7 +124,6 @@ public void testCaretMoveChangesSelection() throws Exception {

@Test
public void testGetCachedSelection() throws Exception {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Document document= new Document("abc");
textViewer.setDocument(document);
Expand All @@ -145,7 +139,6 @@ public void testGetCachedSelection() throws Exception {

@Test
public void testBlockSelectionAccessors() throws Exception {
fShell= new Shell();
ITextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Document document= new Document("0123\n4567\n89ab\ncdef");
textViewer.setDocument(document);
Expand Down Expand Up @@ -190,7 +183,6 @@ private void checkInAndOutUIThread(Runnable r) throws InterruptedException {
@Test
public void testCtrlHomeViewportListener() {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
fShell= new Shell();
fShell.setLayout(new FillLayout());
fShell.setSize(500, 200);
SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE);
Expand All @@ -213,7 +205,6 @@ protected boolean condition() {
@Test
public void testCtrlEndViewportListener() {
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
fShell= new Shell();
fShell.setLayout(new FillLayout());
fShell.setSize(500, 200);
SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE);
Expand All @@ -237,7 +228,6 @@ protected boolean condition() {
*/
@Test
public void testDefaultContentImplementation() {
fShell= new Shell();
final StyledTextContent content;
try {
final TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Expand Down Expand Up @@ -323,7 +313,6 @@ public static String generate5000Lines() {

@Test
public void testShiftLeft() {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
{
// Normal case, both lines match prefix
Expand Down Expand Up @@ -394,7 +383,6 @@ private void checkHyperlink(TextViewer textViewer, int pos, String text, String

@Test
public void testURLHyperlinkDetector() {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
checkHyperlink(textViewer, 3, "https://foo ", "[https://foo]");
checkHyperlink(textViewer, 0, "", "[]");
Expand All @@ -417,7 +405,6 @@ public void testURLHyperlinkDetector() {

@Test
public void testPasteMultiLines() {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
Document document= new Document();
textViewer.setDocument(document);
Expand All @@ -434,15 +421,13 @@ public void testPasteMultiLines() {

@Test
public void testSetSelectionNoDoc() {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
textViewer.setSelection(TextSelection.emptySelection());
// assert no exception is thrown
}

@Test
public void testSelectionFromViewerState() {
fShell= new Shell();
TextViewer textViewer= new TextViewer(fShell, SWT.NONE);
textViewer.setDocument(new Document(
"/**\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class CodeMiningTest {
private Shell fShell;

@Rule
public TestWatcher screenshotRule= Screenshots.onFailure();
public TestWatcher screenshotRule= Screenshots.onFailure(() -> fShell);

@Before
public void setUp() {
Expand Down Expand Up @@ -117,7 +117,6 @@ protected boolean condition() {

@After
public void tearDown() {
fShell.dispose();
fViewer = null;
}

Expand Down

0 comments on commit 66bc2bc

Please sign in to comment.