mirror of
https://github.com/tweag/ormolu.git
synced 2024-10-05 17:37:11 +03:00
Don't use unsafePerformIO
without need
This commit is contained in:
parent
9cdb3e93b0
commit
e7da6bc4c2
@ -17,7 +17,6 @@ import Path
|
||||
import Path.IO
|
||||
import System.Environment (lookupEnv)
|
||||
import qualified System.FilePath as F
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
@ -51,7 +50,7 @@ checkExample srcPath' = it (fromRelFile srcPath' ++ " works") . withNiceExceptio
|
||||
formatted0 <- ormoluFile config inputPath
|
||||
-- 3. Check the output against expected output. Thus all tests should
|
||||
-- include two files: input and expected output.
|
||||
when shouldRegenerateOutput $
|
||||
whenShouldRegenerateOutput $
|
||||
T.writeFile (fromRelFile expectedOutputPath) formatted0
|
||||
expected <- readFileUtf8 $ fromRelFile expectedOutputPath
|
||||
shouldMatch False formatted0 expected
|
||||
@ -112,7 +111,7 @@ withNiceExceptions m = m `catch` h
|
||||
h :: OrmoluException -> IO ()
|
||||
h = expectationFailure . displayException
|
||||
|
||||
shouldRegenerateOutput :: Bool
|
||||
shouldRegenerateOutput =
|
||||
unsafePerformIO $ isJust <$> lookupEnv "ORMOLU_REGENERATE_EXAMPLES"
|
||||
{-# NOINLINE shouldRegenerateOutput #-}
|
||||
whenShouldRegenerateOutput :: IO () -> IO ()
|
||||
whenShouldRegenerateOutput action = do
|
||||
shouldRegenerateOutput <- isJust <$> lookupEnv "ORMOLU_REGENERATE_EXAMPLES"
|
||||
when shouldRegenerateOutput action
|
||||
|
Loading…
Reference in New Issue
Block a user