Skip to content

Commit

Permalink
Don't use unsafePerformIO without need
Browse files Browse the repository at this point in the history
  • Loading branch information
sol authored and mrkkrp committed Jan 2, 2023
1 parent 9cdb3e9 commit e7da6bc
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tests/Ormolu/PrinterSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit e7da6bc

Please sign in to comment.