testing compile errors - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Torsten Schmits

anyone know of a comfy method to run a code snippet (like a quasiquote) in the current environment and extract the error message as a string?
like I want to run a tasty test I check like this:

test = do
  err <- extractCompileError?? [|5 :: Text|]
  assert (err == "No instance (Num Text)")

I looked at hint and th-test-utils, but they were both unsuitable.

Torsten Schmits

my provisional solution will be to put the tested expression in a separate file, turning on -fdeferred-type-errors and catching TypeError in the test!

Joel McCracken

I know Franklin Chen had something like this at some point, IIRC I think he solved it how you say you are solving it

Joel McCracken

I shot him an email asking about it

Torsten Schmits

there's should-not-typecheck on hackage that leverages this for hunit

Joel McCracken

Ah yes, that helped me find what I was looking for: https://github.com/FranklinChen/twenty-four-days2015-of-hackage/blob/2d452a9ce3133a908aa3058bf8a2fea5b06246f1/test/ShouldNotTypecheckExampleSpec.hs

My own little "24 Days of Hackage" for 2015. Contribute to FranklinChen/twenty-four-days2015-of-hackage development by creating an account on GitHub.