-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#64] Implement copy/paste protection checks
Problem: Currently xrefcheck is not able to detect possible bad copy-pastes, when some links are referring the same file, but from the link names it seems that one of those links should refer other file. Solution: Implement check, add corresponding settings to the config.
- Loading branch information
1 parent
82e7292
commit 44f21e5
Showing
12 changed files
with
277 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{- SPDX-FileCopyrightText: 2019 Serokell <https://serokell.io> | ||
- | ||
- SPDX-License-Identifier: MPL-2.0 | ||
-} | ||
|
||
module Test.Xrefcheck.CopyPasteCheckSpec where | ||
|
||
import Universum | ||
|
||
import Test.Tasty (TestTree, testGroup) | ||
import Test.Tasty.HUnit (Assertion, testCase, (@?=)) | ||
|
||
import Xrefcheck.Core | ||
import Xrefcheck.Verify | ||
|
||
assertUnordered :: (Show a, Ord a) => [a] -> [a] -> Assertion | ||
assertUnordered = (@?=) `on` sort | ||
|
||
testPath :: FilePath | ||
testPath = "test-path" | ||
|
||
test_copyPasteCheck :: TestTree | ||
test_copyPasteCheck = testGroup "Copypaste check" | ||
[ testCase "Detect copypaste error if there is a link with a matching name" $ do | ||
let link = "./first-file" | ||
anchor = Just "heading" | ||
differentAnchor = Nothing | ||
defPos = Position Nothing | ||
original1 = Reference "_- First - - File" link anchor defPos | ||
original2 = Reference "_- First - fi - le" link anchor defPos | ||
notCopied = Reference " Link 2 " link differentAnchor defPos | ||
copied1 = Reference " foo bar" link anchor defPos | ||
copied2 = Reference " Baz quux" link anchor defPos | ||
input = [original1, original2, notCopied, copied1, copied2] | ||
res = checkCopyPaste testPath input | ||
expectedRes = | ||
-- only first matching link is shown in the output | ||
[ CopyPasteCheckResult testPath original1 copied1 | ||
, CopyPasteCheckResult testPath original1 copied2 | ||
] | ||
res `assertUnordered` expectedRes | ||
, testCase "Succeed if there is not link with a matching name" $ do | ||
let link = "./first-file" | ||
anchor = Just "heading" | ||
defPos = Position Nothing | ||
original1 = Reference "_Foo bar" link anchor defPos | ||
original2 = Reference " Baz quux" link anchor defPos | ||
original3 = Reference " Foo qubarx" link anchor defPos | ||
input = [original1, original2, original3] | ||
res = checkCopyPaste testPath input | ||
expectedRes = [] | ||
res @?= expectedRes | ||
, testCase "Check external links" $ do | ||
let link = "https://github.com" | ||
anchor = Nothing | ||
defPos = Position Nothing | ||
original = Reference "github" link anchor defPos | ||
copied = Reference "gitlab" link anchor defPos | ||
input = [original, copied] | ||
res = checkCopyPaste testPath input | ||
expectedRes = | ||
[ CopyPasteCheckResult testPath original copied | ||
] | ||
res @?= expectedRes | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bats | ||
|
||
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io> | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
load '../helpers/bats-support/load' | ||
load '../helpers/bats-assert/load' | ||
load '../helpers/bats-file/load' | ||
load '../helpers' | ||
|
||
|
||
@test "Check possible copy-paste errors and copy-paste annotations " { | ||
to_temp xrefcheck | ||
|
||
assert_diff expected.gold | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
=== Possible copy/paste errors === | ||
|
||
➥ In file second-file.md | ||
reference (relative) at src:13:1-29: | ||
- text: "Lol Kek" | ||
- link: ./first-file.md | ||
- anchor: - | ||
is possibly a bad copy paste of | ||
reference (relative) at src:7:1-34: | ||
- text: "First file" | ||
- link: ./first-file.md | ||
- anchor: - | ||
|
||
➥ In file second-file.md | ||
reference (relative) at src:14:1-30: | ||
- text: "Baz quux" | ||
- link: ./first-file.md | ||
- anchor: - | ||
is possibly a bad copy paste of | ||
reference (relative) at src:7:1-34: | ||
- text: "First file" | ||
- link: ./first-file.md | ||
- anchor: - | ||
|
||
➥ In file second-file.md | ||
reference (relative) at src:24:1-29: | ||
- text: "fdw" | ||
- link: ./first-file.md | ||
- anchor: chor | ||
is possibly a bad copy paste of | ||
reference (relative) at src:23:1-32: | ||
- text: "ff-cho" | ||
- link: ./first-file.md | ||
- anchor: chor | ||
|
||
➥ In file second-file.md | ||
reference (external) at src:29:1-28: | ||
- text: "gitlab" | ||
- link: https://github.com | ||
- anchor: - | ||
is possibly a bad copy paste of | ||
reference (external) at src:28:1-28: | ||
- text: "github" | ||
- link: https://github.com | ||
- anchor: - | ||
|
||
Possible copy/paste errors dumped, 4 in total. | ||
All repository links are valid. |
Oops, something went wrong.