Skip to content

Commit

Permalink
Warn on spaces in module names
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jan 20, 2021
1 parent 9f0b49b commit 7c25383
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Hpack/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 7c25383

Please sign in to comment.