Skip to content

Commit

Permalink
[#197] Golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeqz committed Dec 7, 2022
1 parent e086619 commit 9bc47b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,16 @@ verifyReference
= retryVerification 0 $
if shouldCheckLocType mode rInfo
then case rInfo of
RIFileLocal -> do
let fromRoot = ""
checkRef rAnchor root file fromRoot
RIFileLocal -> checkRef rAnchor root file ""
RIFileRelative -> do
let relativeToRoot = getRelativeOrAbsoluteChild root (takeDirectory file)
</> toString rLink
canonicalPath <- takeDirectory file </ toString rLink
let fromRoot = getRelativeOrAbsoluteChild root (takeDirectory file) </> toString rLink
checkRef rAnchor root canonicalPath fromRoot
checkRef rAnchor root canonicalPath relativeToRoot
RIFileAbsolute -> do
canonicalPath <- root </ dropWhile isPathSeparator (toString rLink)
let fromRoot = dropWhile isPathSeparator (toString rLink)
checkRef rAnchor root canonicalPath fromRoot
let relativeToRoot = dropWhile isPathSeparator (toString rLink)
canonicalPath <- root </ relativeToRoot
checkRef rAnchor root canonicalPath relativeToRoot
RIExternal -> checkExternalResource config rLink
RIOtherProtocol -> verifying pass
else return mempty
Expand Down Expand Up @@ -515,12 +514,12 @@ verifyReference

isVirtual canonicalRoot = matchesGlobPatterns canonicalRoot (ecIgnoreLocalRefsTo cExclusions)

checkRef mAnchor canonicalRoot referredFile fromRoot = verifying $
checkRef mAnchor canonicalRoot referredFile relativeToRoot = verifying $
unless (isVirtual canonicalRoot referredFile) do
referredFileRelative <-
case getRelativeChild canonicalRoot referredFile of
Just ps -> pure ps
Nothing -> throwError (LocalFileOutsideRepo fromRoot)
Nothing -> throwError (LocalFileOutsideRepo relativeToRoot)

mFileStatus <- tryGetFileStatus referredFileRelative referredFile
case mFileStatus of
Expand Down
4 changes: 2 additions & 2 deletions tests/golden/check-local-refs/expected1.gold
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- anchor: -

File does not exist:
dir1/dir2/D2F2.md/
dir1/dir2/D2F2.md

➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:29:1-32:
Expand All @@ -33,7 +33,7 @@
- anchor: -

File does not exist:
dir1/dir2/../DIR2
dir1/DIR2

➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:31:1-38:
Expand Down
2 changes: 1 addition & 1 deletion tests/golden/check-local-refs/expected2.gold
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- anchor: -

File does not exist:
dir2/D2F2.md/
dir2/D2F2.md

➥ In file dir2/d2f1.md
bad reference (relative) at src:29:1-32:
Expand Down
4 changes: 2 additions & 2 deletions tests/golden/check-local-refs/expected3.gold
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
- anchor: -

File does not exist:
dir2/D2F2.md/
dir2/D2F2.md

➥ In file dir1/dir2/d2f1.md
➥ In file dir2/d2f1.md
bad reference (relative) at src:31:1-38:
- text: "bad-anchor-rel-1"
- link: d2f2.md
Expand Down

0 comments on commit 9bc47b2

Please sign in to comment.