Stéphane Laurent
Stéphane Laurent

Reputation: 84659

Stack error when running benchmarks (tasty-bench)

I try to include some benchmarks in my Haskell package and running stack bench generates an error:

Benchmark benchmarks: RUNNING...
All
  Fibonacci numbers
    fifth:     OK (4.28s)
      247  ns ±  17 ns
    tenth:     OK (5.88s)
Completed 3 action(s).

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       <stderr>: commitAndReleaseBuffer: invalid argument (cannot encode character '\956')

Here is the relevant part of the cabal file:

benchmark benchmarks
  type:                 exitcode-stdio-1.0
  main-is:              Main.hs
  hs-source-dirs:       benchmarks/
  Build-Depends:        base >= 4.7 && < 5
                      , tasty-bench
                      , hspray
  default-language:     Haskell2010

And here is the code:

module Main where
import Test.Tasty.Bench ( bench, bgroup, defaultMain, nf )

fibo :: Int -> Integer
fibo n = if n < 2 then toInteger n else fibo (n - 1) + fibo (n - 2)

main :: IO ()
main = defaultMain
  [ bgroup "Fibonacci numbers"
    [ bench "fifth"     $ nf fibo  5
    , bench "tenth"     $ nf fibo 10
    , bench "twentieth" $ nf fibo 20
    ]
  ]

I upgraded stack and I ran stack clean. I use the latest lts release of ghc. I'm on Windows.

Upvotes: 1

Views: 92

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84659

Running chcp 65001 in the console before running stack bench solved this problem.

Upvotes: 1

Related Questions