Skip to content

Commit

Permalink
Bracket changes to locale encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Dec 22, 2024
1 parent c8d6743 commit ca3b084
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ look for another way to speed up generation of Fibonacci numbers.
<stdout>: commitBuffer: invalid argument (cannot encode character '\177')
```

or

```
<stdout>: commitBuffer: invalid argument (cannot encode character '\956')
```

it means that your locale does not support UTF-8. `tasty-bench` makes an effort
to force locale to UTF-8, but sometimes, when benchmarks are a part of
a larger application, it's [impossible](https://gitlab.haskell.org/ghc/ghc/-/issues/23606)
Expand Down
18 changes: 14 additions & 4 deletions src/Test/Tasty/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ another way to speed up generation of Fibonacci numbers.
> <stdout>: commitBuffer: invalid argument (cannot encode character '\177')
or
> <stdout>: commitBuffer: invalid argument (cannot encode character '\956')
it means that your locale does not support UTF-8. @tasty-bench@
makes an effort to force locale to UTF-8, but sometimes, when
benchmarks are a part of a larger application, it’s
Expand Down Expand Up @@ -706,7 +710,7 @@ import qualified Prelude
import Control.Applicative
import Control.Arrow (first, second)
import Control.DeepSeq (NFData, force, rnf)
import Control.Exception (bracket, evaluate)
import Control.Exception (bracket, bracket_, evaluate)
import Control.Monad (void, unless, guard, (>=>), when)
import Data.Foldable (foldMap, traverse_)
import Data.Int (Int64)
Expand Down Expand Up @@ -1307,12 +1311,18 @@ type Benchmark = TestTree
defaultMain :: [Benchmark] -> IO ()
defaultMain bs = do
let act = defaultMain' bs
setLocaleEncoding utf8
prevLocaleEnc <- getLocaleEncoding
#if defined(mingw32_HOST_OS)
codePage <- getConsoleOutputCP
bracket (setConsoleOutputCP 65001) (const $ setConsoleOutputCP codePage) (const act)
bracket_
(setLocaleEncoding utf8 >>setConsoleOutputCP 65001)
(setLocaleEncoding prevLocaleEnc >> setConsoleOutputCP codePage)
act
#else
act
bracket_
(setLocaleEncoding utf8)
(setLocaleEncoding prevLocaleEnc)
act
#endif

defaultMain' :: [Benchmark] -> IO ()
Expand Down

0 comments on commit ca3b084

Please sign in to comment.