ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/util FileUtilsTest.java
Date Sat, 28 Jun 2003 14:18:40 GMT
antoine     2003/06/28 07:18:40

  Modified:    src/testcases/org/apache/tools/ant/util FileUtilsTest.java
  Log:
  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
  
  Revision  Changes    Path
  1.19      +31 -8     ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  
  Index: FileUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FileUtilsTest.java	24 Jun 2003 16:07:26 -0000	1.18
  +++ FileUtilsTest.java	28 Jun 2003 14:18:40 -0000	1.19
  @@ -79,7 +79,7 @@
   
       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 @@
                                                    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 @@
               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 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"));
       }
   
       /**
  @@ -468,5 +474,22 @@
       private String localize(String path) {
           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);
  +        }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message