/runtests.d

http://github.com/wilkie/djehuty · D · 111 lines · 85 code · 23 blank · 3 comment · 6 complexity · a6ada1e70af443db9ed0191935c02322 MD5 · raw file

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