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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#include "yql_issue_utils.h"
#include "yql_issue.h"
#include "yql_issue_id.h"
#include <library/cpp/testing/unittest/registar.h>
#include <util/string/subst.h>
using namespace NYql;
Y_UNIT_TEST_SUITE(TIssueUtilsTest) {
Y_UNIT_TEST(TruncLevels1) {
auto level0 = MakeIntrusive<TIssue>("level0");
auto level1 = MakeIntrusive<TIssue>("level1");
auto level2 = MakeIntrusive<TIssue>("level2");
auto level30 = MakeIntrusive<TIssue>("level30");
auto level31 = MakeIntrusive<TIssue>("level31");
auto level40 = MakeIntrusive<TIssue>("level40");
auto level41 = MakeIntrusive<TIssue>("level41");
auto level51 = MakeIntrusive<TIssue>("level51");
/*
* * 0
* |
* * 1
* |
* * 2 --
* | |
* * 30 * 31
* | |
* * 40 * 41
* |
* * 51
*/
level0->AddSubIssue(level1);
level1->AddSubIssue(level2);
level2->AddSubIssue(level30);
level2->AddSubIssue(level31);
level30->AddSubIssue(level40);
level31->AddSubIssue(level41);
level41->AddSubIssue(level51);
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(4).SetKeepTailLevels(2))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: level1
<main>: Error: (skipped levels)
<main>: Error: level30
<main>: Error: level40
<main>: Error: level41
<main>: Error: level51
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(3).SetKeepTailLevels(1))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: level1
<main>: Error: (skipped levels)
<main>: Error: level40
<main>: Error: level51
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
}
Y_UNIT_TEST(TruncLevels2) {
auto level0 = MakeIntrusive<TIssue>("level0");
auto level1 = MakeIntrusive<TIssue>("level1");
auto level2 = MakeIntrusive<TIssue>("level2");
auto level3 = MakeIntrusive<TIssue>("level3");
auto level40 = MakeIntrusive<TIssue>("level40");
auto level41 = MakeIntrusive<TIssue>("level41");
/*
* * 0
* |
* * 1
* |
* * 2
* |
* * 3 --
* | |
* * 40 * 41
*/
level0->AddSubIssue(level1);
level1->AddSubIssue(level2);
level2->AddSubIssue(level3);
level3->AddSubIssue(level40);
level3->AddSubIssue(level41);
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(4).SetKeepTailLevels(2))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: level1
<main>: Error: (skipped levels)
<main>: Error: level3
<main>: Error: level40
<main>: Error: level41
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
}
Y_UNIT_TEST(TruncLevels3) {
auto level0 = MakeIntrusive<TIssue>("level0");
auto level1 = MakeIntrusive<TIssue>("level1");
auto level2 = MakeIntrusive<TIssue>("level2");
auto level3 = MakeIntrusive<TIssue>("level3");
auto level40 = MakeIntrusive<TIssue>("level40");
auto level41 = MakeIntrusive<TIssue>("level41");
auto level50 = MakeIntrusive<TIssue>("level50");
/*
* * 0
* |
* * 1
* |
* * 2
* |
* * 3 --
* | |
* * 40 |
* | |
* * 50 * 41
*/
level0->AddSubIssue(level1);
level1->AddSubIssue(level2);
level2->AddSubIssue(level3);
level3->AddSubIssue(level40);
level3->AddSubIssue(level41);
level40->AddSubIssue(level50);
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(4).SetKeepTailLevels(1))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: level1
<main>: Error: level2
<main>: Error: (skipped levels)
<main>: Error: level41
<main>: Error: level50
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(4).SetKeepTailLevels(2))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: level1
<main>: Error: (skipped levels)
<main>: Error: level3
<main>: Error: level41
<main>: Error: level40
<main>: Error: level50
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
{
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(4).SetKeepTailLevels(3))}).ToString();
const auto expected =
R"___(<main>: Error: level0
<main>: Error: (skipped levels)
<main>: Error: level2
<main>: Error: level3
<main>: Error: level40
<main>: Error: level50
<main>: Error: level41
)___";
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
}
Y_UNIT_TEST(KeepSeverity) {
const auto templ =
R"___(<main>: {severity}: level0, code: 1
<main>: {severity}: level1, code: 1
)___";
for (auto severity: {ESeverity::TSeverityIds_ESeverityId_S_INFO, ESeverity::TSeverityIds_ESeverityId_S_WARNING, ESeverity::TSeverityIds_ESeverityId_S_ERROR, ESeverity::TSeverityIds_ESeverityId_S_FATAL}) {
auto level0 = MakeIntrusive<TIssue>(TIssue("level0").SetCode(1, severity));
auto level1 = MakeIntrusive<TIssue>(TIssue("level1").SetCode(1, severity));
level0->AddSubIssue(level1);
const auto res = TIssues({TruncateIssueLevels(*level0, TTruncateIssueOpts().SetMaxLevels(15).SetKeepTailLevels(3))}).ToString();
const auto expected = SubstGlobalCopy<TString, TString>(templ, "{severity}", SeverityToString(severity));
UNIT_ASSERT_STRINGS_EQUAL(res, expected);
}
}
}
|