the main function that does all the filtering and test running
| 6792 | |
| 6793 | // the main function that does all the filtering and test running |
| 6794 | int Context::run() { |
| 6795 | using namespace detail; |
| 6796 | |
| 6797 | // save the old context state in case such was setup - for using asserts out of a testing context |
| 6798 | auto old_cs = g_cs; |
| 6799 | // this is the current contest |
| 6800 | g_cs = p; |
| 6801 | is_running_in_test = true; |
| 6802 | |
| 6803 | g_no_colors = p->no_colors; |
| 6804 | p->resetRunData(); |
| 6805 | |
| 6806 | std::fstream fstr; |
| 6807 | if(p->cout == nullptr) { |
| 6808 | if(p->quiet) { |
| 6809 | p->cout = &discardOut; |
| 6810 | } else if(p->out.size()) { |
| 6811 | // to a file if specified |
| 6812 | fstr.open(p->out.c_str(), std::fstream::out); |
| 6813 | p->cout = &fstr; |
| 6814 | } else { |
| 6815 | #ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM |
| 6816 | // stdout by default |
| 6817 | p->cout = &std::cout; |
| 6818 | #else // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM |
| 6819 | return EXIT_FAILURE; |
| 6820 | #endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM |
| 6821 | } |
| 6822 | } |
| 6823 | |
| 6824 | FatalConditionHandler::allocateAltStackMem(); |
| 6825 | |
| 6826 | auto cleanup_and_return = [&]() { |
| 6827 | FatalConditionHandler::freeAltStackMem(); |
| 6828 | |
| 6829 | if(fstr.is_open()) |
| 6830 | fstr.close(); |
| 6831 | |
| 6832 | // restore context |
| 6833 | g_cs = old_cs; |
| 6834 | is_running_in_test = false; |
| 6835 | |
| 6836 | // we have to free the reporters which were allocated when the run started |
| 6837 | for(auto& curr : p->reporters_currently_used) |
| 6838 | delete curr; |
| 6839 | p->reporters_currently_used.clear(); |
| 6840 | |
| 6841 | if(p->numTestCasesFailed && !p->no_exitcode) |
| 6842 | return EXIT_FAILURE; |
| 6843 | return EXIT_SUCCESS; |
| 6844 | }; |
| 6845 | |
| 6846 | // setup default reporter if none is given through the command line |
| 6847 | if(p->filters[8].empty()) |
| 6848 | p->filters[8].push_back("console"); |
| 6849 | |
| 6850 | // check to see if any of the registered reporters has been selected |
| 6851 | for(auto& curr : getReporters()) { |
no test coverage detected