From 02ade82b345ea976d12c32547fb097e726fa44fb Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 31 Dec 2015 00:48:07 +0100 Subject: Make sure tests don't blindly continue if a command is "silently" failed Make the default execute() function fail fast on first command printed "fatal: " to output. Introduced executeUnchecked() for few tests which wanted to test fatal output. Change-Id: I5b09aad9443515636811fc4d00bf8b8b9587a626 Signed-off-by: Andrey Loskutov --- .../tst/org/eclipse/jgit/pgm/AddTest.java | 2 +- .../tst/org/eclipse/jgit/pgm/ArchiveTest.java | 3 ++- .../tst/org/eclipse/jgit/pgm/BranchTest.java | 2 +- .../tst/org/eclipse/jgit/pgm/CheckoutTest.java | 4 ++-- .../tst/org/eclipse/jgit/pgm/CommitTest.java | 12 ------------ .../tst/org/eclipse/jgit/pgm/DescribeTest.java | 6 +++--- .../tst/org/eclipse/jgit/pgm/MergeTest.java | 4 ++-- .../tst/org/eclipse/jgit/pgm/RepoTest.java | 2 +- .../tst/org/eclipse/jgit/pgm/TagTest.java | 2 +- 9 files changed, 13 insertions(+), 24 deletions(-) (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm') diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java index ca3f00f49d..5970913693 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/AddTest.java @@ -65,7 +65,7 @@ public class AddTest extends CLIRepositoryTestCase { @Test public void testAddNothing() throws Exception { assertEquals("fatal: Argument \"filepattern\" is required", // - execute("git add")[0]); + executeUnchecked("git add")[0]); } @Test diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index 9aca2d8236..2e02c762bd 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -102,7 +102,8 @@ public class ArchiveTest extends CLIRepositoryTestCase { @Test public void testUnrecognizedFormat() throws Exception { String[] expect = new String[] { "fatal: Unknown archive format 'nonsense'" }; - String[] actual = execute("git archive --format=nonsense " + emptyTree); + String[] actual = executeUnchecked( + "git archive --format=nonsense " + emptyTree); assertArrayEquals(expect, actual); } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java index 4200cd05cf..f369577ba0 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BranchTest.java @@ -89,6 +89,6 @@ public class BranchTest extends CLIRepositoryTestCase { @Test public void testExistingBranch() throws Exception { assertEquals("fatal: A branch named 'master' already exists.", - execute("git branch master")[0]); + executeUnchecked("git branch master")[0]); } } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index 167d8ab512..6175b6c06a 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -109,13 +109,13 @@ public class CheckoutTest extends CLIRepositoryTestCase { assertStringArrayEquals( "fatal: A branch named 'master' already exists.", - execute("git checkout -b master")); + executeUnchecked("git checkout -b master")); } @Test public void testCheckoutNewBranchOnBranchToBeBorn() throws Exception { assertStringArrayEquals("fatal: You are on a branch yet to be born", - execute("git checkout -b side")); + executeUnchecked("git checkout -b side")); } @Test diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java index 360ee5a6ef..721ed15695 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CommitTest.java @@ -98,16 +98,4 @@ public class CommitTest extends CLIRepositoryTestCase { result.trim().equals("On branch master")); } - String toString(String[] arr) { - StringBuilder sb = new StringBuilder(); - for (String s : arr) { - if (s != null && !s.isEmpty()) { - sb.append(s); - if (!s.endsWith("\n")) { - sb.append('\n'); - } - } - } - return sb.toString(); - } } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java index 1c8ba0c2f6..a50b243ee8 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java @@ -73,7 +73,7 @@ public class DescribeTest extends CLIRepositoryTestCase { public void testNoHead() throws Exception { assertArrayEquals( new String[] { "fatal: No names found, cannot describe anything." }, - execute("git describe")); + executeUnchecked("git describe")); } @Test @@ -81,7 +81,7 @@ public class DescribeTest extends CLIRepositoryTestCase { git.commit().setMessage("initial commit").call(); assertArrayEquals( new String[] { "fatal: No names found, cannot describe anything." }, - execute("git describe")); + executeUnchecked("git describe")); } @Test @@ -119,7 +119,7 @@ public class DescribeTest extends CLIRepositoryTestCase { @Test public void testHelpArgumentAfterUnknown() throws Exception { - String[] output = execute("git describe -XYZ -h"); + String[] output = executeUnchecked("git describe -XYZ -h"); String all = Arrays.toString(output); assertTrue("Unexpected help output: " + all, all.contains("jgit describe")); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java index 975e8c4f76..641e59b04a 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/MergeTest.java @@ -195,7 +195,7 @@ public class MergeTest extends CLIRepositoryTestCase { @Test public void testNoFastForwardAndSquash() throws Exception { assertEquals("fatal: You cannot combine --squash with --no-ff.", - execute("git merge master --no-ff --squash")[0]); + executeUnchecked("git merge master --no-ff --squash")[0]); } @Test @@ -210,7 +210,7 @@ public class MergeTest extends CLIRepositoryTestCase { git.commit().setMessage("commit#2").call(); assertEquals("fatal: Not possible to fast-forward, aborting.", - execute("git merge master --ff-only")[0]); + executeUnchecked("git merge master --ff-only")[0]); } @Test diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java index 85fc1dbb4b..715682755c 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java @@ -103,7 +103,7 @@ public class RepoTest extends CLIRepositoryTestCase { @Test public void testMissingPath() throws Exception { assertEquals("fatal: Argument \"path\" is required", - execute("git repo")[0]); + executeUnchecked("git repo")[0]); } /** diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java index ab09db5a56..0fe25f550a 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java @@ -68,6 +68,6 @@ public class TagTest extends CLIRepositoryTestCase { git.commit().setMessage("commit").call(); assertEquals("fatal: tag 'test' already exists", - execute("git tag test")[0]); + executeUnchecked("git tag test")[0]); } } -- cgit v1.2.3