diff options
Diffstat (limited to 'test/errors.cc')
| -rw-r--r-- | test/errors.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/errors.cc b/test/errors.cc new file mode 100644 index 0000000..7d77000 --- /dev/null +++ b/test/errors.cc @@ -0,0 +1,47 @@ +#include "errors.hh" + +#include "location.hh" + +#include <gtest/gtest.h> +#include <memory> +#include <sstream> + +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<src::ErrorsOutput> 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()); +} |
