unittests are really part of the build, not a special run

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 3 02:39:43 PDT 2015


On 2015-04-02 21:11, Ary Borenszweig wrote:

> We can. But then it becomes harder to understand what's going on. In
> RSpec I don't quite understand what's going on really, and I like a bit
> of magic but not too much of it.

It's quite straightforward to implement, in Ruby as least. Something 
like this:

module DSL
   def describe(name, &block)
     context = Class.new(self)
     context.send(:extend, DSL)
     context.instance_eval(&block)
   end

   def it(name, &block)
     send(:define_method, name, &block)
   end
end

class Foo
   extend DSL

   describe 'foo' do
     it 'bar' do
       p 'asd'
     end
   end
end

You need to register the tests somehow also but be able to run them, but 
this is the basic idea. I cheated here and used a class to start with to 
simplify the example.

> In fact with macros it's not that simple because you need to remember
> the context where you are defining stuff, so that might need adding that
> capabilities to macros, which will complicate the language.

Yeah, I don't really now how macros work in Cyrstal.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list