rewrite prop_relPathDirToFileAbs_basics
authorJoey Hess <joeyh@joeyh.name>
Wed, 13 Jan 2021 17:21:15 +0000 (13:21 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 13 Jan 2021 17:23:26 +0000 (13:23 -0400)
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
Utility/Path/Tests.hs
doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__.mdwn
doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_1_23bf4756af808d1b2cf89f7da119031f._comment [new file with mode: 0644]

index 6bd407e600f8e1046287999142e9ce71749c93b7..b1f7a5f4db9747a74a794f9be452245ad150ce00 100644 (file)
@@ -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
index ba0330c7f66dacfe53aef53404eb42f1a10ffe06..2d9c6152aa746a042c7ec0f54e8dddac46c29abe 100644 (file)
@@ -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
index 9a8cba3a67a01e004128faef0ccfd9571829d718..0282ec96da5f58a4ca6a41bc076061c8c285ed68 100644 (file)
@@ -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 (file)
index 0000000..b388e74
--- /dev/null
@@ -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.
+"""]]