diff --git a/README.md b/README.md index 8daf13d..edff2fd 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,12 @@ look for another way to speed up generation of Fibonacci numbers. : commitBuffer: invalid argument (cannot encode character '\177') ``` + or + + ``` + : 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) diff --git a/src/Test/Tasty/Bench.hs b/src/Test/Tasty/Bench.hs index a0de30c..c3423a5 100644 --- a/src/Test/Tasty/Bench.hs +++ b/src/Test/Tasty/Bench.hs @@ -366,6 +366,10 @@ another way to speed up generation of Fibonacci numbers. > : commitBuffer: invalid argument (cannot encode character '\177') + or + + > : 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 @@ -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) @@ -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 ()