11"""Unit test for trepan.options"""
22
3- from trepan .options import process_options
3+ from test .unit .cmdhelper import setup_unit_test_debugger
4+
5+ from trepan .options import postprocess_options , process_options
46
57
68def test_options ():
9+ """
10+ Test trepan.options.process_options() and trepan.options.postprocess.
11+ """
12+
13+ # Setup.
714 option_key_set = {
815 "annotate" ,
916 "basename" ,
@@ -30,19 +37,30 @@ def test_options():
3037 "style" ,
3138 "target" ,
3239 }
40+ dbg , _ = setup_unit_test_debugger ()
3341 dbg_opts_set = {"proc_opts" , "from_ipython" }
3442
43+ # Test with no options. See that we have the some expected
44+ # keys getting set.
3545 opts , dbg_opts , sys_argv = process_options ("1.0" , [__file__ ])
3646 diff_set = option_key_set - set (vars (opts ).keys ())
3747 assert diff_set == set (), "expecting at least these options keys set"
3848 assert (
3949 dbg_opts_set - set (dbg_opts .keys ())
4050 ) == set (), "expecting at least these processor keys set"
4151
52+ # Try with more than one option, a boolean option and a string option.
4253 arg_str = f"{ __file__ } --fntrace --cd=/tmp"
4354 opts , dbg_opts , sys_argv = process_options ("1.1" , arg_str .split ())
4455 assert opts .cd == "/tmp"
56+ postprocess_options (dbg , opts )
57+ assert dbg .settings ["printset" ] == frozenset (
58+ ["c_call" , "c_return" , "call" , "return" ]
59+ )
4560
46- arg_str = f"{ __file__ } --style=emacs"
47- opts , dbg_opts , sys_argv = process_options ("1.2" , arg_str .split ())
48- assert opts .style == "emacs"
61+ # Try with an invalid style option and see that it is
62+ # rejected in postprocess option
63+ arg_str = f"{ __file__ } --style=fafdsaXYZZY"
64+ opts , dbg_opts , sys_argv = process_options ("1.3" , arg_str .split ())
65+ postprocess_options (dbg , opts )
66+ assert dbg .settings ["style" ] is None
0 commit comments