xrefcheck/tests/Test/Xrefcheck/TrailingSlashSpec.hs
Adrián Enríquez 9421c42421
[#244] Symlink scanner
Problem: As GitHub and GitLab do not render symlinks as the file they
point to, we are considering to implement a new scanner for symlinks
that verifies them up to some extent.

Solution: A scanner that validates the reference from a symlink has been
implemented in the same style as the markdown scanner.
2023-02-01 13:06:57 +01:00

51 lines
1.7 KiB
Haskell

{- SPDX-FileCopyrightText: 2019 Serokell <https://serokell.io>
-
- SPDX-License-Identifier: MPL-2.0
-}
module Test.Xrefcheck.TrailingSlashSpec where
import Universum
import System.Directory (doesFileExist)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (assertFailure, testCase)
import Text.Interpolation.Nyan
import Xrefcheck.Config
import Xrefcheck.Core
import Xrefcheck.Progress
import Xrefcheck.Scan
import Xrefcheck.Scanners.Markdown
import Xrefcheck.System
import Xrefcheck.Util
test_slash :: TestTree
test_slash = testGroup "Trailing forward slash detection" $
let config = defConfig GitHub
fileSupport = firstFileSupport [markdownSupport (scMarkdown (cScanners config))]
in roots <&> \root ->
testCase ("All the files within the root \"" <>
root <>
"\" should exist") $ do
(ScanResult _ RepoInfo{..}) <- allowRewrite False $ \rw ->
scanRepo OnlyTracked rw fileSupport (cExclusions config & ecIgnoreL .~ []) root
nonExistentFiles <- lefts <$> forM (fst . snd <$> toPairs riFiles) (\file -> do
predicate <- doesFileExist . filePathFromRoot root $ file
return $ if predicate
then Right ()
else Left . filePathFromRoot root $ file)
whenJust (nonEmpty nonExistentFiles) $ \files ->
assertFailure
[int||
Expected all filepaths to be valid, but these filepaths do not exist:
#{interpolateBlockListF files}
|]
where
roots :: [FilePath]
roots =
[ "tests/markdowns/without-annotations"
, "tests/markdowns/without-annotations/"
, "tests/markdowns/without-annotations/./"
]