1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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());
}
|