From 9748caf7a4004c7072632022570b7bf1511aac1e Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Fri, 15 Nov 2024 09:40:57 +0700 Subject: [PATCH] solid-pp: Use `errorBundlePrettyForGhcPreProcessors` --- cabal.project.freeze | 6 ++-- solid-pp/package.yaml | 2 +- solid-pp/solid-pp.cabal | 6 ++-- solid-pp/src/Solid/PP/Parser.hs | 2 +- solid-pp/test/Solid/PP/ParserSpec.hs | 18 +++--------- solid-pp/test/Solid/PPSpec.hs | 42 +++++----------------------- 6 files changed, 19 insertions(+), 57 deletions(-) diff --git a/cabal.project.freeze b/cabal.project.freeze index 71a540f6..01dfab74 100644 --- a/cabal.project.freeze +++ b/cabal.project.freeze @@ -183,7 +183,7 @@ constraints: any.Cabal ==3.12.1.0, any.lukko ==0.1.2, lukko +ofd-locking, any.markdown-unlit ==0.6.0, - any.megaparsec ==9.6.1, + any.megaparsec ==9.7.0, megaparsec -dev, any.memory ==0.18.0, memory +support_bytestring +support_deepseq, @@ -272,7 +272,7 @@ constraints: any.Cabal ==3.12.1.0, splitmix -optimised-mixer, any.stack ==3.1.1, stack -developer-mode -disable-git-info -disable-stack-upload -hide-dependency-versions -integration-tests -static -supported-build, - any.static-bytes ==0.1.0, + any.static-bytes ==0.1.1, any.stm ==2.5.3.1, any.stm-chans ==3.0.0.9, any.streaming-commons ==0.2.2.6, @@ -335,4 +335,4 @@ constraints: any.Cabal ==3.12.1.0, zip-archive -executable, any.zlib ==0.7.1.0, zlib -bundled-c-zlib +non-blocking-ffi +pkg-config -index-state: hackage.haskell.org 2024-09-09T02:04:10Z +index-state: hackage.haskell.org 2024-11-24T13:26:28Z diff --git a/solid-pp/package.yaml b/solid-pp/package.yaml index 9d7f82e0..f3631f38 100644 --- a/solid-pp/package.yaml +++ b/solid-pp/package.yaml @@ -20,7 +20,7 @@ dependencies: - ghc-boot - text - bytestring - - megaparsec + - megaparsec >= 9.7.0 - parser-combinators build-tools: alex diff --git a/solid-pp/solid-pp.cabal b/solid-pp/solid-pp.cabal index 9e599499..5169ba40 100644 --- a/solid-pp/solid-pp.cabal +++ b/solid-pp/solid-pp.cabal @@ -41,7 +41,7 @@ library , containers , ghc ==9.10.1 , ghc-boot - , megaparsec + , megaparsec >=9.7.0 , parser-combinators , text , transformers @@ -63,7 +63,7 @@ executable solid-pp , containers , ghc ==9.10.1 , ghc-boot - , megaparsec + , megaparsec >=9.7.0 , parser-combinators , solid-pp , text @@ -116,7 +116,7 @@ test-suite spec , ghc-boot , hspec ==2.* , hspec-expectations >=0.8.3 - , megaparsec + , megaparsec >=9.7.0 , mockery , parser-combinators , text diff --git a/solid-pp/src/Solid/PP/Parser.hs b/solid-pp/src/Solid/PP/Parser.hs index ee8c228d..d4800c59 100644 --- a/solid-pp/src/Solid/PP/Parser.hs +++ b/solid-pp/src/Solid/PP/Parser.hs @@ -197,7 +197,7 @@ parse parser language extensions line original current = do stream :: TokenStream stream = TokenStream original.contents result.tokens case P.parse parser original.name stream of - Left err -> Left $ errorBundlePretty err + Left err -> Left $ errorBundlePrettyForGhcPreProcessors err Right r -> Right r token :: (Token -> Maybe a) -> Parser a diff --git a/solid-pp/test/Solid/PP/ParserSpec.hs b/solid-pp/test/Solid/PP/ParserSpec.hs index aa05e78a..3edbc4c0 100644 --- a/solid-pp/test/Solid/PP/ParserSpec.hs +++ b/solid-pp/test/Solid/PP/ParserSpec.hs @@ -345,13 +345,7 @@ spec = do it "reports an error" $ do parseModule "\"foo " `Hspec.shouldBe` Left "main.hs:1:9: error: [GHC-21231]\n lexical error in string/character literal at end of input" let Left err = parseModule "\"foo { " - err `Hspec.shouldBe` (unpack . unlines) [ - "main.hs:1:7:" - , " |" - , "1 | \"foo { " - , " | ^" - , "unterminated string interpolation" - ] + err `Hspec.shouldBe` "main.hs:1:7:unterminated string interpolation" context "unexpected token" $ do it "reports an error" $ do @@ -361,11 +355,7 @@ spec = do , "some more tokens" ] - err `Hspec.shouldBe` (unpack . unlines) [ - "main.hs:2:5:" - , " |" - , "2 | bar ].foo" - , " | ^" - , "unexpected ]" - , "expecting end of input" + err `Hspec.shouldBe` (unpack . T.intercalate "\n") [ + "main.hs:2:5: unexpected ]" + , " expecting end of input" ] diff --git a/solid-pp/test/Solid/PPSpec.hs b/solid-pp/test/Solid/PPSpec.hs index b78e2d0d..5045560e 100644 --- a/solid-pp/test/Solid/PPSpec.hs +++ b/solid-pp/test/Solid/PPSpec.hs @@ -201,13 +201,9 @@ spec = do , "" , "foo , bar" ] - run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [ - "src.hs:3:5:" - , " |" - , "3 | foo , bar" - , " | ^" - , "unexpected ," - , "expecting end of input" + run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.intercalate "\n" [ + "src.hs:3:5: unexpected ," + , " expecting end of input" ]) it "takes LINE pragmas into account" $ do @@ -224,13 +220,7 @@ spec = do , "{-# LINE 3 \"src.hs\" #-}" , "foo = (" ] - run "src.hs" "cur.hs" "dst.hs" `shouldReturn` Failure (List.unlines [ - "src.hs:3:8:" - , " |" - , "3 | foo = (" - , " | ^" - , "unexpected end of input" - ]) + run "src.hs" "cur.hs" "dst.hs" `shouldReturn` Failure "src.hs:3:8:unexpected end of input" context "when pre-processing imports" $ do it "implicitly imports well-know modules" $ do @@ -519,13 +509,7 @@ spec = do ".foo :: Int" , ".foo = undefined" ] - run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [ - "src.hs:2:1:" - , " |" - , "2 | .foo = undefined" - , " | ^" - , "invalid method type (arity must be at least 1)" - ]) + run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:1:invalid method type (arity must be at least 1)" context "with incorrect indentation" $ do it "reports an error" $ do @@ -533,13 +517,7 @@ spec = do ".foo :: Int -> Int" , " .foo = undefined" ] - run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [ - "src.hs:2:2:" - , " |" - , "2 | .foo = undefined" - , " | ^" - , "incorrect indentation (got 2, should be equal to 1)" - ]) + run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:2:incorrect indentation (got 2, should be equal to 1)" context "when method names do not match" $ do it "reports an error" $ do @@ -547,13 +525,7 @@ spec = do ".foo :: Int -> Int" , ".bar = undefined" ] - run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure (List.unlines [ - "src.hs:2:2:" - , " |" - , "2 | .bar = undefined" - , " | ^" - , "unexpected method name \"bar\", expecting \"foo\"" - ]) + run "src.hs" "src.hs" "dst.hs" `shouldReturn` Failure "src.hs:2:2:unexpected method name \"bar\", expecting \"foo\"" context "when pre-processing identifiers" $ do it "desugars postfix bangs" $ do