hspec-core 2.9.0 → 2.9.1
raw patch · 5 files changed
+170/−9 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- hspec-core.cabal +4/−2
- src/Test/Hspec/Core/Formatters/V2.hs +11/−2
- test/Test/Hspec/Core/Formatters/V2Spec.hs +19/−4
- vendor/Text/Show/Unicode.hs +135/−0
- version.yaml +1/−1
hspec-core.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.34.5. -- -- see: https://github.com/sol/hpack name: hspec-core-version: 2.9.0+version: 2.9.1 license: MIT license-file: LICENSE copyright: (c) 2011-2021 Simon Hengel,@@ -88,6 +88,7 @@ Test.Hspec.Core.Tree Control.Concurrent.Async Data.Algorithm.Diff+ Text.Show.Unicode Paths_hspec_core default-language: Haskell2010 @@ -161,6 +162,7 @@ Test.Hspec.Core.Util Control.Concurrent.Async Data.Algorithm.Diff+ Text.Show.Unicode All GetOpt.Declarative.EnvironmentSpec GetOpt.Declarative.UtilSpec
src/Test/Hspec/Core/Formatters/V2.hs view
@@ -74,6 +74,7 @@ import Test.Hspec.Core.Clock import Test.Hspec.Core.Spec (Location(..)) import Text.Printf+import Text.Show.Unicode (ushow, urecover) import Control.Monad.IO.Class import Control.Exception @@ -255,6 +256,7 @@ where formatFailure :: (Int, FailureRecord) -> FormatM () formatFailure (n, FailureRecord mLoc path reason) = do+ unicode <- outputUnicode forM_ mLoc $ \loc -> do withInfoColor $ writeLine (" " ++ formatLocation loc) write (" " ++ show n ++ ") ")@@ -262,7 +264,12 @@ case reason of NoReason -> return () Reason err -> withFailColor $ indent err- ExpectedButGot preface expected actual -> do+ ExpectedButGot preface expected_ actual_ -> do+ let+ recover = if unicode then urecover else id+ expected = recover expected_+ actual = recover actual_+ mapM_ indent preface b <- useDiff@@ -301,7 +308,9 @@ Error _ e -> withFailColor . indent $ (("uncaught exception: " ++) . formatException) e writeLine ""- writeLine (" To rerun use: --match " ++ show (joinPath path))++ let path_ = (if unicode then ushow else show) (joinPath path)+ writeLine (" To rerun use: --match " ++ path_) where indentation = " " indent message = do
test/Test/Hspec/Core/Formatters/V2Spec.hs view
@@ -1,7 +1,3 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE DeriveFunctor #-} module Test.Hspec.Core.Formatters.V2Spec (spec) where import Prelude ()@@ -173,6 +169,25 @@ ] describe "formatterDone" $ do+ it "recovers unicode from ExpectedButGot" $ do+ formatter <- formatterToFormat progress formatConfig { formatConfigOutputUnicode = True }+ _ <- formatter . ItemDone ([], "") . Item Nothing 0 "" $ Failure Nothing $ ExpectedButGot Nothing (show "\955") (show "\956")+ (fmap normalizeSummary . captureLines) (formatter $ Done []) `shouldReturn` [+ ""+ , "Failures:"+ , ""+ , " 1) "+ , " expected: \"λ\""+ , " but got: \"μ\""+ , ""+ , " To rerun use: --match \"//\""+ , ""+ , "Randomized with seed 0"+ , ""+ , "Finished in 0.0000 seconds"+ , "1 example, 1 failure"+ ]+ context "when actual/expected contain newlines" $ do it "adds indentation" $ do formatter <- formatterToFormat progress formatConfig
+ vendor/Text/Show/Unicode.hs view
@@ -0,0 +1,135 @@+{- |+Copyright : (c) Takayuki Muranushi, 2016+License : BSD3+Maintainer : whosekiteneverfly@gmail.com+Stability : experimental+++Provides a interactive printer for printing Unicode characters in ghci REPL. Our design goal is that 'uprint' produces String representations that are valid Haskell 'String' literals and uses as many Unicode printable characters as possible. Hence++@+read . ushow == id+@++see the tests of this package for detailed specifications.++__Example__++With 'print' :++@+$ __ghci__+...+> __["哈斯克尔7.6.1"]__+["\\21704\\26031\\20811\\23572\\&7.6.1"]+>+@++With 'uprint' :++@+$ __ghci -interactive-print=Text.Show.Unicode.uprint Text.Show.Unicode__+...+Ok, modules loaded: Text.Show.Unicode.+> __("Хорошо!",["哈斯克尔7.6.1的力量","感じる"])__+("Хорошо!",["哈斯克尔7.6.1的力量","感じる"])+> "改\\n行"+"改\\n行"+@++You can make 'uprint' the default interactive printer in several ways. One is to+@cabal install unicode-show@, and add the following lines to your @~/.ghci@ config file.++@+import qualified Text.Show.Unicode+:set -interactive-print=Text.Show.Unicode.uprint+@++-}++module Text.Show.Unicode (ushow, uprint, urecover, ushowWith, uprintWith, urecoverWith) where++import Prelude ()+import Test.Hspec.Core.Compat hiding (many)++import Data.Char (isAscii, isPrint)+import Text.ParserCombinators.ReadP+import Text.Read.Lex (lexChar)+import qualified Data.List as L++-- Represents a replaced character using its literal form and its escaped form.+type Replacement = (String, String)++-- | Parse one Haskell character literal expression from a 'String' produced by 'show', and+--+-- * If the found char satisfies the predicate, replace the literal string with the character itself.+-- * Otherwise, leave the string as it was.+-- * Note that special delimiter sequence "\&" may appear in a string. c.f. <https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6 Section 2.6 of the Haskell 2010 specification>.+recoverChar :: (Char -> Bool) -> ReadP Replacement+recoverChar p = represent <$> gather lexCharAndConsumeEmpties+ where+ represent :: (String, Char) -> Replacement+ represent (o,lc)+ -- This is too dirty a hack.+ -- However, I couldn't think of any other way to recover the & consumed by lexChar while not needlessly increasing the number of & by mis-detecting the escape sequence.+ | p lc =+ if head o /= '\\' &&+ "\\&" `L.isSuffixOf` o+ then (o, lc : "\\&")+ else (o, [lc])+ | otherwise = (o, o)++-- | The base library lexChar has been handling & by itself since 4.9.1.0,+-- so consumeEmpties is a meaningless action,+-- but it makes sense for older versions of lexChar.+lexCharAndConsumeEmpties :: ReadP Char+lexCharAndConsumeEmpties = lexChar <* consumeEmpties+ where+ -- Consumes the string "\&" repeatedly and greedily (will only produce one match)+ consumeEmpties :: ReadP ()+ consumeEmpties = do+ rest <- look+ case rest of+ ('\\':'&':_) -> string "\\&" >> consumeEmpties+ _ -> return ()++-- | Show the input, and then replace Haskell character literals+-- with the character it represents, for any Unicode printable characters except backslash, single and double quotation marks.+-- If something fails, fallback to standard 'show'.+ushow :: Show a => a -> String+ushow = ushowWith shouldRecover++-- | Replace Haskell character literals with the character it represents, for+-- any Unicode printable characters except backslash, single and double+-- quotation marks.+urecover :: String -> String+urecover = urecoverWith shouldRecover++shouldRecover :: Char -> Bool+shouldRecover c = isPrint c && not (isAscii c)++-- | A version of 'print' that uses 'ushow'.+uprint :: Show a => a -> IO ()+uprint = putStrLn . ushow++-- | Show the input, and then replace character literals+-- with the character itself, for characters that satisfy the given predicate.+ushowWith :: Show a => (Char -> Bool) -> a -> String+ushowWith p = urecoverWith p . show++-- | Replace character literals with the character itself, for characters that+-- satisfy the given predicate.+urecoverWith :: (Char -> Bool) -> String -> String+urecoverWith p = go ("", "") . readP_to_S (many $ recoverChar p)+ where+ go :: Replacement -> [([Replacement], String)] -> String+ go _ [] = ""+ go _ (([],""):_) = ""+ go _ ((rs,""):_) = snd $ last rs+ go _ [(_,o)] = o+ go pr (([],_):rest) = go pr rest+ go _ ((rs,_):rest) = let r = last rs in snd r ++ go r rest++-- | A version of 'print' that uses 'ushowWith'.+uprintWith :: Show a => (Char -> Bool) -> a -> IO ()+uprintWith p = putStrLn . ushowWith p
version.yaml view
@@ -1,1 +1,1 @@-&version 2.9.0+&version 2.9.1