#include "errors.hh" #include "location.hh" #include #include #include namespace { void generate(src::Errors& errors) { errors.err(src::Location(1, 10), "Fatal error"); errors.warn(src::Location(2, 0), "This is a warning"); errors.dbg(src::Location(10, 1000), "Debugging"); errors.err(src::Location(2, 100), "Another errors error"); } } // namespace TEST(errors, ignore) { auto errors = src::ignore_errors(); generate(*errors); EXPECT_EQ(0, errors->errors()); EXPECT_EQ(0, errors->warnings()); } TEST(errors, stream) { std::stringstream ss; std::shared_ptr output = src::errors_output_ios(ss); auto errors = src::file_errors("filename", output); generate(*errors); EXPECT_EQ(2, errors->errors()); EXPECT_EQ(1, errors->warnings()); EXPECT_EQ(R"(filename:1:10: Error: Fatal error filename:2:0: Warning: This is a warning filename:10:1000: Debug: Debugging filename:2:100: Error: Another errors error )", ss.str()); } TEST(location, out) { std::stringstream ss; ss << src::Location(1, 10); EXPECT_EQ("1:10", ss.str()); }