nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
706 stars 119 forks source link

Quickcheck warns about commented-out properties #52

Open andreasabel opened 9 years ago

andreasabel commented 9 years ago

Applies to ver. 2.8.1

{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All
{-
prop_old_freeVars_Term conf x = True
-}
-- Template Haskell hack to make the following $quickCheckAll work under ghc-7.8.
return [] 
-- | All tests as collected by 'quickCheckAll'.
tests :: IO Bool
tests = do
  putStrLn "Agda.TypeChecking.Free.Tests"
  $quickCheckAll

gives warning

/home/abel/agda/src/full/Agda/TypeChecking/Free/Tests.hs:129:3: Warning:
    Name prop_old_freeVars_Term found in source file but was not in scope

which turns into error with -Werror

nick8325 commented 9 years ago

Hi,

This is definitely unfortunate. The problem is that Template Haskell gives (AFAIK) no way to find all the names in scope. So quickCheckAll works by reading the source file (!) and looking for lines that start with prop_.

The warning is mostly there so that if you forget the return [] you get a warning instead of it just testing nothing. But in this case it gives a false positive. One workaround is to make the line not start with prop_, e.g. by using a single-line -- comment instead of a multi-line one. I'll leave the bug open though until we have a fix.

andreasabel commented 9 years ago

A week ago or so I went looking for a tool that would strip comments from Haskell files. Surprisingly, I did not find anything that is correct, fast, and works with unicode. Should not be so hard to write that DFA. Maybe Ana should give it as homework in her class.

alanz commented 9 years ago

If you use getRichTokenStream, filter out the comments, and then showRichTokenStream the GHC lexer will be able to help.

https://downloads.haskell.org/~ghc/latest/docs/html/libraries/ghc-7.10.1/GHC.html#g:33

andreasabel commented 9 years ago

Yes, but this is too heavy-weight (depending on GHC).

asr commented 7 years ago

The comments could be stripped using haskell-src-exts.

Example:

nick8325 commented 7 years ago

That introduces rather a big dependency though. Maybe haskell-lexer could be an alternative.

asr commented 6 years ago

@andreasabel, please note that {-# LANGUAGE TemplateHaskell #-} is missing in the OP.