Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support record dot syntax #46

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ jobs:
ghc: ["9.8.1", "9.6.3", "9.4.8", "9.2.8", "9.0.2", "8.10.7"]
os: [ubuntu-latest, macOS-latest, windows-latest]
exclude:
- os: windows-latest
ghc: "9.4.2"

- os: windows-latest
ghc: "9.4.2"
- os: macOS-latest
ghc: "9.0.2"
- os: macOS-latest
ghc: "8.10.7"

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-01-05"
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Tasty/Discover/Internal/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data Config = Config
, noModuleSuffix :: Bool -- ^ <<<DEPRECATED>>>: suffix and look in all modules.
, debug :: Bool -- ^ Debug the generated module.
, treeDisplay :: Bool -- ^ Tree display for the test results table.
} deriving (Show)
} deriving stock (Show)

-- | The default configuration
defaultConfig :: FilePath -> Config
Expand Down
11 changes: 9 additions & 2 deletions src/Test/Tasty/Discover/Internal/Driver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,16 @@ findTests config = do
-- | Extract the test names from discovered modules.
extractTests :: FilePath -> String -> [Test]
extractTests file = mkTestDeDuped . isKnownPrefix . parseTest
where mkTestDeDuped = map (mkTest file) . nub
where mkTestDeDuped :: [String] -> [Test]
mkTestDeDuped = map (mkTest file) . nub

isKnownPrefix :: [String] -> [String]
isKnownPrefix = filter (\g -> any (checkPrefix g) generators)

checkPrefix :: String -> Generator -> Bool
checkPrefix g = (`isPrefixOf` g) . generatorPrefix

parseTest :: String -> [String]
parseTest = map fst . concatMap lex . lines

-- | Show the imports.
Expand All @@ -130,7 +137,7 @@ showTests config tests testNumVars = if treeDisplay config
else zipWith const testNumVars tests

newtype ModuleTree = ModuleTree (M.Map String (ModuleTree, [String]))
deriving (Eq, Show)
deriving stock (Eq, Show)

showModuleTree :: ModuleTree -> [String]
showModuleTree (ModuleTree mdls) = map showModule $ M.assocs mdls
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Tasty/Discover/Internal/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
data Test = Test
{ testModule :: String -- ^ Module name.
, testFunction :: String -- ^ Function name.
} deriving (Eq, Show, Ord)
} deriving stock (Eq, Show, Ord)

-- | 'Test' constructor.
mkTest :: FilePath -> String -> Test
Expand All @@ -52,7 +52,7 @@

-- | Function namer.
name :: Test -> String
name = chooser '_' ' ' . tail . dropWhile (/= '_') . testFunction

Check warning on line 55 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, ubuntu-latest)

In the use of ‘tail’

Check warning on line 55 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, macOS-latest)

In the use of ‘tail’

Check warning on line 55 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, windows-latest)

In the use of ‘tail’
where chooser c1 c2 = map $ \c3 -> if c3 == c1 then c2 else c3

-- | Generator retriever (single).
Expand All @@ -63,7 +63,7 @@
-- | Generator retriever (many).
getGenerators :: [Test] -> [Generator]
getGenerators =
map head .

Check warning on line 66 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, ubuntu-latest)

In the use of ‘head’

Check warning on line 66 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, macOS-latest)

In the use of ‘head’

Check warning on line 66 in src/Test/Tasty/Discover/Internal/Generator.hs

View workflow job for this annotation

GitHub Actions / build (9.8.1, windows-latest)

In the use of ‘head’
groupBy ((==) `on` generatorPrefix) .
sortOn generatorPrefix .
map getGenerator
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Tasty/Discover/TastyInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Data.Monoid
data TastyInfo = TastyInfo
{ name :: Last String
, description :: Last String
} deriving (Eq, Show)
} deriving stock (Eq, Show)

instance Semigroup TastyInfo where
a <> b = TastyInfo
Expand Down
32 changes: 22 additions & 10 deletions tasty-discover.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ source-repository head
type: git
location: https://github.com/haskell-works/tasty-discover

flag dev
description: Enable development mode
manual: True
default: False

common base { build-depends: base >= 4.11 && < 5 }

common bytestring { build-depends: bytestring >= 0.9 && < 1.0 }
Expand All @@ -51,14 +56,27 @@ common tasty-hunit { build-depends: tasty-hunit >=
common tasty-quickcheck { build-depends: tasty-quickcheck >= 0.10 && < 0.11 }
common tasty-smallcheck { build-depends: tasty-smallcheck >= 0.8 && < 1.0 }

common project-config
default-extensions: DerivingStrategies
if (impl(ghc >= 9.2.1))
OverloadedRecordDot
ghc-options: -Wall
-Widentities
-Wincomplete-uni-patterns
-Wmissing-deriving-strategies
-Wredundant-constraints
-Wunused-packages
default-language: GHC2021
if (flag(dev))
ghc-options: -Werror

common tasty-discover
build-depends: tasty-discover

library
import: base
import: base, project-config
, Glob
, containers
, directory
, filepath
, tasty
exposed-modules: Test.Tasty.Discover
Expand All @@ -74,10 +92,7 @@ library
default-language: Haskell2010

executable tasty-discover
import: base
, Glob
, containers
, directory
import: base, project-config
, filepath
main-is: app/Main.hs
autogen-modules: Paths_tasty_discover
Expand All @@ -87,12 +102,9 @@ executable tasty-discover
default-language: Haskell2010

test-suite tasty-discover-test
import: base
, Glob
import: base, project-config
, bytestring
, containers
, directory
, filepath
, hedgehog
, hspec
, hspec-core
Expand Down
Loading