From 99ba4712098f2f4339bd22927a79d1b3e6ab8eaa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 13 Jan 2021 13:21:15 -0400 Subject: [PATCH] rewrite prop_relPathDirToFileAbs_basics This was not a good test, it broke the requirement that relPathDirToFileAbs take absolute paths. And it failed when the two input paths were eg, the same but differently normalized. Replaced with some tests of the real basics of that function. --- Utility/Path.hs | 3 +-- Utility/Path/Tests.hs | 16 +++++++--------- ...Abs__95__basics_fail_on_crippled___126__.mdwn | 2 ++ ...t_1_23bf4756af808d1b2cf89f7da119031f._comment | 11 +++++++++++ 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_1_23bf4756af808d1b2cf89f7da119031f._comment diff --git a/Utility/Path.hs b/Utility/Path.hs index 6bd407e600..b1f7a5f4db 100644 --- a/Utility/Path.hs +++ b/Utility/Path.hs @@ -189,8 +189,7 @@ splitShortExtensions' maxextension = go [] (base, ext) = splitExtension f len = B.length ext -{- This requires the first path to be absolute, and the - - second path cannot contain ../ or ./ +{- This requires both paths to be absolute and normalized. - - On Windows, if the paths are on different drives, - a relative path is not possible and the path is simply diff --git a/Utility/Path/Tests.hs b/Utility/Path/Tests.hs index ba0330c7f6..2d9c6152aa 100644 --- a/Utility/Path/Tests.hs +++ b/Utility/Path/Tests.hs @@ -35,16 +35,14 @@ prop_upFrom_basics tdir p = fromRawFilePath <$> upFrom (toRawFilePath dir) dir = fromTestableFilePath tdir -prop_relPathDirToFileAbs_basics :: TestableFilePath -> TestableFilePath -> Bool -prop_relPathDirToFileAbs_basics fromt tot - | from == to = null r - | otherwise = not (null r) +prop_relPathDirToFileAbs_basics :: TestableFilePath -> Bool +prop_relPathDirToFileAbs_basics pt = and + [ relPathDirToFileAbs p (p "bar") == "bar" + , relPathDirToFileAbs (p "bar") p == ".." + , relPathDirToFileAbs p p == "" + ] where - from = fromTestableFilePath fromt - to = fromTestableFilePath tot - r = fromRawFilePath $ relPathDirToFileAbs - (toRawFilePath from) - (toRawFilePath to) + p = pathSeparator `B.cons` toRawFilePath (fromTestableFilePath pt) prop_relPathDirToFileAbs_regressionTest :: Bool prop_relPathDirToFileAbs_regressionTest = same_dir_shortcurcuits_at_difference diff --git a/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__.mdwn b/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__.mdwn index 9a8cba3a67..0282ec96da 100644 --- a/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__.mdwn +++ b/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__.mdwn @@ -14,3 +14,5 @@ Fresh build of 8.20201129+git100-g2d84bf992-1~ndall+1 when having HOME (base sys [[!meta author=yoh]] [[!tag projects/datalad]] + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_1_23bf4756af808d1b2cf89f7da119031f._comment b/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_1_23bf4756af808d1b2cf89f7da119031f._comment new file mode 100644 index 0000000000..b388e7415f --- /dev/null +++ b/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_1_23bf4756af808d1b2cf89f7da119031f._comment @@ -0,0 +1,11 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2021-01-13T17:01:07Z" + content=""" +This is a pure test, and the filesystem does not affect it in any way. + +The test is slightly broken, in that when two paths +are the same except slightly differently normalized (eg, "A" vs "A/"), +it fails. Really not a great test overall, rewriting. +"""]]