| 795 | } |
| 796 | |
| 797 | void run(int argc, const char* argv[]) |
| 798 | { |
| 799 | auto args = parse(argc, argv); |
| 800 | if(args.count("--help") > 0) |
| 801 | { |
| 802 | show_help(args.at("__exe__").front()); |
| 803 | return; |
| 804 | } |
| 805 | if(args.count("--list") > 0) |
| 806 | { |
| 807 | for(auto&& tc : get_test_cases()) |
| 808 | out() << tc.first << std::endl; |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | if(args.count("--quiet") > 0) |
| 813 | quiet = true; |
| 814 | |
| 815 | auto cases = args[""]; |
| 816 | if(cases.empty()) |
| 817 | { |
| 818 | run_test_cases(get_test_cases(), args); |
| 819 | } |
| 820 | else |
| 821 | { |
| 822 | std::unordered_map<std::string, test_case> m(get_test_cases().begin(), |
| 823 | get_test_cases().end()); |
| 824 | |
| 825 | for(auto&& iname : cases) |
| 826 | { |
| 827 | std::vector<std::pair<std::string, test_case>> found_cases; |
| 828 | for(auto&& pattern : get_case_names(iname)) |
| 829 | { |
| 830 | auto f = m.find(pattern); |
| 831 | if(f == m.end()) |
| 832 | { |
| 833 | found_cases = glob_tests(pattern); |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | found_cases.push_back(*f); |
| 838 | } |
| 839 | } |
| 840 | if(found_cases.empty()) |
| 841 | { |
| 842 | out() << color::fg_red << "[ ERROR ] Test case '" << iname << "' not found." |
| 843 | << color::reset << std::endl; |
| 844 | failed.push_back(iname); |
| 845 | } |
| 846 | run_test_cases(found_cases, args); |
| 847 | } |
| 848 | } |
| 849 | out() << color::fg_green << "[==========] " << color::fg_yellow << ran << " tests ran" |
| 850 | << color::reset << std::endl; |
| 851 | if(not failed.empty()) |
| 852 | { |
| 853 | out() << color::fg_red << "[ FAILED ] " << color::fg_yellow << failed.size() |
| 854 | << " tests failed" << color::reset << std::endl; |