Skip to content

Commit 7040a52

Browse files
authored
Merge pull request #129 from phadej/trailing-whitespace
Add --strip-trailing-whitespace
2 parents 916bd3c + 22e5f84 commit 7040a52

File tree

9 files changed

+43
-12
lines changed

9 files changed

+43
-12
lines changed

cabal-bundler/fixtures/derivation.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ stdenv.mkDerivation {
168168
hsdeps = builtins.attrValues {
169169
Cabal = hackageTarball "Cabal" "3.0.0.0" "11yjd0cmqngi1yr7v0dr55n59rq78kk6121sr44abha0swkfqhsi" { rev = 1; sha256 = "0dgyim2sm867sd365xp6vhmfalx98ykm5i4jlpkacvghbv52x1ph"; };
170170
ansi-terminal = hackageTarball "ansi-terminal" "0.10.1" "1b168z688b1lg4d2bmbxmm2mj51mwm2wv0smfb1vcwjp2vzpqf9i" {};
171-
ansi-wl-pprint = hackageTarball "ansi-wl-pprint" "0.6.9" "1b2fg8px98dzbaqyns10kvs8kn6cl1hdq5wb9saz40izrpkyicm7" { rev = 3; sha256 = "1km10sx7ldyv1vfyljik1gqnrwl7bnq2s5m40w41gc930vm48891"; };
171+
ansi-wl-pprint = hackageTarball "ansi-wl-pprint" "0.6.9" "1b2fg8px98dzbaqyns10kvs8kn6cl1hdq5wb9saz40izrpkyicm7" { rev = 4; sha256 = "04ljsk64bzwsczh0zc5w3r98qr1zlzbwwm2xb6nk9vradv4pnwzv"; };
172172
cabal-fmt = hackageTarball "cabal-fmt" "0.1.1" "07hx1s7l5zmh7vs2zmmm56msz2m7wnzn919mvnpypvrsswmmnnd9" {};
173173
colour = hackageTarball "colour" "2.3.5" "1rq4l46jx4lpdppy71wf7m1n7pw2jwy788rm35ycwzb1g4clg39v" {};
174174
optparse-applicative = hackageTarball "optparse-applicative" "0.15.1.0" "1ws6y3b3f6hsgv0ff0yp6lw4hba1rps4dnvry3yllng0s5gngcsd" { rev = 1; sha256 = "0zmhqkd96v2z1ilhqdkd9z4jgsnsxb8yi2479ind8m5zm9363zr9"; };

cabal-bundler/fixtures/fetch-with-curl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cat <<EOF > SHA256SUMS
77
f0862eca5ef06da6e6a592c452a747a953e52adce6f66246d3c7a0aa458dfe35 Cabal-3.0.0.0.cabal
88
5143ec26d740c1a508c93a8860e64407e7546c29b9817db20ff1595c1968d287 Cabal-3.0.0.0.tar.gz
99
31397cff165772b6c3725583cd45e535145945ad7dd5251a79342c84cc4726ac ansi-terminal-0.10.1.tar.gz
10-
212144ea0623b1170807a4162db05d87f26cf10b334aeadd0edb377aba06a1ce ansi-wl-pprint-0.6.9.cabal
10+
fb737bc96e2aef34ad595d54ced7a73f648c521ebcb00fe0679aff45ccd49212 ansi-wl-pprint-0.6.9.cabal
1111
a7b2e8e7cd3f02f2954e8b17dc60a0ccd889f49e2068ebb15abfa1d42f7a4eac ansi-wl-pprint-0.6.9.tar.gz
1212
a9595b2bd73aefebafdd358564bfe5a78aafab29b5d62ff43eb0fe428f0e1d1e cabal-fmt-0.1.1.tar.gz
1313
3b8d471979617dce7c193523743c9782df63433d8e87e3ef6d97922e0da104e7 colour-2.3.5.tar.gz
@@ -19,7 +19,7 @@ EOF
1919
curl --silent --location --output Cabal-3.0.0.0.cabal 'http://hackage.haskell.org/package/Cabal-3.0.0.0/revision/1.cabal'
2020
curl --silent --location --output Cabal-3.0.0.0.tar.gz 'http://hackage.haskell.org/package/Cabal-3.0.0.0/Cabal-3.0.0.0.tar.gz'
2121
curl --silent --location --output ansi-terminal-0.10.1.tar.gz 'http://hackage.haskell.org/package/ansi-terminal-0.10.1/ansi-terminal-0.10.1.tar.gz'
22-
curl --silent --location --output ansi-wl-pprint-0.6.9.cabal 'http://hackage.haskell.org/package/ansi-wl-pprint-0.6.9/revision/3.cabal'
22+
curl --silent --location --output ansi-wl-pprint-0.6.9.cabal 'http://hackage.haskell.org/package/ansi-wl-pprint-0.6.9/revision/4.cabal'
2323
curl --silent --location --output ansi-wl-pprint-0.6.9.tar.gz 'http://hackage.haskell.org/package/ansi-wl-pprint-0.6.9/ansi-wl-pprint-0.6.9.tar.gz'
2424
curl --silent --location --output cabal-fmt-0.1.1.tar.gz 'http://hackage.haskell.org/package/cabal-fmt-0.1.1/cabal-fmt-0.1.1.tar.gz'
2525
curl --silent --location --output colour-2.3.5.tar.gz 'http://hackage.haskell.org/package/colour-2.3.5/colour-2.3.5.tar.gz'

cabal-bundler/fixtures/openbsd-ports.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ MODCABAL_VERSION = 0.1.1
33
MODCABAL_MANIFEST = \
44
Cabal 3.0.0.0 1 \
55
ansi-terminal 0.10.1 0 \
6-
ansi-wl-pprint 0.6.9 3 \
6+
ansi-wl-pprint 0.6.9 4 \
77
colour 2.3.5 0 \
88
optparse-applicative 0.15.1.0 1 \
99
transformers-compat 0.6.5 0 \

cabal-docspec/MANUAL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ However, in this list we mostly only list and show the --option version of them.
6161
Especially outputs are assumed to be Haskell-like.
6262
Default **\--no-strip-comments**.
6363

64+
**-Z, \--ignore-trailing-space**
65+
66+
: Strip trailing whitespace from the produced outputs.
67+
Default **\--no-ignore-trailing-space**.
68+
6469
**\--setup** *expr*
6570

6671
: An additional expression to execute as setup for all examples.

cabal-docspec/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
VERSION=0.0.0.20230406
1+
VERSION=0.0.0.20230517
22
EXETARGET=cabal-docspec
33

44
cabal-docspec.1 : MANUAL.md
5-
echo '.TH CABAL-DOCSPEC 1 "April 6th, 2023" "cabal-docspec $(VERSION)" "Cabal Extras"' > cabal-docspec.1
5+
echo '.TH CABAL-DOCSPEC 1 "May 17th, 2023" "cabal-docspec $(VERSION)" "Cabal Extras"' > cabal-docspec.1
66
pandoc -f markdown -t man MANUAL.md >> cabal-docspec.1
77

88
man : cabal-docspec.1

cabal-docspec/cabal-docspec.1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH CABAL-DOCSPEC 1 "April 6th, 2023" "cabal-docspec 0.0.0.20230406" "Cabal Extras"
1+
.TH CABAL-DOCSPEC 1 "May 17th, 2023" "cabal-docspec 0.0.0.20230517" "Cabal Extras"
22
.SH NAME
33
.PP
44
cabal-docspec - another doctest for Haskell
@@ -72,6 +72,10 @@ Strip Haskell comments from examples and the outputs.
7272
Especially outputs are assumed to be Haskell-like.
7373
Default \f[B]--no-strip-comments\f[R].
7474
.TP
75+
\f[B]-Z, --ignore-trailing-space\f[R]
76+
Strip trailing whitespace from the produced outputs.
77+
Default \f[B]--no-ignore-trailing-space\f[R].
78+
.TP
7579
\f[B]--setup\f[R] \f[I]expr\f[R]
7680
An additional expression to execute as setup for all examples.
7781
Can be specified multiple times.

cabal-docspec/cabal-docspec.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: cabal-docspec
3-
version: 0.0.0.20211114
3+
version: 0.0.0.20230517
44
synopsis: Run examples in your docs
55
category: Development
66
description:

cabal-docspec/src/CabalDocspec/Opts.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ data DynOpts = DynOpts
2727
{ optPhase :: Phase
2828
, optPreserveIt :: PreserveIt
2929
, optStripComs :: StripComments
30+
, optStripEOL :: StripEOL
3031
, optExts :: [String]
3132
, optTimeout :: Double
3233
, optTimeoutMsg :: String -- ^ timeout response
@@ -45,6 +46,7 @@ defaultDynOpts = DynOpts
4546
{ optPhase = Phase2
4647
, optPreserveIt = DontPreserveIt
4748
, optStripComs = DontStripComments
49+
, optStripEOL = DontStripEOL
4850
, optExts = []
4951
, optTimeout = 3
5052
, optTimeoutMsg = "* Hangs forever *"
@@ -62,6 +64,7 @@ newtype Verbosity = Verbosity Int deriving (Eq, Ord, Show)
6264
data PreserveIt = PreserveIt | DontPreserveIt deriving (Eq, Show)
6365
data CabalPlan = CabalPlan | NoCabalPlan deriving (Eq, Show)
6466
data StripComments = StripComments | DontStripComments deriving (Eq, Show)
67+
data StripEOL = StripEOL | DontStripEOL deriving (Eq, Show)
6568

6669
data Properties
6770
= SkipProperties
@@ -145,6 +148,7 @@ dynOptsP = pure combine
145148
<*> phaseP
146149
<*> preserveItP
147150
<*> stripComsP
151+
<*> stripEolP
148152
<*> listP extP
149153
<*> timeoutP
150154
<*> timeoutMsgP
@@ -166,8 +170,8 @@ dynOptsP = pure combine
166170
monoidP :: Monoid a => O.Parser a -> O.Parser (a -> a)
167171
monoidP p = (\xs ys -> mconcat (ys : xs)) <$> many p
168172

169-
combine f1 f2 f3 f4 f5 f6 f7 f8 f9 fA fB fC fD fE (DynOpts x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE) =
170-
DynOpts (f1 x1) (f2 x2) (f3 x3) (f4 x4) (f5 x5) (f6 x6) (f7 x7) (f8 x8) (f9 x9) (fA xA) (fB xB) (fC xC) (fD xD) (fE xE)
173+
combine f1 f2 f3 f4 f5 f6 f7 f8 f9 fA fB fC fD fE fG (DynOpts x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xG) =
174+
DynOpts (f1 x1) (f2 x2) (f3 x3) (f4 x4) (f5 x5) (f6 x6) (f7 x7) (f8 x8) (f9 x9) (fA xA) (fB xB) (fC xC) (fD xD) (fE xE) (fG xG)
171175

172176
lastOpt :: [a] -> a -> a
173177
lastOpt xs initial = foldl' (\_ x -> x) initial xs
@@ -195,6 +199,18 @@ stripComsP = lastOpt <$> many (on <|> off) where
195199
on = O.flag' StripComments $ O.long "strip-comments" <> O.help "Strip comments in examples"
196200
off = O.flag' DontStripComments $ O.long "no-strip-comments" <> O.help "Don't strip comments in examples"
197201

202+
-- $ diff --help
203+
-- <...>
204+
-- -E, --ignore-tab-expansion ignore changes due to tab expansion
205+
-- -Z, --ignore-trailing-space ignore white space at line end
206+
-- -b, --ignore-space-change ignore changes in the amount of white space
207+
-- -w, --ignore-all-space ignore all white space
208+
-- -B, --ignore-blank-lines ignore changes where lines are all blank
209+
stripEolP :: O.Parser (StripEOL -> StripEOL)
210+
stripEolP = lastOpt <$> many (on <|> off) where
211+
on = O.flag' StripEOL $ O.short 'Z' <> O.long "ignore-trailing-space" <> O.help "Ignore white space at line end"
212+
off = O.flag' DontStripEOL $ O.long "no-ignore-trailing-space" <> O.help "Don't ingore white space at line end"
213+
198214
propertiesP :: O.Parser (Properties -> Properties)
199215
propertiesP = lastOpt <$> many (skip <|> simple) where
200216
skip = O.flag' SkipProperties $ O.long "no-check-properties" <> O.help "Skip properties (default)"

cabal-docspec/src/CabalDocspec/Phase2.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Text.PrettyPrint.Annotated (Doc, ($$))
1414
import qualified Cabal.Config as Cabal
1515
import qualified Data.Map as Map
1616
import qualified Data.Set as Set
17-
import qualified System.Console.ANSI as ANSI
1817

1918
import CabalDocspec.Doctest.Example
2019
import CabalDocspec.Doctest.Extract
@@ -180,7 +179,14 @@ phase2 tracer dynOpts unitIds ghcInfo mbuildDir cabalCfg cwd extraEnv parsed = d
180179

181180
Example expr expected -> do
182181
result <- eval tracer ghci preserveIt timeout timeoutMsg expr
183-
case mkResult expected (lines result) of
182+
183+
let ls = lines result
184+
-- --strip-trailing-whitespace
185+
let ls' = case optStripEOL dynOpts of
186+
StripEOL -> map (dropWhileEnd isSpace) ls
187+
DontStripEOL -> ls
188+
189+
case mkResult expected ls' of
184190
Equal -> do
185191
return (Left (acc <> mempty { sExamples = ssSuccess }))
186192
NotEqual diff -> do

0 commit comments

Comments
 (0)