| 1 | #include "tester.hpp" |
| 2 | |
| 3 | #include <cstdlib> |
| 4 | #include <iostream> |
| 5 | #include <stdexcept> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | // This should be passed either be char* or std::string for this to work |
| 10 | static void test_internal(const std::string& data) { |
| 11 | try { |
| 12 | // Check that it actually got anything |
| 13 | if (data.empty()) { |
| 14 | throw std::logic_error("Got empty data"); |
| 15 | } |
| 16 | } |
| 17 | catch (const std::exception& e) { |
| 18 | // Take any standard exception & output its message |
| 19 | std::cerr << e.what() << std::endl; |
| 20 | std::exit(EXIT_FAILURE); |
| 21 | } |
| 22 | catch (...) { |
| 23 | // If any non-std exception is thrown, also fail |
| 24 | std::cerr << "Unknown exception!" << std::endl; |
| 25 | std::exit(EXIT_FAILURE); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // std::string is expected input |
| 30 | void run_test(const std::string& input) { |
| 31 | test_internal(input); |
| 32 | } |
| 33 | |
| 34 | // A special overload for the two funcs that take a vector |
| 35 | void run_test(const std::vector<std::string>& vec) { |
| 36 | // Check each value for validity |
| 37 | for (const std::string& elem : vec) { |
| 38 | test_internal(elem); |
| 39 | } |
| 40 | } |