mihaimaruseac / hindent

Haskell pretty printer
Other
561 stars 113 forks source link

Test suite failure with hindent-5.2.4 #453

Closed DanBurton closed 7 years ago

DanBurton commented 7 years ago

(As seen on the stackage build server) The output was very long, but the diff for each failing case was something to the effect of:

                 The diff:
                 3,4c3
                 <   case month of
                 <     "Jan" -> 1
                 ---
                 >   case month of"Jan" -> 1

Where case statements were expected to be multi-lined, but were actually one-lined. Also note that there seems to be a space missing between of and the first clause in the "actual" output.

This appears to be indicative of a bug so I'll hold back this version from stackage until I hear more about what's going on with this.

sighingnow commented 7 years ago

Hi, @DanBurton, thanks for your reporting. However I can't reproduce the test failure with ghc-8.2.1 and stack nightly-2017-10-21 solver.

Could be provide me the build log ? Or where could I find the build log on stackage's build server ?

DanBurton commented 7 years ago

Here is how I reproduced the issue on my machine:

$ stack unpack hindent-5.2.4
$ cd hindent-5.2.4
$ stack init --resolver nightly-2017-10-21
$ stack test

Here's the test output


Modules
  Extension pragmas
  Module header
  Exports
  Exports, indentation 4
Imports
  Import lists
  Sorted
  Explicit imports - capitals first (typeclasses/types), then operators, then identifiers
  Pretty import specification
Declarations
  Type declaration
  Type declaration with infix promoted type constructor
  Instance declaration without decls
  Instance declaration with decls
  GADT declarations
Expressions
  Lazy patterns in a lambda
  Bang patterns in a lambda
  List comprehensions, short
  List comprehensions, long
  List comprehensions with operators
  Parallel list comprehension, short
  Parallel list comprehension, long
  Record, short
  Record, medium
  Record, long
  Cases FAILED [1]
  Operators, bad
  Operators, good
     # PENDING: No reason given
  Operator with `do`
  Operator with lambda
  Operator with lambda-case
  Type application
  Transform list comprehensions
  Type families
  Type family annotations
  Type family instances
  Type family dependencies
  Binding implicit parameters
  Closed type families
Template Haskell
  Expression brackets
  Pattern brackets
  Type brackets
