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"""(
8895semantic error: Error with label no message
89- --> input:1:5
96+ --> input.txt :1:5
9097 |
91981 | 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"""(
106113semantic error: Error with label and message
107- --> input:1:5
114+ --> input.txt :1:5
108115 |
1091161 | 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"""(
123130semantic error: Error with label and message
124- --> input:1:5
131+ --> input.txt :1:5
125132 |
1261331 | 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"""(
144151semantic error: Error with two labels and message
145- --> input:1:5
152+ --> input.txt :1:5
146153 |
1471541 | 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"""(
166173semantic error: Error with two labels and message
167- --> input:1:5
174+ --> input.txt :1:5
168175 |
1691761 | 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"""(
191198semantic error: Error with two labels and message
192- --> input:1:5
199+ --> input.txt :1:5
193200 |
1942011 | 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"""(
216223semantic error: Error with three labels and message, two spans
217- --> input:1:5
224+ --> input.txt :1:5
218225 |
2192261 | 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\n Second line text\n Third 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"""(
259272semantic error: Error with label no message
260- --> input:1:5 - 2:11
273+ --> input.txt :1:5 - 2:11
261274 |
2622751 | 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"""(
280293semantic error: Error with label, two spans
281- --> input:1:5 - 2:11
294+ --> input.txt :1:5 - 2:11
282295 |
2832961 | 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"""(
308321semantic error: Error with label, two spans
309- --> input:1:1
322+ --> input.txt :1:1
310323 |
3113241 | One line text
312325 | ^^^ Two spans
0 commit comments