debug testcase keyword

  • Thread starter Simon Strandgaard
  • Start date
S

Simon Strandgaard

I am working on a regexp engine, where I follow the test first paradigm.
I want my regexp-engine to be compatible with Ruby's, therefore I share
testcases between the 'test_my_regexp.rb' file and the
'test_rubys_regexp.rb' file.

A testcase looks like this:

def test_repeat8
# 'x' REP ___________________________________________ 'x' END
# GRP GRP REP ___________ /GR 'x' REP ___ /GR nil
# GRP ANY /GR nil ANY nil
assert_regex(["x1x2x3x", "1x2x3", "1x2", "2"], "x(((.)*)x.*)*x", "0x1x2x3x4")
end

Sometimes I need to enable verbose debugging for a paticular testcase.
This is what I want to simplify. The way I do it now, are to add
a 'debug=true' flag within the testcase.

def test_repeat8
# 'x' REP ___________________________________________ 'x' END
# GRP GRP REP ___________ /GR 'x' REP ___ /GR nil
# GRP ANY /GR nil ANY nil
assert_regex(["x1x2x3x", "1x2x3", "1x2", "2"], "x(((.)*)x.*)*x", "0x1x2x3x4", true)
end

But I don't like this current approach (files appears to be modified in
CVS). Instead I _dream_ of a 'debug' keyword, which would set a debug-flag
variable for the specified methods. I imagine something like:

class TestScanner < Test::Unit::TestCase
include Repeat
debug test_repeat8, test_repeat9
end


Is it clear what im saying?

Is this possible ?

Any alternatives ?


BTW: has anyone tried my regexp engine ;-) ?
http://raa.ruby-lang.org/list.rhtml?name=regexp
 
S

Simon Strandgaard

On Fri, 07 Nov 2003 13:47:16 +0100, Simon Strandgaard wrote:
[snip]
But I don't like this current approach (files appears to be modified in
CVS). Instead I _dream_ of a 'debug' keyword, which would set a debug-flag
variable for the specified methods. I imagine something like:

class TestScanner < Test::Unit::TestCase
include Repeat
debug test_repeat8, test_repeat9
end

I solved it myself.. Thanks comp.lang.ruby ;-)

--
Simon Strandgaard


server> ruby debug_keyword.rb
before
42
after
server> exp
expand expr
server> expand -t2 debug_keyword.rb
class Test
def test
puts "42"
end
def self.debug(*methods)
methods.each{|method|
name = method.id2name
org = "_debug_"+name
module_eval <<MSG
alias #{org} #{name}
def #{name}(*a,&b)
puts("before")
#{org}(*a,&b)
puts("after")
end
private :#{org}
MSG
}
end
debug :test
end

Test.new.test
server>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top