Type signatures
  Long argument list should line break
  Class constraints should leave `::` on same line
  Class constraints
  Tuples
  Quasiquotes in types
  Default signatures
  Implicit parameters
  Promoted list (issue #348)
  Promoted list with a tuple (issue #348)
Function declarations
  Prefix notation for operators
  Where clause
  Guards and pattern guards FAILED [2]
  Multi-way if FAILED [3]
  Case inside a `where` and `do` FAILED [4]
  Let inside a `where`
  Lists
  Long line, function application
  Long line, tuple
  Long line, tuple section
Record syntax
  Pattern matching, short
  Pattern matching, long
Johan Tibell compatibility checks
  Basic example from Tibbe's style
  Data declarations
  Spaces between deriving classes
  Hanging lambdas
Comments
  Comments within a declaration FAILED [5]
  Doesn't work yet (wrong comment position detection)
     # PENDING: No reason given
  Haddock comments
  Comments around regular declarations
  Multi-line comments FAILED [6]
  Multi-line comments with multi-line contents
Regression tests
  jml Adds trailing whitespace when wrapping #221 FAILED [7]
  meditans hindent freezes when trying to format this code #222
  bitemyapp wonky multiline comment handling #231
  cocreature removed from declaration issue #186
  sheyll explicit forall in instances #218
  tfausak support shebangs #208
  joe9 preserve newlines between import groups
  Wrapped import list shouldn't add newline
  radupopescu `deriving` keyword not aligned with pipe symbol for type declarations
  sgraf812 top-level pragmas should not add an additional newline #255
  ivan-timokhin breaks code with type operators #277
  ivan-timokhin variables swapped around in constraints #278
  ttuegel qualified infix sections get mangled #273
  ivan-timokhin breaks operators type signatures #301
  cdepillabout Long deriving clauses are not reformatted #289
  ivan-timokhin Breaks instances with type operators #342
  neongreen "{" is lost when formatting "Foo{}" #366
  jparoz Trailing space in list comprehension #357
  ttuegel Record formatting applied to expressions with RecordWildCards #274
  RecursiveDo `rec` and `mdo` keyword #328
  sophie-h Record syntax change in 5.2.2 #393
  k-bx Infix data constructor gets reformatted into a parse error #328
  tfausak Class constraints cause too many newlines #244
  expipiplus1 Always break before `::` on overlong signatures #390
  duog Long Type Constraint Synonyms are not reformatted #290
  ocharles Type application differs from function application (leading to long lines) #359
  NorfairKing Do as left-hand side of an infix operation #296
  NorfairKing Hindent linebreaks after very short names if the total line length goes over 80 #405
  ivan-timokhin No linebreaks for long functional dependency declarations #323
  utdemir Hindent breaks TH name captures of operators #412
  utdemir Hindent can not parse empty case statements #414
  TimoFreiberg INLINE (and other) pragmas for operators are reformatted without parens #415
  NorfairKing Hindent breaks servant API's #417
  andersk Cannot parse @: operator #421
  andersk Corrupts parenthesized type operators #422
  NorfairKing Infix constructor pattern is broken #424
  NorfairKing Hindent can no longer parse type applications code #426
  michalrus Multiline `GHC.TypeLits.Symbol`s are being broken #451
  DavidEichmann Existential Quantification reordered #443
MINIMAL pragma
  Monad example
  Very long names #310
Behaviour checks
  Unicode
  Empty module
  Trailing newline is preserved
Complex input
  A complex, slow-to-print decl FAILED [8]
  Random snippet from hindent itself
  Quasi quotes

Failures:

  src/main/Test.hs:75: 
  1) Expressions Cases
       expected: 
                 strToMonth :: String -> Int
                 strToMonth month =
                   case month of
                     "Jan" -> 1
                     "Feb" -> 2
                     _ -> error $ "Unknown month " ++ month
        but got: 
                 strToMonth :: String -> Int
                 strToMonth month =
                   case month of"Jan" -> 1
                     "Feb" -> 2
                     _ -> error $ "Unknown month " ++ month
                 The diff:
                 3,4c3
                 <   case month of
                 <     "Jan" -> 1
                 ---
                 >   case month of"Jan" -> 1

  src/main/Test.hs:75: 
  2) Function declarations Guards and pattern guards
       expected: 
                 f x
                   | x <- Just x
                   , x <- Just x =
                     case x of
                       Just x -> e
                   | otherwise = do e
                   where
                     x = y
        but got: 
                 f x
                   | x <- Just x
                   , x <- Just x = case x ofJust x -> e
                   | otherwise = do e
                   where
                     x = y
                 The diff:
                 3,5c3
                 <   , x <- Just x =
                 <     case x of
                 <       Just x -> e
                 ---
                 >   , x <- Just x = case x ofJust x -> e

  src/main/Test.hs:75: 
  3) Function declarations Multi-way if
       expected: 
                 x =
                   if | x <- Just x,
                        x <- Just x ->
                        case x of
                          Just x -> e
                          Nothing -> p
                      | otherwise -> e
        but got: 
                 x =
                   if | x <- Just x,
                        x <- Just x ->
                        case x ofJust x -> e
                          Nothing -> p
                      | otherwise -> e
                 The diff:
                 4,5c4
                 <        case x of
                 <          Just x -> e
                 ---
                 >        case x ofJust x -> e

  src/main/Test.hs:75: 
  4) Function declarations Case inside a `where` and `do`
       expected: 
                 g x =
                   case x of
                     a -> x
                   where
                     foo =
                       case x of
                         _ -> do
                           launchMissiles
                       where
                         y = 2
        but got: 
                 g x = case x ofa -> x
                   where
                     foo =
                       case x of_ -> do
                           launchMissiles
                       where
                         y = 2
                 The diff:
                 1,3c1
                 < g x =
                 <   case x of
                 <     a -> x
                 ---
                 > g x = case x ofa -> x
                 6,7c4
                 <       case x of
                 <         _ -> do
                 ---
                 >       case x of_ -> do

  src/main/Test.hs:75: 
  5) Comments Comments within a declaration
       expected: 
                 bob -- after bob
                  =
                   foo -- next to foo
                   -- line after foo
                     (bar
                        foo -- next to bar foo
                        bar -- next to bar
                      ) -- next to the end paren of (bar)
                     -- line after (bar)
                     mu -- next to mu
                     -- line after mu
                     -- another line after mu
                     zot -- next to zot
                     -- line after zot
                     (case casey -- after casey
                            of
                        Just -- after Just
                         -> do
                          justice -- after justice
                           *
                            foo
                              (blah * blah + z + 2 / 4 + a - -- before a line break
                               2 * -- inside this mess
                               z /
                               2 /
                               2 /
                               aooooo /
                               aaaaa -- bob comment
                               ) +
                            (sdfsdfsd fsdfsdf) -- blah comment
                          putStrLn "")
                     [1, 2, 3]
                     [ 1 -- foo
                     , ( 2 -- bar
                       , 2.5 -- mu
                        )
                     , 3
                     ]
                     -- in the end of the function
                   where
                     alpha = alpha
                     -- between alpha and beta
                     beta = beta
                     -- after beta

                 foo = 1 -- after foo

                 gamma = do
                   delta
                   epsilon
                   -- in the end of a do-block 1

                 gamma = do
                   delta
                   epsilon
                   -- the very last block is detected differently
        but got: 
                 bob -- after bob
                  =
                   foo -- next to foo
                   -- line after foo
                     (bar
                        foo -- next to bar foo
                        bar -- next to bar
                      ) -- next to the end paren of (bar)
                     -- line after (bar)
                     mu -- next to mu
                     -- line after mu
                     -- another line after mu
                     zot -- next to zot
                     -- line after zot
                     (case casey -- after casey
                            ofJust -- after Just
                         -> do
                          justice -- after justice
                           *
                            foo
                              (blah * blah + z + 2 / 4 + a - -- before a line break
                               2 * -- inside this mess
                               z /
                               2 /
                               2 /
                               aooooo /
                               aaaaa -- bob comment
                               ) +
                            (sdfsdfsd fsdfsdf) -- blah comment
                          putStrLn "")
                     [1, 2, 3]
                     [ 1 -- foo
                     , ( 2 -- bar
                       , 2.5 -- mu
                        )
                     , 3
                     ]
                     -- in the end of the function
                   where
                     alpha = alpha
                     -- between alpha and beta
                     beta = beta
                     -- after beta

                 foo = 1 -- after foo

                 gamma = do
                   delta
                   epsilon
                   -- in the end of a do-block 1

                 gamma = do
                   delta
                   epsilon
                   -- the very last block is detected differently
                 The diff:
                 16,17c16
                 <            of
                 <        Just -- after Just
                 ---
                 >            ofJust -- after Just

  src/main/Test.hs:75: 
  6) Comments Multi-line comments
       expected: 
                 bob {- after bob -}
                  =
                   foo {- next to foo -}
                   {- line after foo -}
                     (bar
                        foo {- next to bar foo -}
                        bar {- next to bar -}
                      ) {- next to the end paren of (bar) -}
                     {- line after (bar) -}
                     mu {- next to mu -}
                     {- line after mu -}
                     {- another line after mu -}
                     zot {- next to zot -}
                     {- line after zot -}
                     (case casey {- after casey -}
                            of
                        Just {- after Just -}
                         -> do
                          justice {- after justice -}
                           *
                            foo
                              (blah * blah + z + 2 / 4 + a - {- before a line break -}
                               2 * {- inside this mess -}
                               z /
                               2 /
                               2 /
                               aooooo /
                               aaaaa {- bob comment -}
                               ) +
                            (sdfsdfsd fsdfsdf) {- blah comment -}
                          putStrLn "")
                     [1, 2, 3]
                     [ 1 {- foo -}
                     , ( 2 {- bar -}
                       , 2.5 {- mu -}
                        )
                     , 3
                     ]

                 foo = 1 {- after foo -}
        but got: 
                 bob {- after bob -}
                  =
                   foo {- next to foo -}
                   {- line after foo -}
                     (bar
                        foo {- next to bar foo -}
                        bar {- next to bar -}
                      ) {- next to the end paren of (bar) -}
                     {- line after (bar) -}
                     mu {- next to mu -}
                     {- line after mu -}
                     {- another line after mu -}
                     zot {- next to zot -}
                     {- line after zot -}
                     (case casey {- after casey -}
                            ofJust {- after Just -}
                         -> do
                          justice {- after justice -}
                           *
                            foo
                              (blah * blah + z + 2 / 4 + a - {- before a line break -}
                               2 * {- inside this mess -}
                               z /
                               2 /
                               2 /
                               aooooo /
                               aaaaa {- bob comment -}
                               ) +
                            (sdfsdfsd fsdfsdf) {- blah comment -}
                          putStrLn "")
                     [1, 2, 3]
                     [ 1 {- foo -}
                     , ( 2 {- bar -}
                       , 2.5 {- mu -}
                        )
                     , 3
                     ]

                 foo = 1 {- after foo -}
                 The diff:
                 16,17c16
                 <            of
                 <        Just {- after Just -}
                 ---
                 >            ofJust {- after Just -}

  src/main/Test.hs:75: 
  7) Regression tests jml Adds trailing whitespace when wrapping #221
       expected: 
                 x = do
                   config <- execParser options
                   comments <-
                     case config of
                       Diff False args -> commentsFromDiff args
                       Diff True args -> commentsFromDiff ("--cached" : args)
                       Files args -> commentsFromFiles args
                   mapM_ (putStrLn . Fixme.formatTodo) (concatMap Fixme.getTodos comments)
        but got: 
                 x = do
                   config <- execParser options
                   comments <-
                     case config ofDiff False args -> commentsFromDiff args
                       Diff True args -> commentsFromDiff ("--cached" : args)
                       Files args -> commentsFromFiles args
                   mapM_ (putStrLn . Fixme.formatTodo) (concatMap Fixme.getTodos comments)
                 The diff:
                 4,5c4
                 <     case config of
                 <       Diff False args -> commentsFromDiff args
                 ---
                 >     case config ofDiff False args -> commentsFromDiff args

  src/main/Test.hs:75: 
  8) Complex input A complex, slow-to-print decl
       expected: 
                 quasiQuotes =
                   [ ( ''[]
                     , \(typeVariable:_) _automaticPrinter ->
                         (let presentVar = varE (presentVarName typeVariable)
                          in lamE
                               [varP (presentVarName typeVariable)]
                               [|(let typeString = "[" ++ fst $(presentVar) ++ "]"
                                  in ( typeString
                                     , \xs ->
                                         case fst $(presentVar) of
                                           "GHC.Types.Char" ->
                                             ChoicePresentation
                                               "String"
                                               [ ( "String"
                                                 , StringPresentation
                                                     "String"
                                                     (concatMap
                                                        getCh
                                                        (map (snd $(presentVar)) xs)))
                                               , ( "List of characters"
                                                 , ListPresentation
                                                     typeString
                                                     (map (snd $(presentVar)) xs))
                                               ]
                                             where getCh (CharPresentation "GHC.Types.Char" ch) =
                                                     ch
                                                   getCh (ChoicePresentation _ ((_, CharPresentation _ ch):_)) =
                                                     ch
                                                   getCh _ = ""
                                           _ ->
                                             ListPresentation
                                               typeString
                                               (map (snd $(presentVar)) xs)))|]))
                   ]
        but got: 
                 quasiQuotes =
                   [ ( ''[]
                     , \(typeVariable:_) _automaticPrinter ->
                         (let presentVar = varE (presentVarName typeVariable)
                          in lamE
                               [varP (presentVarName typeVariable)]
                               [|(let typeString = "[" ++ fst $(presentVar) ++ "]"
                                  in ( typeString
                                     , \xs ->
                                         case fst $(presentVar) of"GHC.Types.Char" ->
                                             ChoicePresentation
                                               "String"
                                               [ ( "String"
                                                 , StringPresentation
                                                     "String"
                                                     (concatMap
                                                        getCh
                                                        (map (snd $(presentVar)) xs)))
                                               , ( "List of characters"
                                                 , ListPresentation
                                                     typeString
                                                     (map (snd $(presentVar)) xs))
                                               ]
                                             where getCh (CharPresentation "GHC.Types.Char" ch) =
                                                     ch
                                                   getCh (ChoicePresentation _ ((_, CharPresentation _ ch):_)) =
                                                     ch
                                                   getCh _ = ""
                                           _ ->
                                             ListPresentation
                                               typeString
                                               (map (snd $(presentVar)) xs)))|]))
                   ]
                 The diff:
                 10,11c10
                 <                         case fst $(presentVar) of
                 <                           "GHC.Types.Char" ->
                 ---
                 >                         case fst $(presentVar) of"GHC.Types.Char" ->

Randomized with seed 988171000

Finished in 0.0548 seconds
118 examples, 8 failures, 2 pending
sighingnow commented 7 years ago

I found that I have uploaded the wrong sdist file to hackage. I bump up the version to 5.2.4.1 and mark the version 5.2.4 as deprecated version on hackage.

How can I make the version 5.2.4.1 can be used in stackage's next nightly build plan ? Should I submit a pull request to remove the version constraints of hindent ?

DanBurton commented 7 years ago

How can I make the version 5.2.4.1 can be used in stackage's next nightly build plan ? Should I submit a pull request to remove the version constraints of hindent ?

Yes, please!