summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2014-03-30 11:00:36 +0200
committerRobin Stocker <robin@nibor.org>2014-04-06 12:16:41 -0400
commit4a11b7137fa7a3880fb05745256940c186589464 (patch)
treeea0fe5168e4f60f33600d7caf3d3dddfbaa696b4 /org.eclipse.jgit.test
parentecade47a895c19b8ea290d2e5909434176292433 (diff)
downloadjgit-4a11b7137fa7a3880fb05745256940c186589464.tar.gz
jgit-4a11b7137fa7a3880fb05745256940c186589464.zip
Fix ValidRefNameTest on Windows
There are certain ref names which native git can be create only on non-windows systems (e.g. "refs/tags/>"). On Windows systems we can't persist this refs because the ref names are not valid file names. Our tests in ValidRefNameTest assumed that these are valid refs on all systems. This broke the tests on Windows. Change-Id: Ic53c396c88b84cbdf579a636953f7519952270c0
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java78
1 files changed, 55 insertions, 23 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
index 2f8bfb3fdd..e9d46bb582 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ValidRefNameTest.java
@@ -51,7 +51,47 @@ import org.junit.Test;
public class ValidRefNameTest {
private static void assertValid(final boolean exp, final String name) {
- assertEquals("\"" + name + "\"", exp, Repository.isValidRefName(name));
+ SystemReader instance = SystemReader.getInstance();
+ try {
+ setUnixSystemReader();
+ assertEquals("\"" + name + "\"", exp,
+ Repository.isValidRefName(name));
+ setWindowsSystemReader();
+ assertEquals("\"" + name + "\"", exp,
+ Repository.isValidRefName(name));
+ } finally {
+ SystemReader.setInstance(instance);
+ }
+ }
+
+ private static void setWindowsSystemReader() {
+ SystemReader.setInstance(new MockSystemReader() {
+ {
+ setWindows();
+ }
+ });
+ }
+
+ private static void setUnixSystemReader() {
+ SystemReader.setInstance(new MockSystemReader() {
+ {
+ setUnix();
+ }
+ });
+ }
+
+ private static void assertInvalidOnWindows(final String name) {
+ SystemReader instance = SystemReader.getInstance();
+ try {
+ setUnixSystemReader();
+ assertEquals("\"" + name + "\"", true,
+ Repository.isValidRefName(name));
+ setWindowsSystemReader();
+ assertEquals("\"" + name + "\"", false,
+ Repository.isValidRefName(name));
+ } finally {
+ SystemReader.setInstance(instance);
+ }
}
@Test
@@ -153,9 +193,8 @@ public class ValidRefNameTest {
}
@Test
- public void testValidSpecialCharacters() {
+ public void testValidSpecialCharacterUnixs() {
assertValid(true, "refs/heads/!");
- assertValid(true, "refs/heads/\"");
assertValid(true, "refs/heads/#");
assertValid(true, "refs/heads/$");
assertValid(true, "refs/heads/%");
@@ -167,21 +206,24 @@ public class ValidRefNameTest {
assertValid(true, "refs/heads/,");
assertValid(true, "refs/heads/-");
assertValid(true, "refs/heads/;");
- assertValid(true, "refs/heads/<");
assertValid(true, "refs/heads/=");
- assertValid(true, "refs/heads/>");
assertValid(true, "refs/heads/@");
assertValid(true, "refs/heads/]");
assertValid(true, "refs/heads/_");
assertValid(true, "refs/heads/`");
assertValid(true, "refs/heads/{");
- assertValid(true, "refs/heads/|");
assertValid(true, "refs/heads/}");
// This is valid on UNIX, but not on Windows
// hence we make in invalid due to non-portability
//
assertValid(false, "refs/heads/\\");
+
+ // More invalid characters on Windows, but we allow them
+ assertInvalidOnWindows("refs/heads/\"");
+ assertInvalidOnWindows("refs/heads/<");
+ assertInvalidOnWindows("refs/heads/>");
+ assertInvalidOnWindows("refs/heads/|");
}
@Test
@@ -197,22 +239,12 @@ public class ValidRefNameTest {
@Test
public void testWindowsReservedNames() {
- SystemReader original = SystemReader.getInstance();
- try {
- SystemReader.setInstance(new MockSystemReader() {
- public boolean isWindows() {
- return true;
- }
- });
- // re-using code from DirCacheCheckoutTest, hence
- // only testing for one of the special names.
- assertValid(false, "refs/heads/con");
- assertValid(false, "refs/con/x");
- assertValid(false, "con/heads/x");
- assertValid(true, "refs/heads/conx");
- assertValid(true, "refs/heads/xcon");
- } finally {
- SystemReader.setInstance(original);
- }
+ // re-using code from DirCacheCheckoutTest, hence
+ // only testing for one of the special names.
+ assertInvalidOnWindows("refs/heads/con");
+ assertInvalidOnWindows("refs/con/x");
+ assertInvalidOnWindows("con/heads/x");
+ assertValid(true, "refs/heads/conx");
+ assertValid(true, "refs/heads/xcon");
}
}