Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 7104 invoked from network); 24 Oct 2004 00:10:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 24 Oct 2004 00:10:11 -0000 Received: (qmail 40559 invoked by uid 500); 24 Oct 2004 00:10:09 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 40221 invoked by uid 500); 24 Oct 2004 00:10:06 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 40208 invoked by uid 500); 24 Oct 2004 00:10:06 -0000 Received: (qmail 40205 invoked by uid 99); 24 Oct 2004 00:10:06 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 23 Oct 2004 17:10:06 -0700 Received: (qmail 7062 invoked by uid 1339); 24 Oct 2004 00:10:05 -0000 Date: 24 Oct 2004 00:10:05 -0000 Message-ID: <20041024001005.7061.qmail@minotaur.apache.org> From: martinc@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/io/src/test/org/apache/commons/io/find FileFinderTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N martinc 2004/10/23 17:10:05 Modified: io/src/test/org/apache/commons/io FilenameUtilsTestCase.java io/src/test/org/apache/commons/io/find FileFinderTest.java Log: The tests were using explicit Unix-style path separators, whereas the utils themselves were using File.separator, so the tests failed on Windows. Now the tests also use File.separator, and work on Windows. The one tricky part is that paths for regex searches need to be escaped if the separator is a backslash. Revision Changes Path 1.9 +7 -7 jakarta-commons/io/src/test/org/apache/commons/io/FilenameUtilsTestCase.java Index: FilenameUtilsTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/FilenameUtilsTestCase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FilenameUtilsTestCase.java 13 Jun 2004 05:13:57 -0000 1.8 +++ FilenameUtilsTestCase.java 24 Oct 2004 00:10:05 -0000 1.9 @@ -208,9 +208,9 @@ { "README", "" }, { "domain.dot.com", "com" }, { "image.jpeg", "jpeg" }, - { "a.b/c", "" }, - { "a.b/c.txt", "txt" }, - { "a/b/c", "" }, + { "a.b" + File.separator + "c", "" }, + { "a.b" + File.separator + "c.txt", "txt" }, + { "a" + File.separator + "b" + File.separator + "c", "" }, }; for (int i = 0; i < tests.length; i++) { assertEquals(tests[i][1], FilenameUtils.getExtension(tests[i][0])); @@ -244,9 +244,9 @@ { "README", "README" }, { "domain.dot.com", "domain.dot" }, { "image.jpeg", "image" }, - { "a.b/c", "a.b/c" }, - { "a.b/c.txt", "a.b/c" }, - { "a/b/c", "a/b/c" }, + { "a.b" + File.separator + "c", "a.b" + File.separator + "c" }, + { "a.b" + File.separator + "c.txt", "a.b" + File.separator + "c" }, + { "a" + File.separator + "b" + File.separator + "c", "a" + File.separator + "b" + File.separator + "c" }, }; for (int i = 0; i < tests.length; i++) { 1.3 +19 -5 jakarta-commons/io/src/test/org/apache/commons/io/find/FileFinderTest.java Index: FileFinderTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/find/FileFinderTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- FileFinderTest.java 22 Sep 2004 02:02:35 -0000 1.2 +++ FileFinderTest.java 24 Oct 2004 00:10:05 -0000 1.3 @@ -29,7 +29,7 @@ private HashMap options; private FileFinder finder; - private String dirStr = "src/test/find-data/"; + private String dirStr = "src" + File.separator + "test" + File.separator + "find-data" + File.separator; private File dir = new File(dirStr); public FileFinderTest(String name) { @@ -61,13 +61,13 @@ } public void testFindPath() { - options.put(Finder.PATH, dirStr+"path/dir/file"); + options.put(Finder.PATH, dirStr+"path" + File.separator + "dir" + File.separator + "file"); File[] files = finder.find(new File(dir, "path"), options); assertEquals(1, files.length); } public void testFindIPath() { - options.put(Finder.IPATH, dirStr+"PAth/dIR/fILe"); + options.put(Finder.IPATH, dirStr+"PAth" + File.separator + "dIR" + File.separator + "fILe"); File[] files = finder.find(new File(dir, "path"), options); assertEquals(1, files.length); } @@ -79,13 +79,13 @@ } public void testFindRegex() { - options.put(Finder.REGEX, dirStr+"regex/f.*"); + options.put(Finder.REGEX, escapePath(dirStr+"regex" + File.separator + "f.*")); File[] files = finder.find(new File(dir, "regex"), options); assertEquals(3, files.length); } public void testFindIRegex() { - options.put(Finder.IREGEX, dirStr+"REgeX/F.*"); + options.put(Finder.IREGEX, escapePath(dirStr+"REgeX" + File.separator + "F.*")); File[] files = finder.find(new File(dir, "regex"), options); assertEquals(3, files.length); } @@ -138,6 +138,20 @@ options.put(Finder.CAN_READ, "false"); File[] files = finder.find(new File(dir, "can_read"), options); assertEquals(0, files.length); + } + + private static String escapePath(String text) { + String repl = "\\"; + String with = "\\\\"; + + StringBuffer buf = new StringBuffer(text.length()); + int start = 0, end = 0; + while ((end = text.indexOf(repl, start)) != -1) { + buf.append(text.substring(start, end)).append(with); + start = end + repl.length(); + } + buf.append(text.substring(start)); + return buf.toString(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org