From ebe2b05bb330246f04db1fb9296e980e95cfa154 Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Sat, 28 Jun 2003 14:18:40 +0000 Subject: [PATCH] Make FileUtilsTest pass under cygwin I found doing this how to tell whether one is running under cygwin if the first letter (drive letter) of System.getProperty("user.dir") is lower case then one is under cygwin git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274728 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/util/FileUtilsTest.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java index f723d145a..076044b56 100644 --- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java @@ -79,7 +79,7 @@ public class FileUtilsTest extends TestCase { public void setUp() { fu = FileUtils.newFileUtils(); - // Windows adds the drive letter in uppercase, unless you run Cygnus + // Windows adds the drive letter in uppercase, unless you run Cygwin root = new File(File.separator).getAbsolutePath().toUpperCase(); } @@ -408,9 +408,9 @@ public class FileUtilsTest extends TestCase { new File("c:\\foo\\bar"))); assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"))); - assertEquals(fu.normalize("/bar").getAbsolutePath(), + assertEqualsIgnoreDriveCase(fu.normalize("/bar").getAbsolutePath(), fu.removeLeadingPath(new File("/foo"), new File("/bar"))); - assertEquals(fu.normalize("/foobar").getAbsolutePath(), + assertEqualsIgnoreDriveCase(fu.normalize("/foobar").getAbsolutePath(), fu.removeLeadingPath(new File("/foo"), new File("/foobar"))); // bugzilla report 19979 assertEquals("", fu.removeLeadingPath(new File("/foo/bar"), @@ -436,7 +436,13 @@ public class FileUtilsTest extends TestCase { dosRoot = ""; } if (Os.isFamily("dos")) { - assertEquals("file:///C:/foo", fu.toURI("c:\\foo")); + assertEquals("file:///"+ dosRoot + "foo", fu.toURI("c:\\foo")); + } + if (Os.isFamily("dos")) { + // this amounts to : are we under cygwin ? + if (Character.isLowerCase(System.getProperty("user.dir").charAt(0))) { + dosRoot = "c:/"; + } } assertEquals("file:///" + dosRoot + "foo", fu.toURI("/foo")); assertEquals("file:./foo", fu.toURI("./foo")); @@ -453,13 +459,13 @@ public class FileUtilsTest extends TestCase { */ public void testFromURI() { if (Os.isFamily("dos")) { - assertEquals("C:\\foo", fu.fromURI("file:///c:/foo")); + assertEqualsIgnoreDriveCase("C:\\foo", fu.fromURI("file:///c:/foo")); } - assertEquals(localize("/foo"), fu.fromURI("file:///foo")); + assertEqualsIgnoreDriveCase(localize("/foo"), fu.fromURI("file:///foo")); assertEquals("." + File.separator + "foo", fu.fromURI("file:./foo")); - assertEquals(localize("/foo bar"), fu.fromURI("file:///foo%20bar")); - assertEquals(localize("/foo#bar"), fu.fromURI("file:///foo%23bar")); + assertEqualsIgnoreDriveCase(localize("/foo bar"), fu.fromURI("file:///foo%20bar")); + assertEqualsIgnoreDriveCase(localize("/foo#bar"), fu.fromURI("file:///foo%23bar")); } /** @@ -469,4 +475,21 @@ public class FileUtilsTest extends TestCase { path = root + path.substring(1); return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); } + /** + * convenience method + * normalize brings the drive in uppercase + * the drive letter is in lower case under cygwin + * calling this method allows tests where normalize is called to pass under cygwin + */ + private void assertEqualsIgnoreDriveCase(String s1, String s2) { + if (Os.isFamily("dos") && s1.length()>=1 && s2.length()>=1) { + StringBuffer sb1= new StringBuffer(s1); + StringBuffer sb2= new StringBuffer(s2); + sb1.setCharAt(0,Character.toUpperCase(s1.charAt(0))); + sb2.setCharAt(0,Character.toUpperCase(s2.charAt(0))); + assertEquals(sb1.toString(),sb2.toString()); + } else { + assertEquals(s1,s2); + } + } }