Merge branch 'master' into opts-in-lib
This commit is contained in:
commit
d47c9f1205
@ -46,8 +46,10 @@ loadMappedFileSource :: IOish m
|
|||||||
-> GhcModT m ()
|
-> GhcModT m ()
|
||||||
loadMappedFileSource from src = do
|
loadMappedFileSource from src = do
|
||||||
tmpdir <- cradleTempDir `fmap` cradle
|
tmpdir <- cradleTempDir `fmap` cradle
|
||||||
|
enc <- liftIO . mkTextEncoding . optEncoding =<< options
|
||||||
to <- liftIO $ do
|
to <- liftIO $ do
|
||||||
(fn, h) <- openTempFile tmpdir (takeFileName from)
|
(fn, h) <- openTempFile tmpdir (takeFileName from)
|
||||||
|
hSetEncoding h enc
|
||||||
hPutStr h src
|
hPutStr h src
|
||||||
hClose h
|
hClose h
|
||||||
return fn
|
return fn
|
||||||
|
@ -175,6 +175,11 @@ globalArgSpec = Options
|
|||||||
<=> metavar "OPT"
|
<=> metavar "OPT"
|
||||||
<=> help "Option to be passed to GHC"
|
<=> help "Option to be passed to GHC"
|
||||||
<*> many fileMappingSpec
|
<*> many fileMappingSpec
|
||||||
|
<*> strOption
|
||||||
|
$$ long "encoding"
|
||||||
|
<=> value "UTF-8"
|
||||||
|
<=> showDefault
|
||||||
|
<=> help "I/O encoding"
|
||||||
where
|
where
|
||||||
fileMappingSpec =
|
fileMappingSpec =
|
||||||
getFileMapping . splitOn '=' <$> strOption
|
getFileMapping . splitOn '=' <$> strOption
|
||||||
|
@ -105,6 +105,7 @@ data Options = Options {
|
|||||||
-- | GHC command line options set on the @ghc-mod@ command line
|
-- | GHC command line options set on the @ghc-mod@ command line
|
||||||
, optGhcUserOptions :: [GHCOption]
|
, optGhcUserOptions :: [GHCOption]
|
||||||
, optFileMappings :: [(FilePath, Maybe FilePath)]
|
, optFileMappings :: [(FilePath, Maybe FilePath)]
|
||||||
|
, optEncoding :: String
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
-- | A default 'Options'.
|
-- | A default 'Options'.
|
||||||
@ -124,6 +125,7 @@ defaultOptions = Options {
|
|||||||
}
|
}
|
||||||
, optGhcUserOptions = []
|
, optGhcUserOptions = []
|
||||||
, optFileMappings = []
|
, optFileMappings = []
|
||||||
|
, optEncoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
@ -34,9 +34,12 @@ handler = flip gcatches
|
|||||||
]
|
]
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main =
|
||||||
hSetEncoding stdout utf8
|
parseArgs >>= \res@(globalOptions, _) -> do
|
||||||
parseArgs >>= \res@(globalOptions, _) ->
|
enc <- mkTextEncoding $ optEncoding globalOptions
|
||||||
|
hSetEncoding stdout enc
|
||||||
|
hSetEncoding stderr enc
|
||||||
|
hSetEncoding stdin enc
|
||||||
catches (progMain res) [
|
catches (progMain res) [
|
||||||
Handler $ \(e :: GhcModError) ->
|
Handler $ \(e :: GhcModError) ->
|
||||||
runGmOutT globalOptions $ exitError $ renderStyle ghcModStyle (gmeDoc e)
|
runGmOutT globalOptions $ exitError $ renderStyle ghcModStyle (gmeDoc e)
|
||||||
@ -107,7 +110,6 @@ getFileSourceFromStdin = do
|
|||||||
then fmap (x:) readStdin'
|
then fmap (x:) readStdin'
|
||||||
else return []
|
else return []
|
||||||
|
|
||||||
-- Someone please already rewrite the cmdline parsing code *weep* :'(
|
|
||||||
wrapGhcCommands :: (IOish m, GmOut m) => Options -> GhcModCommands -> m ()
|
wrapGhcCommands :: (IOish m, GmOut m) => Options -> GhcModCommands -> m ()
|
||||||
wrapGhcCommands _opts CmdRoot = gmPutStr =<< rootInfo
|
wrapGhcCommands _opts CmdRoot = gmPutStr =<< rootInfo
|
||||||
wrapGhcCommands opts cmd =
|
wrapGhcCommands opts cmd =
|
||||||
|
@ -123,13 +123,13 @@ spec = do
|
|||||||
res <- runD $ do
|
res <- runD $ do
|
||||||
loadMappedFile "File.hs" "File_Redir_Lint.hs"
|
loadMappedFile "File.hs" "File_Redir_Lint.hs"
|
||||||
lint defaultLintOpts "File.hs"
|
lint defaultLintOpts "File.hs"
|
||||||
res `shouldBe` "File.hs:4:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
res `shouldBe` "File.hs:4:1: Warning: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
||||||
it "lints in-memory file if one is specified and outputs original filename" $ do
|
it "lints in-memory file if one is specified and outputs original filename" $ do
|
||||||
withDirectory_ "test/data/file-mapping" $ do
|
withDirectory_ "test/data/file-mapping" $ do
|
||||||
res <- runD $ do
|
res <- runD $ do
|
||||||
loadMappedFileSource "File.hs" "func a b = (++) a b\n"
|
loadMappedFileSource "File.hs" "func a b = (++) a b\n"
|
||||||
lint defaultLintOpts "File.hs"
|
lint defaultLintOpts "File.hs"
|
||||||
res `shouldBe` "File.hs:1:1: Error: Eta reduce\NULFound:\NUL func a b = (++) a b\NULWhy not:\NUL func = (++)\n"
|
res `shouldBe` "File.hs:1:1: Warning: Eta reduce\NULFound:\NUL func a b = (++) a b\NULWhy not:\NUL func = (++)\n"
|
||||||
it "shows types of the expression for redirected files" $ do
|
it "shows types of the expression for redirected files" $ do
|
||||||
let tdir = "test/data/file-mapping"
|
let tdir = "test/data/file-mapping"
|
||||||
res <- runD' tdir $ do
|
res <- runD' tdir $ do
|
||||||
@ -184,14 +184,14 @@ spec = do
|
|||||||
res <- runD $ do
|
res <- runD $ do
|
||||||
loadMappedFile "File.hs" "File_Redir_Lint.hs"
|
loadMappedFile "File.hs" "File_Redir_Lint.hs"
|
||||||
lint defaultLintOpts "File.hs"
|
lint defaultLintOpts "File.hs"
|
||||||
res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
res `shouldBe` "File.hs:6:1: Warning: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
||||||
it "lints in-memory file if one is specified and outputs original filename" $ do
|
it "lints in-memory file if one is specified and outputs original filename" $ do
|
||||||
withDirectory_ "test/data/file-mapping/preprocessor" $ do
|
withDirectory_ "test/data/file-mapping/preprocessor" $ do
|
||||||
src <- readFile "File_Redir_Lint.hs"
|
src <- readFile "File_Redir_Lint.hs"
|
||||||
res <- runD $ do
|
res <- runD $ do
|
||||||
loadMappedFileSource "File.hs" src
|
loadMappedFileSource "File.hs" src
|
||||||
lint defaultLintOpts "File.hs"
|
lint defaultLintOpts "File.hs"
|
||||||
res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
res `shouldBe` "File.hs:6:1: Warning: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
|
||||||
describe "literate haskell tests" $ do
|
describe "literate haskell tests" $ do
|
||||||
it "checks redirected file if one is specified and outputs original filename" $ do
|
it "checks redirected file if one is specified and outputs original filename" $ do
|
||||||
withDirectory_ "test/data/file-mapping/lhs" $ do
|
withDirectory_ "test/data/file-mapping/lhs" $ do
|
||||||
|
@ -9,7 +9,7 @@ spec = do
|
|||||||
describe "lint" $ do
|
describe "lint" $ do
|
||||||
it "can detect a redundant import" $ do
|
it "can detect a redundant import" $ do
|
||||||
res <- runD $ lint defaultLintOpts "test/data/hlint/hlint.hs"
|
res <- runD $ lint defaultLintOpts "test/data/hlint/hlint.hs"
|
||||||
res `shouldBe` "test/data/hlint/hlint.hs:4:8: Error: Redundant do\NULFound:\NUL do putStrLn \"Hello, world!\"\NULWhy not:\NUL putStrLn \"Hello, world!\"\n"
|
res `shouldBe` "test/data/hlint/hlint.hs:4:8: Warning: Redundant do\NULFound:\NUL do putStrLn \"Hello, world!\"\NULWhy not:\NUL putStrLn \"Hello, world!\"\n"
|
||||||
|
|
||||||
context "when no suggestions are given" $ do
|
context "when no suggestions are given" $ do
|
||||||
it "doesn't output an empty line" $ do
|
it "doesn't output an empty line" $ do
|
||||||
|
Loading…
Reference in New Issue
Block a user