1 module bed; 2 3 public import reporters; 4 public import runnable; 5 public import spec; 6 public import suite; 7 8 static Suite[] suites; 9 static Suite currentSuite; 10 11 void describe(string title, Block block) 12 { 13 if(currentSuite is null) 14 { 15 currentSuite = new Suite(title); 16 } 17 else 18 { 19 auto suite = new Suite(title, currentSuite); 20 currentSuite.suites ~= suite; 21 currentSuite = suite; 22 } 23 24 block(); 25 26 if(!currentSuite.isRoot) 27 { 28 currentSuite = cast(Suite) currentSuite.parent; 29 } 30 else 31 { 32 suites ~= currentSuite; 33 currentSuite = null; 34 } 35 } 36 37 void it(string title, Block block) 38 { 39 auto spec = new Spec(title, currentSuite, block); 40 currentSuite.specs ~= spec; 41 spec.connect(¤tSuite.propagateFailure); 42 } 43 44 void before(Block block) 45 { currentSuite.befores ~= block; } 46 47 void beforeEach(Block block) 48 { currentSuite.beforeEachs ~= block; } 49 50 void after(Block block) 51 { currentSuite.afters = block ~ currentSuite.afters; } 52 53 void afterEach(Block block) 54 { currentSuite.afterEachs = block ~ currentSuite.afterEachs; } 55 56 static ~this() 57 { 58 import std.c.process : exit; 59 import colorize : fg, color; 60 auto rootSuite = new Suite("\n -- bed --\n".color(fg.yellow)); 61 62 foreach(suite; suites) 63 { 64 suite.parent = rootSuite; 65 rootSuite.suites ~= suite; 66 } 67 68 auto rep = new SpecReporter(rootSuite); 69 rootSuite.run(); 70 if(rootSuite.failed) exit(1); 71 }