Skip to content

Commit

Permalink
Add an alternate main function, mainWithOpts, that uses custom TestOp…
Browse files Browse the repository at this point in the history
…tions.

Add some documentation for the compile-time options.
Fix a typo.
  • Loading branch information
orlitzky committed Dec 6, 2012
1 parent ea0c951 commit 2c3fe32
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions example/Test/Framework/Example.lhs
@@ -1,12 +1,34 @@
== RUNNING == == RUNNING ==


ghc -package test-framework -package test-framework-quickcheck2 -package test-framework-hunit -threaded Example.lhs -o Example Compile the test suite:
./Example --maximum-generated-tests=5000 +RTS -N2


ghc -package test-framework -package test-framework-quickcheck2 \
-package test-framework-hunit -threaded Example.lhs -o Example

To run the test suite with the default options, simply execute the
resulting binary:

./Example

Test options can also be supplied on the command-line:

./Example --maximum-generated-tests=5000 +RTS -N2

To see the available options, run:

./Example --help

These options can also be specified in the code. An alternate main
function, mainWithOpts, with compile-time options is provided:

ghc -package test-framework -package test-framework-quickcheck2 \
-package test-framework-hunit -main-is mainWithOpts \
-threaded Example.lhs -o Example
./Example


== ATTRIBUTION == == ATTRIBUTION ==


Tthe example properties come from the parallel QuickCheck driver (pqc), The example properties come from the parallel QuickCheck driver (pqc),
see http://code.haskell.org/~dons/code/pqc/. The BSD license is repeated see http://code.haskell.org/~dons/code/pqc/. The BSD license is repeated
below, per the licensing conditions of pqc. below, per the licensing conditions of pqc.


Expand Down Expand Up @@ -46,7 +68,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


\begin{code} \begin{code}
import Test.Framework (defaultMain, testGroup) module Main
where
import Data.Monoid (mempty)
import Test.Framework (defaultMain, defaultMainWithOpts, testGroup)
import Test.Framework.Options (TestOptions, TestOptions'(..))
import Test.Framework.Runners.Options (RunnerOptions, RunnerOptions'(..))
import Test.Framework.Providers.HUnit import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.Framework.Providers.QuickCheck2 (testProperty)
Expand All @@ -55,9 +83,28 @@ import Test.HUnit
import Data.List import Data.List
main = defaultMain tests main = defaultMain tests
mainWithOpts = do
-- Test options can also be specified in the code. The TestOptions
-- type is an instance of the Monoid type class, so the easiest way
-- to get an empty set of options is with `mempty`.
let empty_test_opts = mempty :: TestOptions
-- We update the empty TestOptions with our desired values.
let my_test_opts = empty_test_opts {
topt_maximum_generated_tests = Just 500
}
-- Now we create an empty RunnerOptions in the same way, and add
-- our TestOptions to it.
let empty_runner_opts = mempty :: RunnerOptions
let my_runner_opts = empty_runner_opts {
ropt_test_options = Just my_test_opts
}
defaultMainWithOpts tests my_runner_opts
tests = [ tests = [
testGroup "Sorting Group 1" [ testGroup "Sorting Group 1" [
testProperty "sort1" prop_sort1, testProperty "sort1" prop_sort1,
Expand Down

0 comments on commit 2c3fe32

Please sign in to comment.