Skip to content

Commit

Permalink
fixup! [#64] Implement copy/paste protection checks
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
YuriRomanowski committed Dec 23, 2022
1 parent a844583 commit fd71f97
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/Xrefcheck/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ defaultAction Options{..} = do
{ cNetworking = addNetworkingOptions (cNetworking config) oNetworkingOptions }
verifyRepo rw fullConfig oMode oRoot repoInfo

whenJust (nonEmpty copyPasteErrors) reportCopyPasteErrors
whenJust (nonEmpty copyPasteErrors) $ \errs -> do
reportCopyPasteErrors errs
fmt "\n"
case verifyErrors verifyRes of
Nothing | null scanErrs -> fmtLn "All repository links are valid."
Nothing -> exitFailure
Expand Down
63 changes: 52 additions & 11 deletions tests/golden/check-copy-paste/expected.gold
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,67 @@
- anchor: -

➥ In file second-file.md
reference (relative) at src:24:1-29:
reference (relative) at src:23:1-33:
- text: "fubarw"
- link: ./nonexistent-file.md
- anchor: -
is possibly a bad copy paste of
reference (relative) at src:24:1-36:
- text: "nonexfile"
- link: ./nonexistent-file.md
- anchor: -

➥ In file second-file.md
reference (relative) at src:25:1-30:
- text: "fdw"
- link: ./first-file.md
- anchor: chor
- link: ./nonexistent-file.md
- anchor: -
is possibly a bad copy paste of
reference (relative) at src:23:1-32:
- text: "ff-cho"
- link: ./first-file.md
- anchor: chor
reference (relative) at src:24:1-36:
- text: "nonexfile"
- link: ./nonexistent-file.md
- anchor: -

➥ In file second-file.md
reference (external) at src:29:1-28:
reference (external) at src:30:1-28:
- text: "gitlab"
- link: https://github.com
- anchor: -
is possibly a bad copy paste of
reference (external) at src:28:1-28:
reference (external) at src:29:1-28:
- text: "github"
- link: https://github.com
- anchor: -

Possible copy/paste errors dumped, 4 in total.
All repository links are valid.
Possible copy/paste errors dumped, 5 in total.

=== Invalid references found ===

➥ In file second-file.md
bad reference (relative) at src:23:1-33:
- text: "fubarw"
- link: ./nonexistent-file.md
- anchor: -

File does not exist:
nonexistent-file.md

➥ In file second-file.md
bad reference (relative) at src:24:1-36:
- text: "nonexfile"
- link: ./nonexistent-file.md
- anchor: -

File does not exist:
nonexistent-file.md

➥ In file second-file.md
bad reference (relative) at src:25:1-30:
- text: "fdw"
- link: ./nonexistent-file.md
- anchor: -

File does not exist:
nonexistent-file.md

Invalid references dumped, 3 in total.
5 changes: 3 additions & 2 deletions tests/golden/check-copy-paste/second-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

<!-- These ones are reported because -->
<!-- ff-cho is a subsequence of link+anchor -->
[ ff-cho](./first-file.md#chor)
[ fdw](./first-file.md#chor)
[ fubarw](./nonexistent-file.md)
[ nonexfile](./nonexistent-file.md)
[ fdw](./nonexistent-file.md)


<!-- check external links -->
Expand Down

0 comments on commit fd71f97

Please sign in to comment.