在 tasty-quickcheck 中使用 quickCheckAll 函数

Using the quickCheckAll function in tasty-quickcheck

精简版: 可以在tasty-quickcheck中使用quickCheckAll功能吗?

长版:

quickCheckAll 函数测试当前模块中以 prop_ 开头的 所有 属性,如下例所示:

{-# LANGUAGE TemplateHaskell #-}

module Main where

import Test.QuickCheck ( quickCheckAll )

prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x

prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x

-- Template Haskell hack to make the following $quickCheckAll work
-- under GHC >= 7.8.
return []

-- All properties as collected by 'quickCheckAll'.
runTests :: IO Bool
runTests = $quickCheckAll

main :: IO ()
main = runTests >> return ()

另一方面,我可以通过 tasty-quickcheck 包在 Tasty 测试框架中使用 QuickCheck,如下例所示:

module Main where

import Test.Tasty ( defaultMain, testGroup, TestTree )

import qualified Test.Tasty.QuickCheck as QC

prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x

prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x

tests :: TestTree
tests = testGroup "Tested by QuickCheck"
  [ QC.testProperty "prop_1" prop_1
  , QC.testProperty "prop_2" prop_2
  ]

main :: IO ()
main = defaultMain tests

可以在上面的例子中使用quickCheckAll函数来避免在使用QuickCheck和Tasty时显式列出所有属性吗?

版本:以上示例使用 GHC 8.2.2、QuickCheck 2.10.1 和 tasty-quickcheck 0.9.1 进行测试。

quickCheckAll 这似乎不可能,但测试框架可以重用底层逻辑。 Here's a new PR to get all properties in a list.