Basic test harness
| 851 | |
| 852 | // Basic test harness |
| 853 | int main(int argc, char** argv) |
| 854 | { |
| 855 | bool disablePrompt = false; |
| 856 | std::vector<std::string> selectedTests; |
| 857 | |
| 858 | // Disable buffering (so that when run in, e.g., Sublime Text, the output appears as it is written) |
| 859 | std::setvbuf(stdout, nullptr, _IONBF, 0); |
| 860 | |
| 861 | // Isolate the executable name |
| 862 | std::string progName = argv[0]; |
| 863 | auto slash = progName.find_last_of("/\\"); |
| 864 | if (slash != std::string::npos) { |
| 865 | progName = progName.substr(slash + 1); |
| 866 | } |
| 867 | |
| 868 | ReaderWriterQueueTests tests; |
| 869 | |
| 870 | // Parse command line options |
| 871 | if (argc == 1) { |
| 872 | std::printf("Running all unit tests for moodycamel::ReaderWriterQueue.\n(Run %s --help for other options.)\n\n", progName.c_str()); |
| 873 | } |
| 874 | else { |
| 875 | bool printHelp = false; |
| 876 | bool printedTests = false; |
| 877 | bool error = false; |
| 878 | for (int i = 1; i < argc; ++i) { |
| 879 | if (std::strcmp(argv[i], "--help") == 0) { |
| 880 | printHelp = true; |
| 881 | } |
| 882 | else if (std::strcmp(argv[i], "--disable-prompt") == 0) { |
| 883 | disablePrompt = true; |
| 884 | } |
| 885 | else if (std::strcmp(argv[i], "--run") == 0) { |
| 886 | if (i + 1 == argc || argv[i + 1][0] == '-') { |
| 887 | std::printf("Expected test name argument for --run option.\n"); |
| 888 | if (!printedTests) { |
| 889 | printTests(tests); |
| 890 | printedTests = true; |
| 891 | } |
| 892 | error = true; |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | if (!tests.validateTestName(argv[++i])) { |
| 897 | std::printf("Unrecognized test '%s'.\n", argv[i]); |
| 898 | if (!printedTests) { |
| 899 | printTests(tests); |
| 900 | printedTests = true; |
| 901 | } |
| 902 | error = true; |
| 903 | continue; |
| 904 | } |
| 905 | |
| 906 | selectedTests.push_back(argv[i]); |
| 907 | } |
| 908 | else { |
| 909 | std::printf("Unrecognized option '%s'.\n", argv[i]); |
| 910 | error = true; |
nothing calls this directly
no test coverage detected