-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to golden-executable to only show size of diffs for certai…
…n extensions
- Loading branch information
1 parent
5815083
commit 3a09a1c
Showing
4 changed files
with
102 additions
and
14 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
64 changes: 64 additions & 0 deletions
64
tasty-golden-executable/src/Test/Tasty/Golden/Executable/TestSpec/SizeOnly.hs
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,64 @@ | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
|
||
module Test.Tasty.Golden.Executable.TestSpec.SizeOnly | ||
( SizeOnlyExtension (..), | ||
SizeOnlyExtensions (..), | ||
toSizeOnlyExtensionsSet, | ||
) | ||
where | ||
|
||
import Data.Aeson.Types (FromJSON (..), Parser, ToJSON (..), Value, typeMismatch) | ||
import Data.Aeson.Types qualified as Value (Value (..)) | ||
import Data.Data (Typeable) | ||
import Data.Set (Set) | ||
import Data.Set qualified as Set (fromList) | ||
import Data.String (IsString (..)) | ||
import Data.Tagged (Tagged) | ||
import Data.Text qualified as Text | ||
import Test.Tasty.Options (IsOption (..), safeRead) | ||
|
||
-- | Extension for which only diffs should show the size. | ||
newtype SizeOnlyExtension = SizeOnlyExtension {extension :: FilePath} | ||
deriving (Eq, Ord, Typeable) | ||
|
||
instance Show SizeOnlyExtension where | ||
show :: SizeOnlyExtension -> String | ||
show (SizeOnlyExtension programName) = programName | ||
|
||
instance Read SizeOnlyExtension where | ||
readsPrec :: Int -> ReadS SizeOnlyExtension | ||
readsPrec _prec programName = [(SizeOnlyExtension programName, "")] | ||
|
||
instance IsString SizeOnlyExtension where | ||
fromString :: String -> SizeOnlyExtension | ||
fromString = SizeOnlyExtension | ||
|
||
instance FromJSON SizeOnlyExtension where | ||
parseJSON :: Value -> Parser SizeOnlyExtension | ||
parseJSON (Value.String name) = return $ SizeOnlyExtension (Text.unpack name) | ||
parseJSON value = typeMismatch "String" value | ||
|
||
instance ToJSON SizeOnlyExtension where | ||
toJSON :: SizeOnlyExtension -> Value | ||
toJSON = toJSON . extension | ||
|
||
newtype SizeOnlyExtensions = SizeOnlyExtensions [SizeOnlyExtension] | ||
deriving (Eq, Ord, Show, Typeable, Semigroup, Monoid) | ||
|
||
instance IsOption SizeOnlyExtensions where | ||
defaultValue :: SizeOnlyExtensions | ||
defaultValue = mempty | ||
|
||
parseValue :: String -> Maybe SizeOnlyExtensions | ||
parseValue input = SizeOnlyExtensions <$> traverse safeRead names | ||
where | ||
names = Text.unpack . Text.strip <$> Text.splitOn "," (Text.pack input) | ||
|
||
optionName :: Tagged SizeOnlyExtensions String | ||
optionName = return "sizeOnly" | ||
|
||
optionHelp :: Tagged SizeOnlyExtensions String | ||
optionHelp = return "A list of file extensions for which diffs should only display the sizes of the old and new files." | ||
|
||
toSizeOnlyExtensionsSet :: SizeOnlyExtensions -> Set String | ||
toSizeOnlyExtensionsSet (SizeOnlyExtensions exts) = Set.fromList (fmap extension exts) |
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