Skip to content

Commit

Permalink
Merge pull request #1973 from jglick/TarArchiverTest.permission
Browse files Browse the repository at this point in the history
Skip the test if the `tar` or `unzip` commands are not available
  • Loading branch information
jglick committed Jan 11, 2016
2 parents a7a8e30 + e61621c commit dda00aa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/src/test/java/hudson/util/io/TarArchiverTest.java
Expand Up @@ -32,7 +32,10 @@
import hudson.util.StreamTaskListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*;
import org.junit.Assume;
import static org.junit.Assume.*;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -76,7 +79,7 @@ public class TarArchiverTest {
e.mkdirs();

// extract via the tar command
assertEquals(0, new LocalLauncher(new StreamTaskListener(System.out)).launch().cmds("tar", "xvpf", tar.getAbsolutePath()).pwd(e).join());
run(e, "tar", "xvpf", tar.getAbsolutePath());

assertEquals(0100755,e.child("a.txt").mode());
assertEquals(dirMode,e.child("subdir").mode());
Expand All @@ -85,7 +88,7 @@ public class TarArchiverTest {

// extract via the zip command
e.deleteContents();
assertEquals(0, new LocalLauncher(new StreamTaskListener(System.out)).launch().cmds("unzip", zip.getAbsolutePath()).pwd(e).join());
run(e, "unzip", zip.getAbsolutePath());
e = e.listDirectories().get(0);

assertEquals(0100755, e.child("a.txt").mode());
Expand All @@ -98,6 +101,14 @@ public class TarArchiverTest {
}
}

private static void run(FilePath dir, String... cmds) throws InterruptedException {
try {
assertEquals(0, new LocalLauncher(StreamTaskListener.fromStdout()).launch().cmds(cmds).pwd(dir).join());
} catch (IOException x) { // perhaps restrict to x.message.contains("Cannot run program")? or "error=2, No such file or directory"?
Assume.assumeNoException("failed to run " + Arrays.toString(cmds), x);
}
}

@Issue("JENKINS-14922")
@Test public void brokenSymlinks() throws Exception {
assumeTrue(!Functions.isWindows());
Expand Down

0 comments on commit dda00aa

Please sign in to comment.