-
Notifications
You must be signed in to change notification settings - Fork 74
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
Import statements get counted as separate tests #95
Comments
Isn't this a good thing? The import statements are commands that your users are expected to type into ghci. If they don't work for some reason, I want the test suite to fail. But suppose we didn't count the import statements as tests. So we ignore them if they fail. What good can come if it? if an import fails, the subsequent tests will probably fail anyway. But if the subsequent tests do pass, then you have a useless import, which is something I'd like to know! If I know the import is failing but the rest of the test suite works, I can simply remove the import. |
It's a single output, hence a single example. Import statements are only an environment for this example. If they fail, the test should fail. I'm really surprised someone can look at it another way. |
If import failure implies test failure, aren't imports "tests" then? =) I see what you're saying -- that all you really want to test is output -- but it's hard to differentiate. It might be nice to have another output statistic, "nonempty output lines" or something like that. But consider the following test:
which also tests something that produces no output. You want that to fail if the |
Testing import statements - that is definitely something new. Though a documentation with examples, which produce no visible result, could be another hit. Please pardon my sarcasm, but it is very hard to come up with a reply to this that is any more delicate. |
Ok, so the -- | This module makes heavy use of the 'GHC.Generics' module, and the
-- associated \"DeriveGeneric\" extension which allows instances of 'Generic'
-- to be, well, derived. First, we'll need to enable a few GHC extensions:
--
-- >>> :set -XDeriveGeneric
-- >>> :set -XNoMonomorphismRestriction
--
-- We'll also need to import the 'Generics' module from GHC:
--
-- >>> import GHC.Generics
--
-- With that out of the way, we can now define a new data type which
-- automatically derives its 'Generic' instance:
--
-- >>> data Foo = Bar Int Int Int deriving (Show, Generic)
--
-- This should give you a feel for how the typeclass and extension are used below.
--
module Main
where
main :: IO ()
main = putStrLn "Actual code goes here." None of the |
@nikita-volkov Doctest is agnostic about what kind of statements you feed it. So it can not differentiate import statements from expressions that produce output. This has the advantage that
What we could change is how we count examples. Currently every line that starts with a I'm not very opinionated about it, but I most likely will not invest any cycles in that myself. But if somebody has a vision and wants to outline a different approach, let's go for it. |
@orlitzky ah yea, what you said makes sense, but also brings up a lot of complexity.
-- | MyTest
-- >>> 1 + 2
-- >>> 2 + 3
-- 5
-- | MyTest2
-- >>> let foo = 2
-- >>> foo + 4
-- 6
-- | MyTest3
-- >>> import Control.Concurrent.MVar
-- >>> newEmptyMVar
-- >>> newEmptyMVar
--
-- | MyTest4
-- >>> putStr ""
-- >>> putStr "foo"
-- >>> putStr "bar"
-- bar
-- | MyTest5
-- >>> data Foo = Foo deriving Show
-- >>> Foo
-- >>> Foo
-- Foo
@orlitzky also, your example you provided is kind of weird when you think about it. Because it doesn't look like your asserting anything, it just looks like your documenting the setup of a multiline test. Since you can't write: -- >>> import GHC.Generics
-- With that out of the way, we can now define a new data type which
-- automatically derives its 'Generic' instance: Though it doesn't look like it to a human, there's actually an assertion here. -- >>> import GHC.Generics
-- "" <-- Is this really an explicit assertion by the programmer? It just looks like whitespacing to me.
-- With that out of the way, we can now define a new data type which @sol I've just thought about it for a bit, and I think that's a great idea to leave all the behavior how it is, and just treat a single Haddock comment as a test. Since if one assert in the chain fails, the all the rest of the Also, it's normal for a programmer to do multiple assertions in a single test. Finally, it relates to #106 since I had already assumed the entire Haddock comment was treated as one test internally. 😄 |
If the import statement outputs something other than |
I have only a single doctest, which is the following:
Executing doctest on it, produces the following summary:
Version: doctest-0.9.11.1
The text was updated successfully, but these errors were encountered: