Git Product home page Git Product logo

test-generator's People

Contributors

dag avatar finnsson avatar hvriedel avatar kazu-yamamoto avatar sol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

test-generator's Issues

Support custom test groups

Such that if I have

test_someTests :: [Test]
test_someTests = [ testCase ... ]

tests = $testGroupGenerator

The generator will pick it up as

tests = testGroup "SomeModule" [ testGroup "someTests" test_someTests, ... ]

test-framework already supports nested groups like this, and I'd like to use it to make some generated test cases show more detail in the output. It also makes it possible to run individual tests with greater control, and also parallelizes better.

test-framework-th does not work with GeneralizedNewtypeDeriving or TypeSynonymInstances

$(defaultMainGenerator) is not seeing the arbitary instance of Results.

Yet $quickCheckAll, from quickchek, works for these, so must be possible

Example TypeSynonymInstances Code:

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE OverlappingInstances #-}
module Main where

import ClassyPrelude
import qualified Data.Map as Map
import Test.HUnit
import Data.Number.Fixed
import Test.QuickCheck hiding (Result)
import Test.QuickCheck.All
import Test.Framework.TH
import Test.Framework
import Test.Framework.Providers.QuickCheck2

type Result = (Int,Int)

instance Arbitrary Result where
    arbitrary = elements resultElements

resultMax = 3

resultElements :: [Result]
resultElements = [(h,a)| h <- [0..resultMax], a <- [0..resultMax]]

type Results = Map Result Rational

instance Monoid Results where
    mempty = empty
    mappend = Map.unionWith (+)

instance Arbitrary Results where
    arbitrary = do
      rs <-listOf $ elements resultElements
      ws <-listOf $ elements [1, 1.5 .. 2]
      return $ Map.fromListWith (+) $ zip rs ws

main = do
    runTests1
    runTests2
    return ()


prop_resultsAdd :: Results -> Results -> Bool
prop_resultsAdd rs1 rs2 = mappend rs1 rs2 == mappend rs2 rs1

runTests1 = $quickCheckAll
runTests2 = $(defaultMainGenerator)


Error: No instance for (Arbitrary (Map Result Rational))

Example GeneralizedNewtypeDeriving Code:

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main2 where

import ClassyPrelude
import qualified Data.Map as Map
import Test.HUnit
import Data.Number.Fixed
import Test.QuickCheck hiding (Result)
import Test.QuickCheck.All
import Test.Framework.TH
import Test.Framework
import Test.Framework.Providers.QuickCheck2

newtype Result = Result (Int,Int) deriving (Show,Eq,Ord)


instance Arbitrary Result where
    arbitrary = elements resultElements

resultMax = 3

resultElements :: [Result]
resultElements = [Result (h,a)| h <- [0..resultMax], a <- [0..resultMax]]

newtype Results = Results (Map Result Rational) deriving (Eq,Ord, Show)

instance Monoid Results where
    mempty = Results empty
    mappend (Results r1)(Results r2) = Results $ Map.unionWith (+) r1 r2

instance Arbitrary Results where
    arbitrary = do
      rs <-listOf $ elements resultElements
      ws <-listOf $ elements [1, 1.5 .. 2]
      return . Results . Map.fromListWith (+) $ zip rs ws

main = do
    runTests1
    runTests2
    return ()

runTests1 = $quickCheckAll
runTests2 = $(defaultMainGenerator)

prop_resultsAdd :: Results -> Results -> Bool
prop_resultsAdd rs1 rs2 = mappend rs1 rs2 == mappend rs2 rs1

Error: No instance for (Arbitrary Results)

doco fix

neither the github readme nor the hackage page contain a runnable program - they should import Test.Framework.TH

Compile error suppression

If I create a test file with an error in it and then add a property, I get an error like this:

test/Properties.hs:14:10:
    Not in scope: ‘prop_analyzeReturnsSameForEquals’
    In the splice: $defaultMainGenerator

If I remove the property, I get this error:

test/Properties.hs:32:20:
    Expecting one more argument to ‘TestValues’
    The first argument of ‘Arbitrary’ should have kind ‘*’,
      but ‘TestValues’ has kind ‘* -> *’
    In the instance declaration for ‘Arbitrary TestValues’

So, $defaultMainGenerator suppresses the error messages that are really causing the problem. I've figured out that you can resolve this problem by placing $defaultMainGenerator at the bottom of the file.

Would it be possible to figure out a way to prevent $defaultMainGenerator from causing this problem, or should the documentation be updated to recommend declaring main at the bottom of the file? (I could supply a PR for the second, the first is rather beyond my ability RN.)

test-framework-th does not respect comments

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
 -}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.