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

$(defaultMainGenerator) and imports #3

Closed
decentral1se opened this issue Feb 15, 2016 · 5 comments
Closed

$(defaultMainGenerator) and imports #3

decentral1se opened this issue Feb 15, 2016 · 5 comments

Comments

@decentral1se
Copy link

In the following snippet:

module Main where

import Test.Tasty
import Test.Tasty.TH
import Test.Tasty.Quickcheck

import AllMyPropTests

main :: IO ()
main = $(defaultMainGenerator)

If I have all my quickcheck properties defined (as prop_*) in test/AllMyPropTests, should the properties be picked up and run?

It isn't working for me so far, but I have a strange use case. I am trying to create a new Tasty plugin which does test discovery, and I think the API would be greatly improved by using tasty-th. The implementation is 'borrowed' from the awesome hspec and their discover implementation.

The Tasty plugins pre processed output will be the following code which will auto import all test modules under the users test directory. Then, the main generator would generate the boilerplate to run the tests.

I'd really like to get this working. Is there some TemplateHaskell limitation here? Any help really appreciated.

@bennofs
Copy link
Owner

bennofs commented Feb 16, 2016

The reason that this does not work is that tasty-th currently does the following:

So perhaps, for your use case, I could add a function to generate a TestTree given a file name from which to read the properties? Since you already detect all the files, you could then just use that and write your main similar to this:

main :: IO ()
main = defaultMain $ testGroup "yourTestName"
  [ $(generateTestTree "FileFoo.hs")
  , $(generateTestTree "FIleBar.hs")
  , ...
  ]

Or even better, we could split the "detect the names of properties from a file" and "generate a test tree from property function names" into two separate functions, the first of which would take a file name.

@decentral1se
Copy link
Author

Ah, right. I understand. It would be awesome if you could make that happen.

Also, generateTestTree could grab of all the case_* tests as well, I hope 👍

@bennofs
Copy link
Owner

bennofs commented Feb 16, 2016

Ok, you should now be able to use "extractTestFunctions" + "defaultMainGeneratorFor" to achieve your goal: just use extractTestFunctions in your plugin, and then generate a file which contains defaultMainGeneratorFor <name of the toplevel test group> <all found test functions>. I'll make a hackage release soon, after travis tests finish.

@decentral1se
Copy link
Author

Brilliant, thank you, I will let you know how it goes when I get a chance 🚀

@bennofs
Copy link
Owner

bennofs commented Feb 16, 2016

You're welcome, hackage release is done.

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

2 participants