Options.icl 1.26 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1 2
implementation module Testing.Options

3
import StdList
Camil Staps's avatar
Camil Staps committed
4 5 6

import Data.Error
from Data.Func import $
Camil Staps's avatar
Camil Staps committed
7
import Data.GenDefault
Camil Staps's avatar
Camil Staps committed
8
import Data.Maybe
9
import System.Options
10
import Text
Camil Staps's avatar
Camil Staps committed
11

12 13 14
derive gDefault TestOptions, TestRun

testOptionDescription :: Option TestOptions
15
testOptionDescription = WithHelp True $ Options
16 17 18 19 20 21 22
	[ Shorthand "-l" "--list" $ Flag
		"--list"
		(\opts -> Ok {opts & list=True})
		"List all available tests"
	, Shorthand "-O" "--option" $ Option
		"--option"
		(\opt opts -> case opts.runs of
Camil Staps's avatar
Camil Staps committed
23 24 25
			[] -> Error ["--option used before --run"]
			rs -> let r = last rs in
				Ok {opts & runs=init rs ++ [{r & options=r.options ++ [opt]}]})
26 27
		"OPT"
		"Add OPT to the options of the previously added test"
28 29 30 31 32 33 34 35
	, Option
		"--options"
		(\optstring opts -> case opts.runs of
			[] -> Error ["--options used before --run"]
			rs -> let r = last rs in
				Ok {opts & runs=init rs ++ [{r & options=r.options ++ split ";" optstring}]})
		"'OPT;OPT;OPT'"
		"Add the semicolon-separated OPTs to the options of the previously added test"
36 37 38 39 40 41 42 43 44 45
	, Shorthand "-r" "--run"  $ Option
		"--run"
		(\r opts -> Ok {opts & runs=opts.runs ++ [{name=r, options=[]}]})
		"NAME"
		"Run test NAME"
	, Shorthand "-s" "--skip" $ Option
		"--skip"
		(\r opts -> Ok {opts & skip=[r:opts.skip]})
		"NAME"
		"Skip test NAME"
Camil Staps's avatar
Camil Staps committed
46
	]