doctest icon indicating copy to clipboard operation
doctest copied to clipboard

Interplay of >>> and prop>

Open sgraf812 opened this issue 7 years ago • 5 comments

Consider this:

-- |
-- >>> let x = 1
-- prop> x == 1
main = putStrLn "Hello World"

This complains that the output of let x = 1 didn't match prop> x == 1. If the prop> were a >>> instead, this would at least pass the first line (independent of #174, which would happen the line after).

sgraf812 avatar Nov 16 '17 10:11 sgraf812

Thanks for reporting. It is not entirely clear what feature you are requesting here. Could you elaborate more, e.g. on the expected behavior?

andreasabel avatar Jan 03 '18 18:01 andreasabel

The line after >>> is always parsed as expected output (as long as it doesn't start with >>>). So, currently the above doctest states that the assignment let x = 1 should output the string prop> x == 1, which of course it doesn't.

This is rather surprising behavior, I rather expected that the second line would declare an ordinary quickcheck property.

A workaround is to insert an empty line inbetween, as in #174.

sgraf812 avatar Jan 06 '18 21:01 sgraf812

I think this is an extension of #174. As we currently don't share the scope between properties and examples, code like

-- >>> let x = 1
-- prop> x == 1

is not something you commonly want to write.

@sgraf812 can you check what haddock does here. If haddock parses this as an example and a property then we want to do the same in doctest.

sol avatar Jan 07 '18 09:01 sol

Judging from this function, haddock will most likely parse this as example + result. That makes no observable difference for haddock, I think, because results and properties are formatted the same. It does to doctest, though.

Maybe we should fix haddock first (e.g. add a property case to resultAndMoreExamples)? Also, wouldn't it make sense for doctest to depend on the haddock parser directly if we keep compatibility between the two anyway?

sgraf812 avatar Jan 07 '18 09:01 sgraf812

The problem might be solved by multi-line properties: #131.

amigalemming avatar Mar 25 '20 10:03 amigalemming