]> source.dussan.org Git - jgit.git/commitdiff
Fix unit tests on Windows 03/61203/2
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 24 Nov 2015 14:16:42 +0000 (15:16 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 26 Nov 2015 00:26:32 +0000 (01:26 +0100)
PushCommandTest and RunExternalScriptTest didn't succeed on Windows.
Fix this by expecting a simple line-feed as line ending (instead of the
platform dependent line separator. Additionally correct the computation
of expected URLs in PushCommandTest.

Change-Id: Idcdc41cd7e535ff88df33ea0a249333ed8fc91b0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java

index ccf1a51f1ba948722cc25d7f7f794098ce4637df..1fcfef9c716402c0fa7b85a9504b621f33a6fea9 100644 (file)
@@ -138,11 +138,9 @@ public class PushCommandTest extends RepositoryTestCase {
 
                RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
                git1.push().setRemote("test").setRefSpecs(spec).call();
-               assertEquals(
-                               "1:test, 2:file://" + db2.getDirectory().toPath() //
-                                               + "/, 3:\n" + "refs/heads/master " + commit.getName()
-                                               + " refs/heads/x " + ObjectId.zeroId().name(),
-                               read(hookOutput));
+               assertEquals("1:test, 2:" + uri + ", 3:\n" + "refs/heads/master "
+                               + commit.getName() + " refs/heads/x "
+                               + ObjectId.zeroId().name(), read(hookOutput));
        }
 
        private File writeHookFile(final String name, final String data)
index b6a2519c59474edd7d2be99459623d74a80975e6..7c0985ef424497a2a55a60c9a1918a1b24ed8531 100644 (file)
@@ -57,12 +57,12 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class RunExternalScriptTest {
+       private static final String LF = "\n";
+
        private ByteArrayOutputStream out;
 
        private ByteArrayOutputStream err;
 
-       private String sep = System.getProperty("line.separator");
-
        @Before
        public void setUp() throws Exception {
                out = new ByteArrayOutputStream();
@@ -74,7 +74,7 @@ public class RunExternalScriptTest {
                String inputStr = "a\nb\rc\r\nd";
                File script = writeTempFile("cat -");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath()), out, err,
+                               new ProcessBuilder("sh", script.getPath()), out, err,
                                new ByteArrayInputStream(inputStr.getBytes()));
                assertEquals(0, rc);
                assertEquals(inputStr, new String(out.toByteArray()));
@@ -85,7 +85,7 @@ public class RunExternalScriptTest {
        public void testCopyNullStdIn() throws IOException, InterruptedException {
                File script = writeTempFile("cat -");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath()), out, err,
+                               new ProcessBuilder("sh", script.getPath()), out, err,
                                (InputStream) null);
                assertEquals(0, rc);
                assertEquals("", new String(out.toByteArray()));
@@ -95,7 +95,8 @@ public class RunExternalScriptTest {
        @Test
        public void testArguments() throws IOException, InterruptedException {
                File script = writeTempFile("echo $#,$1,$2,$3,$4,$5,$6");
-               int rc = FS.DETECTED.runProcess(new ProcessBuilder("/bin/bash",
+               int rc = FS.DETECTED.runProcess(
+                               new ProcessBuilder("sh",
                                script.getPath(), "a", "b", "c"), out, err, (InputStream) null);
                assertEquals(0, rc);
                assertEquals("3,a,b,c,,,\n", new String(out.toByteArray()));
@@ -106,7 +107,7 @@ public class RunExternalScriptTest {
        public void testRc() throws IOException, InterruptedException {
                File script = writeTempFile("exit 3");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+                               new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
                                out, err, (InputStream) null);
                assertEquals(3, rc);
                assertEquals("", new String(out.toByteArray()));
@@ -117,7 +118,7 @@ public class RunExternalScriptTest {
        public void testNullStdout() throws IOException, InterruptedException {
                File script = writeTempFile("echo hi");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath()), null, err,
+                               new ProcessBuilder("sh", script.getPath()), null, err,
                                (InputStream) null);
                assertEquals(0, rc);
                assertEquals("", new String(out.toByteArray()));
@@ -128,11 +129,11 @@ public class RunExternalScriptTest {
        public void testStdErr() throws IOException, InterruptedException {
                File script = writeTempFile("echo hi >&2");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath()), null, err,
+                               new ProcessBuilder("sh", script.getPath()), null, err,
                                (InputStream) null);
                assertEquals(0, rc);
                assertEquals("", new String(out.toByteArray()));
-               assertEquals("hi" + sep, new String(err.toByteArray()));
+               assertEquals("hi" + LF, new String(err.toByteArray()));
        }
 
        @Test
@@ -140,11 +141,11 @@ public class RunExternalScriptTest {
                String inputStr = "a\nb\rc\r\nd";
                File script = writeTempFile("echo $#,$1,$2,$3,$4,$5,$6 >&2 ; cat -; exit 5");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+                               new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
                                out, err, new ByteArrayInputStream(inputStr.getBytes()));
                assertEquals(5, rc);
                assertEquals(inputStr, new String(out.toByteArray()));
-               assertEquals("3,a,b,c,,," + sep, new String(err.toByteArray()));
+               assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray()));
        }
 
        @Test(expected = IOException.class)
@@ -159,7 +160,7 @@ public class RunExternalScriptTest {
        public void testWrongScript() throws IOException, InterruptedException {
                File script = writeTempFile("cat-foo -");
                int rc = FS.DETECTED.runProcess(
-                               new ProcessBuilder("/bin/sh", script.getPath(), "a", "b", "c"),
+                               new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
                                out, err, (InputStream) null);
                assertEquals(127, rc);
        }
@@ -169,7 +170,7 @@ public class RunExternalScriptTest {
                        throws IOException, InterruptedException {
                String inputStr = "a\nb\rc\r\nd";
                File script = writeTempFile("cat -");
-               ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+               ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
                ExecutionResult res = FS.DETECTED.execute(pb,
                                new ByteArrayInputStream(inputStr.getBytes()));
                assertEquals(0, res.getRc());
@@ -180,11 +181,11 @@ public class RunExternalScriptTest {
        @Test
        public void testStdErrExecute() throws IOException, InterruptedException {
                File script = writeTempFile("echo hi >&2");
-               ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath());
+               ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
                ExecutionResult res = FS.DETECTED.execute(pb, null);
                assertEquals(0, res.getRc());
                assertEquals("", new String(res.getStdout().toByteArray()));
-               assertEquals("hi" + sep, new String(res.getStderr().toByteArray()));
+               assertEquals("hi" + LF, new String(res.getStderr().toByteArray()));
        }
 
        @Test
@@ -193,13 +194,13 @@ public class RunExternalScriptTest {
                String inputStr = "a\nb\rc\r\nd";
                File script = writeTempFile(
                                "echo $#,$1,$2,$3,$4,$5,$6 >&2 ; cat -; exit 5");
-               ProcessBuilder pb = new ProcessBuilder("/bin/sh", script.getPath(), "a",
+               ProcessBuilder pb = new ProcessBuilder("sh", script.getPath(), "a",
                                "b", "c");
                ExecutionResult res = FS.DETECTED.execute(pb,
                                new ByteArrayInputStream(inputStr.getBytes()));
                assertEquals(5, res.getRc());
                assertEquals(inputStr, new String(res.getStdout().toByteArray()));
-               assertEquals("3,a,b,c,,," + sep,
+               assertEquals("3,a,b,c,,," + LF,
                                new String(res.getStderr().toByteArray()));
        }