/runtests.d
D | 111 lines | 85 code | 23 blank | 3 comment | 6 complexity | a6ada1e70af443db9ed0191935c02322 MD5 | raw file
1import djehuty; 2 3import io.console; 4 5import spec.specification; 6import spec.itemspecification; 7import spec.packagespecification; 8import spec.modulespecification; 9import spec.test; 10 11import parsing.options; 12 13char[] usage = `runtests rev1 14 15USAGE: runtests [(+|-)className]* 16EXAMPLE: runtests +String +Random 17 runtests -Random`; 18 19class Opts : OptionParser { 20 21 mixin Options!( 22 "-help", "View help and usage" 23 ); 24 25 void onHelp() { 26 showUsage(); 27 Djehuty.application.exit(0); 28 } 29 30 void onError(string token) { 31 Console.putln("YAY"); 32 } 33 34 string[] modules() { 35 return _modules; 36 } 37 38private: 39 string[] _modules; 40} 41 42// Do not change the class name, it is used in a test for djehuty proper! 43class DjehutyTester : Application { 44 static this() { new DjehutyTester(); } 45 46 void onApplicationStart() { 47 options = new Opts(); 48 49 if (options.modules is null) { 50 Console.putln(); 51 52 // Go through every package 53 foreach(pack; Specification) { 54 _testPackage(pack); 55 } 56 } 57 } 58 59private: 60 61 void _testPackage(PackageSpecification ps, string prior = "") { 62 foreach(PackageSpecification pack; ps) { 63 _testPackage(pack, prior ~ ps.name ~ "."); 64 } 65 66 foreach(ModuleSpecification mod; ps) { 67 _testModule(mod, prior ~ ps.name); 68 } 69 } 70 71 void _testModule(ModuleSpecification ms, string packName = "") { 72 Console.put(packName ~ "." ~ ms.name, " : "); 73 74 // Keep track of success over the module 75 int numFailures; 76 int numSuccesses; 77 foreach(item; ms) { 78 foreach(feature; item) { 79 auto tester = new Test(item, feature); 80 tester.run(); 81 if (tester.failures > 0) { 82 Console.forecolor = Color.Red; 83 if (numFailures == 0) { 84 Console.putln("FAILED "); 85 } 86 Console.putln(" ".times((packName ~ "." ~ ms.name).length), " : ", item.name, " ", feature); 87 } 88 numFailures += tester.failures; 89 numSuccesses += tester.successes; 90 } 91 } 92 if (numFailures > 0) { 93 Console.forecolor = Color.Gray; 94 Console.put(packName ~ "." ~ ms.name, " : "); 95 Console.forecolor = Color.Red; 96 Console.put("FAILED "); 97 98 Console.forecolor = Color.Gray; 99 Console.putln(numSuccesses, " / ", numSuccesses+numFailures); 100 } 101 else { 102 Console.forecolor = Color.Green; 103 Console.put("PASSED "); 104 105 Console.forecolor = Color.Gray; 106 Console.putln("all ", numSuccesses, " tests"); 107 } 108 } 109 110 Opts options; 111}