Skip to content
This repository has been archived by the owner on May 29, 2021. It is now read-only.

Commit

Permalink
Only print emojis for Unicode-capable terminals
Browse files Browse the repository at this point in the history
isUnicodeLocale will not update if setLocaleEncoding is called, but as
the test runner shouldn't need to do so, that should be safe.
  • Loading branch information
ag-eitilt authored and joelburget committed Sep 22, 2018
1 parent fdf6106 commit e3f1261
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/EasyTest/Porcelain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.CallStack
import System.Exit
import System.IO
import qualified Control.Concurrent.Async as A
import qualified Data.Map as Map
import qualified System.Random as Random
Expand Down Expand Up @@ -95,7 +96,20 @@ atomicLogger = do
pure $ \msg ->
-- force msg before acquiring lock
let dummy = T.foldl' (\_ ch -> ch == 'a') True msg
in dummy `seq` bracket (takeMVar lock) (\_ -> putMVar lock ()) (\_ -> T.putStrLn msg)
in dummy `seq` bracket (takeMVar lock) (\_ -> putMVar lock ()) (\_ -> T.putStrLn $ sanitize msg)

sanitize :: Text -> Text
sanitize msg = if isUnicodeLocale
then msg
else T.replace "" "!"
. T.replace "" "X"
. T.replace "😶" ":/"
. T.replace "👍" ":D"
. T.replace "🎉" ":P"
$ msg

isUnicodeLocale :: Bool
isUnicodeLocale = elem (show localeEncoding) $ map show [utf8, utf8_bom, utf16, utf16le, utf16be, utf32, utf32le, utf32be]

-- | A test with a setup and teardown
using :: IO r -> (r -> IO ()) -> (r -> Test a) -> Test a
Expand Down

0 comments on commit e3f1261

Please sign in to comment.