Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the test suite is for QuickCheck, i advise you to use the new <code>All</code> module instead: <a href="http://hackage.haskell.org/packages/archive/QuickCheck/2.4.1.1/doc/html/Test-QuickCheck-All.html" rel="nofollow">http://hackage.haskell.org/packages/archive/QuickCheck/2.4.1.1/doc/html/Test-QuickCheck-All.html</a></p> <p>It does the same thing except it fetches the names of properties by accessing the file system and parsing the file that the splice resides in (if you are using some other test framework, you can still use the same approach).</p> <p>If you really want to quote the entire file, you could use a quasi-quoter instead (which does not require indentation). You can easily build your quoter on haskell-src-meta, but i advice against this approach because it will not support some Haskell features and it will probably give poor error messages.</p> <hr> <p>Aggregating test suits is a difficult problem, one could probably extend the name gathering routine to somehow follow imports but it's a lot of work. Here's a workaround:</p> <p>You can use this modified version of <code>forAllProperties</code>:</p> <pre><code>import Test.QuickCheck import Test.QuickCheck.All import Language.Haskell.TH import Data.Char import Data.List import Control.Monad allProperties :: Q Exp -- :: [(String,Property)] allProperties = do Loc { loc_filename = filename } &lt;- location when (filename == "&lt;interactive&gt;") $ error "don't run this interactively" ls &lt;- runIO (fmap lines (readFile filename)) let prefixes = map (takeWhile (\c -&gt; isAlphaNum c || c == '_') . dropWhile (\c -&gt; isSpace c || c == '&gt;')) ls idents = nubBy (\x y -&gt; snd x == snd y) (filter (("prop_" `isPrefixOf`) . snd) (zip [1..] prefixes)) quickCheckOne :: (Int, String) -&gt; Q [Exp] quickCheckOne (l, x) = do exists &lt;- return False `recover` (reify (mkName x) &gt;&gt; return True) if exists then sequence [ [| ($(stringE $ x ++ " on " ++ filename ++ ":" ++ show l), property $(mono (mkName x))) |] ] else return [] [|$(fmap (ListE . concat) (mapM quickCheckOne idents)) |] </code></pre> <p>You also need the function <code>runQuickCheckAll</code> which is not exported from All:</p> <pre><code>runQuickCheckAll :: [(String, Property)] -&gt; (Property -&gt; IO Result) -&gt; IO Bool runQuickCheckAll ps qc = fmap and . forM ps $ \(xs, p) -&gt; do putStrLn $ "=== " ++ xs ++ " ===" r &lt;- qc p return $ case r of Success { } -&gt; True Failure { } -&gt; False NoExpectedFailure { } -&gt; False </code></pre> <p>In each test module you now define </p> <pre><code>propsN = $allProperties </code></pre> <p>where <code>N</code> is some number or other unique identifier (or you could use the same name and use qualified names in the step below).</p> <p>In your main test suite you define</p> <pre><code>props :: [(String,Property)] props = concat [props1, props2 ... propsN] </code></pre> <p>If you really want to avoid adding a list member for each module, you could make a TH script that generates this list.</p> <p>To run all your tests you simply say</p> <pre><code>runTests = runQuickCheckAll quickCheckResult props </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload