-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Haddock tests #5
Conversation
spec :: Spec | ||
spec = describe "EntityHaddockSpec" $ do | ||
it "generates entity Haddock" $ do | ||
maybeDoc <- runQ $ getDoc (DeclDoc 'CommentModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grepping ghc
codebase for Template Haskell failure
gets us this:
badIO :: String -> IO a
badIO op = do { qReport True ("Can't do `" ++ op ++ "' in the IO monad")
; fail "Template Haskell failure" }
Which is kind of an awful error - the actual reason is interleaved within the test output, here.
I think what you'll want to do here is splice the doc into the file, and then you can write assertions on the doc in a spec. Like,
[d|
commentModelDoc :: String
commentModelDoc =
$(lift =<< getDoc (DeclDoc 'CommentModel))
|]
spec = describe "EntityHaddockSpec" $ do
it "generates entity haddock" $ do
commentModelDoc `shouldBe` "..."
Or, if you want a compilation failure, you could write the whole "test" in the splice.
module Test where
import Doc
do
maybeDoc <- getDoc (DeclDoc 'CommentModel)
case maybeDoc of
Nothing -> reportError "Expected doc for CommentModel"
Just doc -> do
let expected = "..."
when (doc /= expected) $ do
reportError "Expected doc to be different..."
pure [] -- to satisfy the `Q [Dec]` type for a top level splice
But this is probably much less easy to write, and won't get you nice error message rendering. But it will fail faster, so idk. hspec-compilation
is begging to be born I guess lol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've completed EntityHaddockSpec
using the former method. However, the test output shows that it only finds the field comment added using putDoc
- attempting to get the Haddock for CommentModel
(added using withDecDoc
) returns Nothing
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now fixed - I'd put 'CommentModel
(constructor Name
) instead of ''CommentModel
(type Name
) in the splice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh goodness - I guess you can write, like,
-- | commentary for type
data Thing =
-- | commentary for constructor
MkThing
Great catch 😄
CommentSpec is compiled with -haddock to ensure that documentation added using putDoc and withDecDoc is available.
This reverts commit dce3941.
PR created in fork for CI testing.