Skip to content

Commit fac6eb6

Browse files
Introduce FileLocations in the test_error_rendering
Store the input into the input.txt. Later use this to render the errors.
1 parent 7b2546b commit fac6eb6

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ share/jupyter/kernels/fortran/kernel.json
6262
src/runtime/*.o.empty.c
6363
python_ast.py
6464
python_ast.h
65-
ser.txt
65+
input.txt
6666
integration_tests/py_*
6767
integration_tests/b1/*
6868
integration_tests/b2/*
@@ -72,6 +72,7 @@ integration_tests/b5/*
7272
integration_tests/b6/*
7373
integration_tests/_lpython-tmp-test-*
7474
inst/bin/*
75+
*.tmp
7576
*.tlog
7677
*.filters
7778
*.obj

src/lpython/tests/test_error_rendering.cpp

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <tests/doctest.h>
22

33
#include <iostream>
4-
#include <sstream>
4+
#include <fstream>
55

66
#include <libasr/diagnostics.h>
77

@@ -62,12 +62,19 @@ TEST_CASE("Error Render: primary/secondary labels, single line") {
6262
Location loc1, loc2, loc3;
6363
LocationManager lm;
6464
input = "One line text\n";
65-
lm.in_filename = "input";
66-
lm.get_newlines(input, lm.in_newlines);
67-
lm.out_start.push_back(0);
68-
lm.in_start.push_back(0);
69-
lm.in_start.push_back(input.size());
70-
lm.out_start.push_back(input.size());
65+
{
66+
std::ofstream out("input.txt");
67+
out << input;
68+
LocationManager::FileLocations fl;
69+
fl.in_filename = "input.txt";
70+
lm.get_newlines(input, fl.in_newlines);
71+
fl.out_start.push_back(0);
72+
fl.in_start.push_back(0);
73+
fl.in_start.push_back(input.size());
74+
fl.out_start.push_back(input.size());
75+
lm.files.push_back(fl);
76+
lm.file_ends.push_back(input.size());
77+
}
7178

7279
loc1.first = 4;
7380
loc1.last = 7;
@@ -83,10 +90,10 @@ TEST_CASE("Error Render: primary/secondary labels, single line") {
8390
Label("", {loc1})
8491
}
8592
);
86-
out = render_diagnostic_human(d, input, lm, false, false);
93+
out = render_diagnostic_human(d, lm, false, false);
8794
ref = S(R"""(
8895
semantic error: Error with label no message
89-
--> input:1:5
96+
--> input.txt:1:5
9097
|
9198
1 | One line text
9299
| ^^^^
@@ -101,10 +108,10 @@ semantic error: Error with label no message
101108
Label("label message", {loc1, loc2})
102109
}
103110
);
104-
out = render_diagnostic_human(d, input, lm, false, false);
111+
out = render_diagnostic_human(d, lm, false, false);
105112
ref = S(R"""(
106113
semantic error: Error with label and message
107-
--> input:1:5
114+
--> input.txt:1:5
108115
|
109116
1 | One line text
110117
| ^^^^ ^^^^ label message
@@ -118,10 +125,10 @@ semantic error: Error with label and message
118125
Label("label message", {loc1, loc2, loc3})
119126
}
120127
);
121-
out = render_diagnostic_human(d, input, lm, false, false);
128+
out = render_diagnostic_human(d, lm, false, false);
122129
ref = S(R"""(
123130
semantic error: Error with label and message
124-
--> input:1:5
131+
--> input.txt:1:5
125132
|
126133
1 | One line text
127134
| ^^^^ ^^^^ label message
@@ -139,10 +146,10 @@ semantic error: Error with label and message
139146
Label("label2 message", {loc2})
140147
}
141148
);
142-
out = render_diagnostic_human(d, input, lm, false, false);
149+
out = render_diagnostic_human(d, lm, false, false);
143150
ref = S(R"""(
144151
semantic error: Error with two labels and message
145-
--> input:1:5
152+
--> input.txt:1:5
146153
|
147154
1 | One line text
148155
| ^^^^ label1 message
@@ -161,10 +168,10 @@ semantic error: Error with two labels and message
161168
Label("label3 message", {loc3})
162169
}
163170
);
164-
out = render_diagnostic_human(d, input, lm, false, false);
171+
out = render_diagnostic_human(d, lm, false, false);
165172
ref = S(R"""(
166173
semantic error: Error with two labels and message
167-
--> input:1:5
174+
--> input.txt:1:5
168175
|
169176
1 | One line text
170177
| ^^^^ label1 message
@@ -186,10 +193,10 @@ semantic error: Error with two labels and message
186193
Label("label3 secondary message", {loc3}, false)
187194
}
188195
);
189-
out = render_diagnostic_human(d, input, lm, false, false);
196+
out = render_diagnostic_human(d, lm, false, false);
190197
ref = S(R"""(
191198
semantic error: Error with two labels and message
192-
--> input:1:5
199+
--> input.txt:1:5
193200
|
194201
1 | One line text
195202
| ^^^^ label1 primary message
@@ -211,10 +218,10 @@ semantic error: Error with two labels and message
211218
Label("label3 secondary message", {loc3}, false)
212219
}
213220
);
214-
out = render_diagnostic_human(d, input, lm, false, false);
221+
out = render_diagnostic_human(d, lm, false, false);
215222
ref = S(R"""(
216223
semantic error: Error with three labels and message, two spans
217-
--> input:1:5
224+
--> input.txt:1:5
218225
|
219226
1 | One line text
220227
| ~~~~ ~~~~ label1 secondary message
@@ -233,13 +240,19 @@ TEST_CASE("Error Render: primary/secondary labels, multi line") {
233240
Location loc1, loc2, loc3;
234241
LocationManager lm;
235242
input = "One line text\nSecond line text\nThird line text\n";
236-
lm.in_filename = "input";
237-
lm.get_newlines(input, lm.in_newlines);
238-
lm.out_start.push_back(0);
239-
lm.in_start.push_back(0);
240-
lm.in_start.push_back(input.size());
241-
lm.out_start.push_back(input.size());
242-
243+
{
244+
std::ofstream out("input.txt");
245+
out << input;
246+
LocationManager::FileLocations fl;
247+
fl.in_filename = "input.txt";
248+
lm.get_newlines(input, fl.in_newlines);
249+
fl.out_start.push_back(0);
250+
fl.in_start.push_back(0);
251+
fl.in_start.push_back(input.size());
252+
fl.out_start.push_back(input.size());
253+
lm.files.push_back(fl);
254+
lm.file_ends.push_back(input.size());
255+
}
243256
loc1.first = 4; // 1 line
244257
loc1.last = 24; // 2 line
245258
loc2.first = 9; // 1 text
@@ -254,10 +267,10 @@ TEST_CASE("Error Render: primary/secondary labels, multi line") {
254267
Label("Multilines", {loc1})
255268
}
256269
);
257-
out = render_diagnostic_human(d, input, lm, false, false);
270+
out = render_diagnostic_human(d, lm, false, false);
258271
ref = S(R"""(
259272
semantic error: Error with label no message
260-
--> input:1:5 - 2:11
273+
--> input.txt:1:5 - 2:11
261274
|
262275
1 | One line text
263276
| ^^^^^^^^^...
@@ -275,10 +288,10 @@ semantic error: Error with label no message
275288
Label("Two spans", {loc1, loc2})
276289
}
277290
);
278-
out = render_diagnostic_human(d, input, lm, false, false);
291+
out = render_diagnostic_human(d, lm, false, false);
279292
ref = S(R"""(
280293
semantic error: Error with label, two spans
281-
--> input:1:5 - 2:11
294+
--> input.txt:1:5 - 2:11
282295
|
283296
1 | One line text
284297
| ^^^^^^^^^...
@@ -303,10 +316,10 @@ semantic error: Error with label, two spans
303316
Label("Two spans", {loc3, loc2})
304317
}
305318
);
306-
out = render_diagnostic_human(d, input, lm, false, false);
319+
out = render_diagnostic_human(d, lm, false, false);
307320
ref = S(R"""(
308321
semantic error: Error with label, two spans
309-
--> input:1:1
322+
--> input.txt:1:1
310323
|
311324
1 | One line text
312325
| ^^^ Two spans

0 commit comments

Comments
 (0)