From 7c2538376cde315f7d026ac893a38748b72ebf4c Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Thu, 21 Jan 2021 00:58:38 +0700 Subject: [PATCH] Warn on spaces in module names --- src/Hpack/Module.hs | 6 +++++- test/EndToEndSpec.hs | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Hpack/Module.hs b/src/Hpack/Module.hs index cc849919..8bb2b573 100644 --- a/src/Hpack/Module.hs +++ b/src/Hpack/Module.hs @@ -33,7 +33,11 @@ instance IsString Module where fromString = Module instance FromValue Module where - fromValue = fmap Module . fromValue + fromValue v = do + r <- fromValue v + case words r of + [name] -> return (Module name) + _ -> warn ("invalid module name " ++ show r) >> return (Module r) toModule :: Path -> Module toModule path = case reverse $ Path.components path of diff --git a/test/EndToEndSpec.hs b/test/EndToEndSpec.hs index 227de42b..bf2b702c 100644 --- a/test/EndToEndSpec.hs +++ b/test/EndToEndSpec.hs @@ -70,6 +70,17 @@ spec = around_ (inTempDirectoryNamed "foo") $ do "package.yaml: Duplicate field $.name" ] + context "when a module name contains spaces" $ do + it "warns" $ do + [i| + name: foo + library: + other-modules: + Foo + Bar + Baz + |] `shouldWarn` ["package.yaml: invalid module name \"Foo Bar Baz\" in $.library.other-modules"] + describe "handling of Paths_ module" $ do it "adds Paths_ to other-modules" $ do [i|