From: Simon Strandgaard Date: 2004-02-25T22:54:52+09:00 Subject: Re: proposal: debug keyword On Wed, 25 Feb 2004 14:26:36 +0100, Robert Klemme wrote: > "Simon Strandgaard" schrieb im Newsbeitrag >> Its syntax is >> >> debug :method [, :method]* >> >> What it does is to enable the global flag $debug. > > More precisely it switches all output on or off in a method. And that's > what I don't like about it: in your example class A behavior of "puts", > "print" etc. changes depending on the $debug flag. That's IMHO not > compliant with POLS. Agree it isn't POLS, but debugging is sometimes tuff. I never remove print statements.. because I one day might need that information. Then a debug keyword + Debuggable module is practical. I have attached a debug output from a testcase (my regexp project). I have used logfiles in the past.. but in conjunction with unittesting they seems to be not needed. > I'd prefer to have specialized methods for debug printing. > Please enlighten me. How do you debug ? It would be nice to identify a good model for advanced debugging with Test::Unit. -- Simon Strandgaard Loaded suite TestScanner Started test_verbose_alt_rep1(TestScanner): before #test_verbose_alt_rep1 regexp="(foob|fo|o)*bar" +-Sequence +-Repeat greedy{0,-1} | +-Group register=1 | +-Alternation | +-Sequence | | +-Literal "f" | | +-Literal "o" | | +-Literal "o" | | +-Literal "b" | +-Sequence | | +-Literal "f" | | +-Literal "o" | +-Literal "o" +-Literal "b" +-Literal "a" +-Literal "r" input="xfoobarx" ---------------------------------------- execute at position 0 repeat 0 visitor#set_state from active into inactive match "b" at position 0 path end = expected "b" but got "x" check_integrity history.size=1 index-stack=[0] integrity "bar" (line 0) next_path zero. found=false lazy=false state=active index=0 has_match=false clear history replace zero with one visitor#set_state from inactive into active visitor#set_memento group_open register=1 alternation 0 match "f" at position 0 path end = expected "f" but got "x" check_integrity history.size=2 index-stack=[1, 0] integrity "foob bar" (line 1) next_path alternation. index=0->1 visitor#set_memento match "f" at position 0 path end = expected "f" but got "x" check_integrity history.size=2 index-stack=[1, 1] integrity "fo bar" (line 2) next_path alternation. index=1->2 visitor#set_memento match "o" at position 0 path end = expected "o" but got "x" check_integrity history.size=2 index-stack=[1, 2] integrity "o bar" (line 3) next_path alternation. index=2->3, exhausted skip, path end = exhausted next_path one. found=false lazy=false state=active index=0 has_match=false clear history skip, path end = is done execute at position 1 repeat 0 visitor#set_state from active into inactive match "b" at position 1 path end = expected "b" but got "f" check_integrity history.size=1 index-stack=[0] integrity "bar" (line 4) next_path zero. found=false lazy=false state=active index=0 has_match=false clear history replace zero with one visitor#set_state from inactive into active visitor#set_memento group_open register=1 alternation 0 match "f" at position 1 match "o" at position 2 match "o" at position 3 match "b" at position 4 group_close register=1 visitor#set_state from active into inactive one-end match "b" at position 5 path end = expected "b" but got "a" check_integrity history.size=3 index-stack=[1, 0] integrity "foob bar" (line 5) next_path zero. found=false lazy=false state=active index=1 has_match=false clear history replace zero with one visitor#set_state from inactive into active visitor#set_memento group_open register=1 alternation 0 match "f" at position 5 path end = expected "f" but got "a" check_integrity history.size=4 index-stack=[2, 0, 0] integrity "foob foob bar" (line 6) next_path alternation. index=0->1 visitor#set_memento match "f" at position 5 path end = expected "f" but got "a" check_integrity history.size=4 index-stack=[2, 0, 1] integrity "foob fo bar" (line 7) next_path alternation. index=1->2 visitor#set_memento match "o" at position 5 path end = expected "o" but got "a" check_integrity history.size=4 index-stack=[2, 0, 2] integrity "foob o bar" (line 8) next_path alternation. index=2->3, exhausted skip, path end = exhausted next_path one. found=false lazy=false state=active index=1 has_match=false clear history skip, path end = is done next_path alternation. index=0->1 visitor#set_memento match "f" at position 1 match "o" at position 2 group_close register=1 visitor#set_state from active into inactive one-end match "b" at position 3 path end = expected "b" but got "o" check_integrity history.size=3 index-stack=[1, 1] integrity "fo bar" (line 9) next_path zero. found=false lazy=false state=active index=1 has_match=false clear history replace zero with one visitor#set_state from inactive into active visitor#set_memento group_open register=1 alternation 0 match "f" at position 3 path end = expected "f" but got "o" check_integrity history.size=4 index-stack=[2, 1, 0] integrity "fo foob bar" (line 10) next_path alternation. index=0->1 visitor#set_memento match "f" at position 3 path end = expected "f" but got "o" check_integrity history.size=4 index-stack=[2, 1, 1] integrity "fo fo bar" (line 11) next_path alternation. index=1->2 visitor#set_memento match "o" at position 3 group_close register=1 visitor#set_state from active into inactive one-end match "b" at position 4 match "a" at position 5 match "r" at position 6 last path end = reached last node check_integrity history.size=5 index-stack=[2, 1, 2] integrity "fo o bar" (line 12) next_path zero. found=true lazy=false state=active index=2 has_match=false remember zero and clear replace zero with one visitor#set_state from inactive into active visitor#set_memento group_open register=1 alternation 0 match "f" at position 4 path end = expected "f" but got "b" check_integrity history.size=6 index-stack=[3, 1, 2, 0] integrity "fo o foob bar" (line 13) next_path alternation. index=0->1 visitor#set_memento match "f" at position 4 path end = expected "f" but got "b" check_integrity history.size=6 index-stack=[3, 1, 2, 1] integrity "fo o fo bar" (line 14) next_path alternation. index=1->2 visitor#set_memento match "o" at position 4 path end = expected "o" but got "b" check_integrity history.size=6 index-stack=[3, 1, 2, 2] integrity "fo o o bar" (line 15) next_path alternation. index=2->3, exhausted skip, path end = exhausted next_path one. found=false lazy=false state=active index=2 has_match=true clear history install match visitor#set_memento skip, path end = is done next_path alternation. index=2->3, found skip, path end = found next_path one. found=true lazy=false state=active index=1 has_match=true remember one and clear install match visitor#set_memento skip, path end = is done next_path alternation. index=1->2, found skip, path end = found next_path one. found=true lazy=false state=active index=0 has_match=true remember one and clear install match visitor#set_memento ----- BEGIN before activate ----- content of history stack 0: ONE_0 quantifier_id=0 1: ALT_1 2: ONE_1 quantifier_id=0 3: ALT_2 4: ZERO_2 quantifier_id=0 quantifier information 0: active found=no ----- END before activate ----- activate_next found zero/one activate_inactive ----- BEGIN after activate ----- content of history stack 0: ONE_0 quantifier_id=0 1: ALT_1 2: ONE_1 quantifier_id=0 3: ALT_2 4: ZERO_2 quantifier_id=0 quantifier information 0: done found=no ----- END after activate ----- skip, path end = is done next_path zero. found=true lazy=false state=done index=2 has_match=false skip, path end = done next_path alternation. index=2->3, found skip, path end = found next_path one. found=true lazy=false state=done index=1 has_match=false skip, path end = done next_path alternation. index=1->2, found skip, path end = found next_path one. found=true lazy=false state=done index=0 has_match=false skip, path end = done ---------------------------------------- result=["foobar", "o"] after #test_verbose_alt_rep1 .. Finished in 0.026799 seconds. 1 tests, 1 assertions, 0 failures, 0 errors