Skip to content

Commit 0b21ff2

Browse files
committed
Improve enablement when running under GitHub actions/Jenkins
Previous commits aimed to disable tests when running on Jenkins and/or GitHub actions. However the conditions were too aggressive in some cases, causing tests to be skipped even when run locally by devs. This change aims to improve the enablements so that tests are only skipped on CI. `isRunningOnContinousIntegration` was unused, hence removed as it is related to this PR. Part of #2714
1 parent 8c5fcdd commit 0b21ff2

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/ClipboardBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class ClipboardBase {
4747
* <code>true</code>: skip tests <code>false</code>: don't skip tests
4848
* <code>null</code>: unknown whether to skip tests yet
4949
*/
50-
private static Boolean skipTestsRequiringButtonPress = (Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS"))
51-
|| System.getenv("JOB_NAME") != null) ? true : null;
50+
private static Boolean skipTestsRequiringButtonPress = (SwtTestUtil.isRunningOnGitHubActions()
51+
|| SwtTestUtil.isRunningOnJenkins()) ? true : null;
5252
private static int uniqueId = 1;
5353
protected Display display;
5454
protected Shell shell;

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestUtil.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.eclipse.swt.widgets.Listener;
5353
import org.eclipse.swt.widgets.Shell;
5454
import org.eclipse.test.Screenshots;
55+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
5556

5657
public class SwtTestUtil {
5758
/**
@@ -101,9 +102,41 @@ public class SwtTestUtil {
101102
public final static boolean isWindowsOS = System.getProperty("os.name").startsWith("Windows");
102103
public final static boolean isLinux = System.getProperty("os.name").equals("Linux");
103104

105+
private static boolean checkEnvVarMatches(String name, String regex) {
106+
String value = System.getenv(name);
107+
if (value == null) {
108+
return false;
109+
}
110+
return value.matches(regex);
111+
}
112+
113+
public static final String GITHUB_DETECT_ENV_VAR = "GITHUB_ACTIONS";
114+
public static final String GITHUB_DETECT_REGEX = "true";
115+
116+
/**
117+
* Return true if we are probably running on GitHub Actions.
118+
*
119+
* To enable or disable tests on Jenkins with annotations use
120+
* {@link EnabledIfEnvironmentVariable} and related classes with
121+
* {@link #GITHUB_DETECT_ENV_VAR} and {@link #GITHUB_DETECT_REGEX}
122+
*/
123+
public static boolean isRunningOnGitHubActions() {
124+
return checkEnvVarMatches(GITHUB_DETECT_ENV_VAR, GITHUB_DETECT_REGEX);
125+
}
104126

105-
/** Useful if you want some tests not to run on Jenkins with user "genie.platform" */
106-
public final static boolean isRunningOnContinousIntegration = isGTK && ("genie.platform".equalsIgnoreCase(System.getProperty("user.name")));
127+
public static final String JENKINS_DETECT_ENV_VAR = "JOB_NAME";
128+
public static final String JENKINS_DETECT_REGEX = ".*";
129+
130+
/**
131+
* Return true if we are probably running on Jenkins.
132+
*
133+
* To enable or disable tests on Jenkins with annotations use
134+
* {@link EnabledIfEnvironmentVariable} and related classes with
135+
* {@link #JENKINS_DETECT_ENV_VAR} and {@link #JENKINS_DETECT_REGEX}
136+
*/
137+
public static boolean isRunningOnJenkins() {
138+
return checkEnvVarMatches(JENKINS_DETECT_ENV_VAR, JENKINS_DETECT_REGEX);
139+
}
107140

108141
/**
109142
* Return whether running on x11. This is dynamically set at runtime and cannot

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package org.eclipse.swt.tests.junit;
1515

1616

17+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_ENV_VAR;
18+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_REGEX;
1719
import static org.eclipse.swt.tests.junit.SwtTestUtil.hasPixel;
1820
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1921
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -25,7 +27,6 @@
2527
import static org.junit.jupiter.api.Assertions.assertTrue;
2628
import static org.junit.jupiter.api.Assertions.fail;
2729
import static org.junit.jupiter.api.Assumptions.assumeFalse;
28-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2930

3031
import java.util.ArrayList;
3132
import java.util.Random;
@@ -80,6 +81,7 @@
8081
import org.junit.jupiter.api.BeforeEach;
8182
import org.junit.jupiter.api.Tag;
8283
import org.junit.jupiter.api.Test;
84+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
8385

8486
/**
8587
* Automated Test Suite for class org.eclipse.swt.custom.StyledText
@@ -5913,9 +5915,8 @@ public void test_arrowDownKeepsPositionAfterNewLine() {
59135915
*/
59145916
@Test
59155917
@Tag("gtk4-todo")
5918+
@DisabledIfEnvironmentVariable(named = JENKINS_DETECT_ENV_VAR, matches = JENKINS_DETECT_REGEX, disabledReason = "Display.post tests don't run reliably on Jenkins - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571")
59165919
public void test_backspaceAndDelete() throws InterruptedException {
5917-
assumeTrue(Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")),
5918-
"Display.post tests only run successfully on GitHub actions - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571");
59195920
shell.open();
59205921
text.setSize(10, 50);
59215922
// The display.post needs to successfully obtain the focused window (at least on GTK3)

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*******************************************************************************/
1515
package org.eclipse.swt.tests.junit;
1616

17+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_ENV_VAR;
18+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_REGEX;
1719
import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
1820
import static org.junit.jupiter.api.Assertions.assertEquals;
1921
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -49,8 +51,8 @@
4951
import org.junit.jupiter.api.Tag;
5052
import org.junit.jupiter.api.Test;
5153
import org.junit.jupiter.api.TestInfo;
54+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
5255
import org.junit.jupiter.api.condition.DisabledOnOs;
53-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
5456

5557
/**
5658
* Automated Test Suite for class org.eclipse.swt.widgets.Display
@@ -1042,7 +1044,7 @@ public void test_mapLorg_eclipse_swt_widgets_ControlLorg_eclipse_swt_widgets_Con
10421044
}
10431045

10441046
@Test
1045-
@EnabledIfEnvironmentVariable(named = "GITHUB_ACTIONS", matches = "true", disabledReason = "Display.post tests only run successfully on GitHub actions - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571")
1047+
@DisabledIfEnvironmentVariable(named = JENKINS_DETECT_ENV_VAR, matches = JENKINS_DETECT_REGEX, disabledReason = "Display.post tests don't run reliably on Jenkins - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571")
10461048
@Tag("gtk4-todo")
10471049
@Tag("gtk3-wayland-todo")
10481050
public void test_postLorg_eclipse_swt_widgets_Event() {

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_ENV_VAR;
17+
import static org.eclipse.swt.tests.junit.SwtTestUtil.JENKINS_DETECT_REGEX;
1618
import static org.junit.jupiter.api.Assertions.assertEquals;
1719
import static org.junit.jupiter.api.Assertions.assertFalse;
1820
import static org.junit.jupiter.api.Assertions.assertThrows;
1921
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2122

2223
import org.eclipse.swt.SWT;
2324
import org.eclipse.swt.events.ModifyListener;
@@ -37,6 +38,7 @@
3738
import org.junit.jupiter.api.BeforeEach;
3839
import org.junit.jupiter.api.Tag;
3940
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
4042

4143
/**
4244
* Automated Test Suite for class org.eclipse.swt.widgets.Text
@@ -1569,9 +1571,8 @@ private void doSegmentsTest (boolean isListening) {
15691571
*/
15701572
@Test
15711573
@Tag("gtk4-todo")
1574+
@DisabledIfEnvironmentVariable(named = JENKINS_DETECT_ENV_VAR, matches = JENKINS_DETECT_REGEX, disabledReason = "Display.post tests don't run reliably on Jenkins - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571")
15721575
public void test_backspaceAndDelete() throws InterruptedException {
1573-
assumeTrue(Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")),
1574-
"Display.post tests only run successfully on GitHub actions - see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2571");
15751576
shell.open();
15761577
text.setSize(10, 50);
15771578
// The display.post needs to successfully obtain the focused window (at least on GTK3)

0 commit comments

Comments
 (0)