Skip to content

Commit d6c821b

Browse files
committed
Retain ANSI "show cursor"-sequence when parsing summary
This fixes a bug introduced in 559eaf6
1 parent 3b6235d commit d6c821b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Session.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module Session (
2020
, hasSpec
2121
, hasHspecCommandSignature
2222
, hspecCommand
23+
, Extract(..)
2324
, extractSummary
25+
, ansiShowCursor
2426
#endif
2527
) where
2628

@@ -123,16 +125,21 @@ isSuccess = not . isFailure
123125
extractSummary :: Extract Summary
124126
extractSummary = Extract {
125127
isPartialMessage = partialMessageStartsWithOneOf [summaryPrefix, ansiShowCursor <> summaryPrefix]
126-
, parseMessage = fmap (flip (,) "") . parseSummary
128+
, parseMessage
127129
} where
128130
summaryPrefix :: ByteString
129131
summaryPrefix = "Summary {"
130132

133+
parseMessage :: ByteString -> Maybe (Summary, ByteString)
134+
parseMessage input = case ByteString.stripPrefix ansiShowCursor input of
135+
Nothing -> flip (,) "" <$> parseSummary input
136+
Just i -> flip (,) ansiShowCursor <$> parseSummary i
137+
131138
parseSummary :: ByteString -> Maybe Summary
132139
parseSummary = readMaybe . decodeUtf8 . stripAnsiShowCursor
133140

134-
ansiShowCursor :: ByteString
135-
ansiShowCursor = "\ESC[?25h"
136-
137141
stripAnsiShowCursor :: ByteString -> ByteString
138142
stripAnsiShowCursor input = fromMaybe input $ ByteString.stripPrefix ansiShowCursor input
143+
144+
ansiShowCursor :: ByteString
145+
ansiShowCursor = "\ESC[?25h"

test/SessionSpec.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@ spec = do
8888
withSession [name, "--no-color", "-m", "foo"] $ \session -> do
8989
_ <- runSpec session >> runSpec session
9090
hspecPreviousSummary session `shouldReturn` Just (Summary 1 0)
91+
92+
describe "extractSummary" $ do
93+
let
94+
summary :: Summary
95+
summary = Summary 0 0
96+
97+
input :: ByteString
98+
input = fromString $ show summary
99+
100+
it "extracts summary" $ do
101+
extractSummary.parseMessage input `shouldBe` Just (summary, "")
102+
103+
context "when the input starts with the ANSI \"show cursor\"-sequence" $ do
104+
it "extracts summary" $ do
105+
extractSummary.parseMessage (ansiShowCursor <> input) `shouldBe` Just (summary, ansiShowCursor)

0 commit comments

Comments
 (0)