packages feed

sydtest-discover 0.0.0.2 → 0.0.0.3

raw patch · 3 files changed

+25/−7 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Test.Syd.Discover: findTestBaseDir :: Path Abs a -> Path Abs Dir
- Test.Syd.Discover: sourceFilesInNonHiddenDirsRecursively :: forall m. MonadIO m => Path Abs Dir -> m [Path Rel File]
+ Test.Syd.Discover: sourceFilesInNonHiddenDirsRecursively :: forall m. MonadIO m => Path Rel Dir -> m [Path Rel File]

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## [0.0.0.3] - 2023-04-29++### Changed++* Test case discovery now works even if the `Spec.hs` file is not at top level+ ## [0.0.0.2] - 2022-08-05  ### Changed
src/Test/Syd/Discover.hs view
@@ -1,10 +1,12 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}  module Test.Syd.Discover where  import Control.Monad.IO.Class+import Data.Char import Data.List import Data.Maybe import Options.Applicative@@ -16,13 +18,23 @@ sydTestDiscover = do   Arguments {..} <- getArguments   specSourceFile <- resolveFile' argSource-  -- We asume that the spec source is a top-level module.-  let testDir = parent specSourceFile-  specSourceFileRel <- stripProperPrefix testDir specSourceFile-  otherSpecFiles <- mapMaybe parseSpecModule . sort . filter (\fp -> fp /= specSourceFileRel && isHaskellFile fp) <$> sourceFilesInNonHiddenDirsRecursively testDir-  let output = makeSpecModule argSettings specSourceFileRel otherSpecFiles+  let testBaseDir = findTestBaseDir specSourceFile+      testDir = parent specSourceFile+  testDirRelToBaseDirParent <- stripProperPrefix (parent testBaseDir) testDir+  testDirRelToBaseDir <- if testBaseDir == testDir then pure [reldir|.|] else stripProperPrefix testBaseDir testDir+  specSourceFileRel <- stripProperPrefix testBaseDir specSourceFile+  -- traversing the files in the directory below the Spec file, appending the prefix from the test root to the Spec's location+  otherSpecFilesRelativeToBaseDir <- fmap (\f -> testDirRelToBaseDir </> f) <$> sourceFilesInNonHiddenDirsRecursively testDirRelToBaseDirParent+  let otherSpecFiles = mapMaybe parseSpecModule $ sort $ filter (\fp -> fp /= specSourceFileRel && isHaskellFile fp) otherSpecFilesRelativeToBaseDir+      output = makeSpecModule argSettings specSourceFileRel otherSpecFiles   writeFile argDestination output +-- we're traversing up the file tree until we find a directory that doesn't start with an uppercase letter+findTestBaseDir :: Path Abs a -> Path Abs Dir+findTestBaseDir specSourceFile = if isUpper (head (toFilePath $ dirname directParent)) then findTestBaseDir directParent else directParent+  where+    directParent = parent specSourceFile+ data Arguments = Arguments   { argSource :: FilePath,     argIgnored :: FilePath,@@ -55,7 +67,7 @@ sourceFilesInNonHiddenDirsRecursively ::   forall m.   MonadIO m =>-  Path Abs Dir ->+  Path Rel Dir ->   m [Path Rel File] sourceFilesInNonHiddenDirsRecursively =   walkDirAccumRel (Just goWalk) goOutput
sydtest-discover.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           sydtest-discover-version:        0.0.0.2+version:        0.0.0.3 synopsis:       Automatic test suite discovery for sydtest category:       Testing homepage:       https://github.com/NorfairKing/sydtest#readme