BDDTest.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "BDDTest.h"
  2. #include "trace.h"
  3. #include <sstream>
  4. #include <iostream>
  5. #include <string>
  6. #include <list>
  7. int testCount = 0;
  8. int testPasses = 0;
  9. const char* testDescription;
  10. std::list<std::string> failureList;
  11. void bddtest_suite(const char* name) {
  12. LOG(name << "\n");
  13. }
  14. int bddtest_test(const char* file, int line, const char* assertion, int result) {
  15. if (!result) {
  16. LOG("✗\n");
  17. std::ostringstream os;
  18. os << " ! "<<testDescription<<"\n " <<file << ":" <<line<<" : "<<assertion<<" ["<<result<<"]";
  19. failureList.push_back(os.str());
  20. }
  21. return result;
  22. }
  23. void bddtest_start(const char* description) {
  24. LOG(" - "<<description<<" ");
  25. testDescription = description;
  26. testCount ++;
  27. }
  28. void bddtest_end() {
  29. LOG("✓\n");
  30. testPasses ++;
  31. }
  32. int bddtest_summary() {
  33. for (std::list<std::string>::iterator it = failureList.begin(); it != failureList.end(); it++) {
  34. LOG("\n");
  35. LOG(*it);
  36. LOG("\n");
  37. }
  38. LOG(std::dec << testPasses << "/" << testCount << " tests passed\n\n");
  39. if (testPasses == testCount) {
  40. return 0;
  41. }
  42. return 1;
  43. }