From 4987c2aac8d2a99bac04eb0d4f4c8148f06ccd19 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 2 Jul 2018 10:35:32 +0200 Subject: [PATCH] some additional tests for isLeadingPath testing for trailing slashes --- .../apache/tools/ant/util/FileUtilsTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java index 716751d4d..d82b7b694 100644 --- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -624,6 +624,22 @@ public class FileUtilsTest { assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/bar"), true)); } + @Test + public void isLeadingPathAndTrailingSlashesOnUnix() throws IOException { + assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), true)); + + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), false)); + } + @Test public void isLeadingPathCanonicalVersionWorksAsExpectedOnDos() throws IOException { assumeTrue("Test only runs on DOS", Os.isFamily("dos")); @@ -634,6 +650,22 @@ public class FileUtilsTest { assertFalse(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\bar"), true)); } + @Test + public void isLeadingPathAndTrailingSlashesOnDos() throws IOException { + assumeTrue("Test only runs on DOS", Os.isFamily("dos")); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), true)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), true)); + + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), false)); + assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), false)); + } + /** * adapt file separators to local conventions */