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

test-framework-th does not respect comments #3

Open
sol opened this issue Jun 7, 2011 · 3 comments
Open

test-framework-th does not respect comments #3

sol opened this issue Jun 7, 2011 · 3 comments

Comments

@sol
Copy link
Contributor

sol commented Jun 7, 2011

This works:

{-# LANGUAGE TemplateHaskell #-}
module ResponseTest where

import Test.Framework.TH
import Test.Framework.Providers.QuickCheck2

main = $(defaultMainGenerator)

prop_reverse xs = reverse (reverse xs) == xs
  where types = xs::[Int]

But the following does not:

{-# LANGUAGE TemplateHaskell #-}
module ResponseTest where

import Test.Framework.TH
import Test.Framework.Providers.QuickCheck2

main = $(defaultMainGenerator)

prop_reverse xs = reverse (reverse xs) == xs
  where types = xs::[Int]

{-
prop_foo = foo
 -}
@finnsson
Copy link
Owner

Darn. Previously test-generator used haskell-src-exts to parse the source code so it probably used to respect comments, but I had problems with haskell-src-exts and extensions that the parser did not support so I switched to just split each line and search for "prop_" och "case_" in the beginning of lines. This had the consequence that the parser cannot identity which lines are inside comments. I guess a solution would be to strip lines between {- and -}. I'll take a look at the problem during the weekend.

@Toxaris
Copy link

Toxaris commented Nov 15, 2011

The same issue also applies to *.lhs files:

> module Broken where
> 
> import Test.Framework.TH
> import Test.Framework
> import Test.HUnit
> import Test.Framework.Providers.HUnit

case_nonexistent is not a Haskell function, but just text.

> case_ignored = do 1 @=? 1
>
> main = $(defaultMainGenerator)

The defaultMainGenerator ignores case_ignored but picks case_nonexistent up. Compilation then fails with the following error message:

Broken.lhs:11:12:
    Not in scope: `case_nonexistent'
    In the result of the splice:
      $defaultMainGenerator

This means that test-framework-th is not yet usable with literate Haskell files.

@uuner
Copy link

uuner commented Dec 30, 2015

This issue is caused by language-haskell-extract that simply reads first lexemas on every line to extract functions.
You can't even have anything starting from whitespace and "case_" or "prop_" in a where clause or in the beginning of any new line.
For example, these two test will be broken too:

case_test = let case_const = "llo" in "hello" @=? ("he" ++
    case_const)

case_test2 = "hello" @=? ("he" ++ case_const2)
  where
  case_const2 = "llo"

Pull request 10 in template-helper should fix the issue with comments and the above examples: finnsson/template-helper#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants