From 39903842575d3eadbec8c8153f79caa76c3f2c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Gond=C5=BEa?= Date: Wed, 30 Sep 2015 13:45:22 +0200 Subject: [PATCH] Do not skip tests silently --- core/src/test/java/hudson/FilePathTest.java | 3 ++- core/src/test/java/hudson/LauncherTest.java | 7 +++---- .../src/test/java/hudson/util/ProcessTreeTest.java | 6 +++--- .../groovy/hudson/model/AbstractProjectTest.groovy | 10 +++------- .../jenkins/model/PeepholePermalinkTest.groovy | 6 ++++-- .../hudson/model/DirectoryBrowserSupportTest.java | 3 ++- .../test/java/hudson/slaves/JNLPLauncherTest.java | 8 +++----- .../hudson/tasks/EnvVarsInConfigTasksTest.java | 10 ++++++---- test/src/test/java/hudson/tasks/ShellTest.java | 5 ++--- .../test/java/hudson/tools/JDKInstallerTest.java | 14 +++++--------- .../java/hudson/util/ProcessTreeKillerTest.java | 3 ++- 11 files changed, 35 insertions(+), 40 deletions(-) diff --git a/core/src/test/java/hudson/FilePathTest.java b/core/src/test/java/hudson/FilePathTest.java index daae3fcf6f..ed6ec0e9a5 100644 --- a/core/src/test/java/hudson/FilePathTest.java +++ b/core/src/test/java/hudson/FilePathTest.java @@ -58,6 +58,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Chmod; import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeFalse; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -464,7 +465,7 @@ public class FilePathTest { } @Test public void symlinkInTar() throws Exception { - if (Functions.isWindows()) return; // can't test on Windows + assumeFalse("can't test on Windows", Functions.isWindows()); FilePath tmp = new FilePath(temp.getRoot()); FilePath in = tmp.child("in"); diff --git a/core/src/test/java/hudson/LauncherTest.java b/core/src/test/java/hudson/LauncherTest.java index 84dde944f3..62ff200e96 100644 --- a/core/src/test/java/hudson/LauncherTest.java +++ b/core/src/test/java/hudson/LauncherTest.java @@ -34,6 +34,8 @@ import java.io.File; import jenkins.security.MasterToSlaveCallable; import org.apache.commons.io.FileUtils; import static org.junit.Assert.*; + +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -46,10 +48,7 @@ public class LauncherTest { @Issue("JENKINS-4611") @Test public void remoteKill() throws Exception { - if (File.pathSeparatorChar != ':') { - System.err.println("Skipping, currently Unix-specific test"); - return; - } + Assume.assumeFalse("Skipping, currently Unix-specific test", Functions.isWindows()); File tmp = temp.newFile(); diff --git a/core/src/test/java/hudson/util/ProcessTreeTest.java b/core/src/test/java/hudson/util/ProcessTreeTest.java index f3d5d3e6f2..d4c8fed7de 100644 --- a/core/src/test/java/hudson/util/ProcessTreeTest.java +++ b/core/src/test/java/hudson/util/ProcessTreeTest.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.io.Serializable; import jenkins.security.MasterToSlaveCallable; import static org.junit.Assert.*; + +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; @@ -26,9 +28,7 @@ public class ProcessTreeTest { } @Test public void remoting() throws Exception { - // on some platforms where we fail to list any processes, this test will just not work - if (ProcessTree.get()==ProcessTree.DEFAULT) - return; + Assume.assumeFalse("on some platforms where we fail to list any processes", ProcessTree.get()==ProcessTree.DEFAULT); Tag t = channels.french.call(new MyCallable()); diff --git a/test/src/test/groovy/hudson/model/AbstractProjectTest.groovy b/test/src/test/groovy/hudson/model/AbstractProjectTest.groovy index fe6c39351b..dd99ae7f13 100644 --- a/test/src/test/groovy/hudson/model/AbstractProjectTest.groovy +++ b/test/src/test/groovy/hudson/model/AbstractProjectTest.groovy @@ -54,7 +54,7 @@ import org.jvnet.hudson.test.TestExtension; import org.jvnet.hudson.test.recipes.PresetData; import org.jvnet.hudson.test.recipes.PresetData.DataSet import org.apache.commons.io.FileUtils; - +import org.junit.Assume; import org.jvnet.hudson.test.MockFolder /** @@ -224,9 +224,7 @@ public class AbstractProjectTest extends HudsonTestCase { @Issue("JENKINS-1986") public void testBuildSymlinks() { - // If we're on Windows, don't bother doing this. - if (Functions.isWindows()) - return; + Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows()); def job = createFreeStyleProject(); job.buildersList.add(new Shell("echo \"Build #\$BUILD_NUMBER\"\n")); @@ -260,9 +258,7 @@ public class AbstractProjectTest extends HudsonTestCase { @Issue("JENKINS-2543") public void testSymlinkForPostBuildFailure() { - // If we're on Windows, don't bother doing this. - if (Functions.isWindows()) - return; + Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows()); // Links should be updated after post-build actions when final build result is known def job = createFreeStyleProject(); diff --git a/test/src/test/groovy/jenkins/model/PeepholePermalinkTest.groovy b/test/src/test/groovy/jenkins/model/PeepholePermalinkTest.groovy index 35d25a072d..a500677a9f 100644 --- a/test/src/test/groovy/jenkins/model/PeepholePermalinkTest.groovy +++ b/test/src/test/groovy/jenkins/model/PeepholePermalinkTest.groovy @@ -2,6 +2,8 @@ package jenkins.model import static org.junit.Assert.assertTrue +import org.junit.Assume; + import hudson.Functions import hudson.Util import hudson.model.Run @@ -24,7 +26,7 @@ class PeepholePermalinkTest { */ @Test void basics() { - if (Functions.isWindows()) return; // can't run on windows because we rely on symlinks + Assume.assumeFalse("can't run on windows because we rely on symlinks", Functions.isWindows()); def p = j.createFreeStyleProject() def b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)) @@ -71,7 +73,7 @@ class PeepholePermalinkTest { */ @Test void legacyCompatibility() { - if (Functions.isWindows()) return; // can't run on windows because we rely on symlinks + Assume.assumeFalse("can't run on windows because we rely on symlinks", Functions.isWindows()); def p = j.createFreeStyleProject() def b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)) diff --git a/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java b/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java index fc07a335b0..244189e246 100644 --- a/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java +++ b/test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java @@ -40,6 +40,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipFile; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Issue; @@ -94,7 +95,7 @@ public class DirectoryBrowserSupportTest { @Email("http://www.nabble.com/Status-Code-400-viewing-or-downloading-artifact-whose-filename-contains-two-consecutive-periods-tt21407604.html") @Test public void doubleDots2() throws Exception { - if(Functions.isWindows()) return; // can't test this on Windows + Assume.assumeFalse("can't test this on Windows", Functions.isWindows()); // create a problematic file name in the workspace FreeStyleProject p = j.createFreeStyleProject(); diff --git a/test/src/test/java/hudson/slaves/JNLPLauncherTest.java b/test/src/test/java/hudson/slaves/JNLPLauncherTest.java index 7184b1e147..cf9df8e051 100644 --- a/test/src/test/java/hudson/slaves/JNLPLauncherTest.java +++ b/test/src/test/java/hudson/slaves/JNLPLauncherTest.java @@ -36,6 +36,8 @@ import hudson.remoting.Which; import hudson.util.ArgumentListBuilder; import jenkins.security.SlaveToMasterCallable; + +import org.junit.Assume; import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.TestExtension; @@ -55,12 +57,8 @@ public class JNLPLauncherTest extends HudsonTestCase { * Starts a JNLP slave agent and makes sure it successfully connects to Hudson. */ public void testLaunch() throws Exception { - if(GraphicsEnvironment.isHeadless()) { - System.err.println("Skipping JNLPLauncherTest.testLaunch because we are running headless"); - return; - } + Assume.assumeFalse("Skipping JNLPLauncherTest.testLaunch because we are running headless", GraphicsEnvironment.isHeadless()); - System.err.println("Not in headless mode, continuing with JNLPLauncherTest.testLaunch..."); Computer c = addTestSlave(); launchJnlpAndVerify(c, buildJnlpArgs(c)); } diff --git a/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java b/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java index 532ec1454c..fb5b7e2e1e 100644 --- a/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java +++ b/test/src/test/java/hudson/tasks/EnvVarsInConfigTasksTest.java @@ -14,6 +14,7 @@ import hudson.tasks.Ant.AntInstallation; import hudson.tasks.Maven.MavenInstallation; import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Assume; import org.jvnet.hudson.test.ExtractResourceSCM; import org.jvnet.hudson.test.HudsonTestCase; import static hudson.tasks._ant.Messages.Ant_ExecutableNotFound; @@ -92,10 +93,11 @@ public class EnvVarsInConfigTasksTest extends HudsonTestCase { } public void testFreeStyleAntOnSlave() throws Exception { - if (jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations().length == 0) { - System.out.println("Cannot do testFreeStyleAntOnSlave without ANT_HOME"); - return; - } + Assume.assumeFalse( + "Cannot do testFreeStyleAntOnSlave without ANT_HOME", + jenkins.getDescriptorByType(Ant.DescriptorImpl.class).getInstallations().length == 0 + ); + FreeStyleProject project = createFreeStyleProject(); project.setJDK(jenkins.getJDK("varJDK")); project.setScm(new ExtractResourceSCM(getClass().getResource( diff --git a/test/src/test/java/hudson/tasks/ShellTest.java b/test/src/test/java/hudson/tasks/ShellTest.java index 3edd014a48..b92ca772b7 100644 --- a/test/src/test/java/hudson/tasks/ShellTest.java +++ b/test/src/test/java/hudson/tasks/ShellTest.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.List; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -45,9 +46,7 @@ public class ShellTest { @Test public void testBasic() throws Exception { - // If we're on Windows, don't bother doing this. - if (Functions.isWindows()) - return; + Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows()); // TODO: define a FakeLauncher implementation with easymock so that this kind of assertions can be simplified. PretendSlave s = rule.createPretendSlave(new FakeLauncher() { diff --git a/test/src/test/java/hudson/tools/JDKInstallerTest.java b/test/src/test/java/hudson/tools/JDKInstallerTest.java index 8f7bf1cf65..c91f1cc112 100644 --- a/test/src/test/java/hudson/tools/JDKInstallerTest.java +++ b/test/src/test/java/hudson/tools/JDKInstallerTest.java @@ -7,6 +7,8 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlFormUtil; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.tools.JDKInstaller.DescriptorImpl; + +import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -105,9 +107,7 @@ public class JDKInstallerTest { */ @Test public void locate() throws Exception { - // this is a really time consuming test, so only run it when we really want. - if(!Boolean.getBoolean("jenkins.testJDKInstaller")) - return; + Assume.assumeTrue("this is a really time consuming test, so only run it when we really want", Boolean.getBoolean("jenkins.testJDKInstaller")); retrieveUpdateCenterData(); @@ -148,9 +148,7 @@ public class JDKInstallerTest { * End-to-end installation test. */ private void doTestAutoInstallation(String id, String fullversion) throws Exception { - // this is a really time consuming test, so only run it when we really want - if(!Boolean.getBoolean("jenkins.testJDKInstaller")) - return; + Assume.assumeTrue("this is a really time consuming test, so only run it when we really want", Boolean.getBoolean("jenkins.testJDKInstaller")); retrieveUpdateCenterData(); @@ -177,9 +175,7 @@ public class JDKInstallerTest { */ @Test public void fakeUnixInstall() throws Exception { - // If we're on Windows, don't bother doing this. - if (Functions.isWindows()) - return; + Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows()); File bundle = File.createTempFile("fake-jdk-by-hudson","sh"); try { diff --git a/test/src/test/java/hudson/util/ProcessTreeKillerTest.java b/test/src/test/java/hudson/util/ProcessTreeKillerTest.java index adf4c91277..1763c4662e 100644 --- a/test/src/test/java/hudson/util/ProcessTreeKillerTest.java +++ b/test/src/test/java/hudson/util/ProcessTreeKillerTest.java @@ -10,6 +10,7 @@ import hudson.tasks.Maven; import hudson.tasks.Shell; import hudson.util.ProcessTreeRemoting.IOSProcess; import org.junit.After; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.ExtractResourceSCM; @@ -56,7 +57,7 @@ public class ProcessTreeKillerTest { @Issue("JENKINS-22641") public void processProperlyKilledUnix() throws Exception { ProcessTree.enabled = true; - if (Functions.isWindows()) return; // This test does not involve windows. + Assume.assumeFalse("This test does not involve windows", Functions.isWindows()); FreeStyleProject sleepProject = j.createFreeStyleProject(); FreeStyleProject processJob = j.createFreeStyleProject();