Skip to content
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

customized comparisons for output #63

Open
aavogt opened this issue Sep 30, 2013 · 1 comment
Open

customized comparisons for output #63

aavogt opened this issue Sep 30, 2013 · 1 comment
Assignees

Comments

@aavogt
Copy link
Collaborator

aavogt commented Sep 30, 2013

I use doctest to check that some types can be properly inferred. I would like some way to customize the comparison so that the following tests would be accepted:

This fails because a isn't b... though they mean exactly the same thing:

{- |
>>>  let p = (+) :: Num b => b -> b -> b
>>> :t p
p :: Num a => a -> a -> a
-}

This fails because of whitespace.... sometimes ghc breaks type signatures
into different lines

{- |
>>>  let p = (+) :: Num b => b -> b -> b
>>> :t p
p :: Num a =>
             a -> a -> a
-}

As far as I know, there is no way to get a String in ghci out of :type, so I can't even do something confusing like:

{- |
>>> let x = show (1 + 1) ++ " next"
>>> let canonicalize = filter (/=' ')
>>> let expectedX = "2next"
>>> canonicalize x == canonicalize expectedX
True
-}

One idea might be to make the comparison happen in the ghci session using whatever == is in scope (or some other/better function name). In other words,

{- |
>>> let (==) a b = canonicalize a Prelude.== canonicalize b
>>> 1+1
2
<BLANKLINE>
3
-}

will send two lines to ghci like:

let (==) a b  = canonicalize a Prelude.== canonicalize b
show (1+1) == "2\n3"
@ghost ghost assigned aavogt Sep 30, 2013
@sol
Copy link
Owner

sol commented Sep 30, 2013

Not sure what to do here. My first impression is "too much hassle for no gain". But then again, what may be no gain for me, may be important to you. So if you really feel like hacking on this, go for it, but be prepared that we bikeshed it to death if it gets ugly..

aavogt added a commit to aavogt/doctest-haskell that referenced this issue Oct 2, 2013
No tests exist for the comparison function yet.
In other words, I removed Runner.Example.mkResult and
the replacement has no unit tests.

The default doctestEq is also slightly different with respect to
trailing whitespace, so there is a test failure:

  Main.doctest ignores trailing whitespace when matching test output FAILED
  trailing-whitespace ["Foo.hs"]
aavogt added a commit to aavogt/doctest-haskell that referenced this issue Oct 7, 2013
aavogt added a commit to aavogt/doctest-haskell that referenced this issue Jun 28, 2014
No tests exist for the comparison function yet.
In other words, I removed Runner.Example.mkResult and
the replacement has no unit tests.

The default doctestEq is also slightly different with respect to
trailing whitespace, so there is a test failure:

  Main.doctest ignores trailing whitespace when matching test output FAILED
  trailing-whitespace ["Foo.hs"]
aavogt added a commit to aavogt/doctest-haskell that referenced this issue Jun 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants