Skip to content

Commit e3f5f76

Browse files
committed
Update tests
1 parent a675e51 commit e3f5f76

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

source/compiler/tests/warning_250_251.meta

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
'test_type': 'output_check',
33
'errors': """
44
warning_250_251.pwn(19) : warning 250: variable "n" used in loop condition not modified in loop body
5-
warning_250_251.pwn(20) : warning 250: variable "i" used in loop condition not modified in loop body
6-
warning_250_251.pwn(38) : warning 250: variable "n" used in loop condition not modified in loop body
7-
warning_250_251.pwn(39) : warning 250: variable "i" used in loop condition not modified in loop body
8-
warning_250_251.pwn(53) : warning 251: none of the variables used in loop condition are modified in loop body
9-
warning_250_251.pwn(54) : warning 251: none of the variables used in loop condition are modified in loop body
10-
warning_250_251.pwn(111) : warning 250: variable "n" used in loop condition not modified in loop body
11-
warning_250_251.pwn(112) : warning 251: none of the variables used in loop condition are modified in loop body
5+
warning_250_251.pwn(20) : warning 250: variable "n" used in loop condition not modified in loop body
6+
warning_250_251.pwn(21) : warning 250: variable "i" used in loop condition not modified in loop body
7+
warning_250_251.pwn(42) : warning 250: variable "n" used in loop condition not modified in loop body
8+
warning_250_251.pwn(43) : warning 250: variable "n" used in loop condition not modified in loop body
9+
warning_250_251.pwn(44) : warning 250: variable "i" used in loop condition not modified in loop body
10+
warning_250_251.pwn(59) : warning 251: none of the variables used in loop condition are modified in loop body
11+
warning_250_251.pwn(60) : warning 251: none of the variables used in loop condition are modified in loop body
12+
warning_250_251.pwn(61) : warning 251: none of the variables used in loop condition are modified in loop body
13+
warning_250_251.pwn(122) : warning 250: variable "n" used in loop condition not modified in loop body
14+
warning_250_251.pwn(123) : warning 251: none of the variables used in loop condition are modified in loop body
1215
"""
1316
}

source/compiler/tests/warning_250_251.pwn

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ main()
1717

1818
// Case 1: Variable is used inside a loop condition without being modified.
1919
while (n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body
20+
do {} while (n < 10); // warning 250: variable "n" used in loop condition not modified in loop body
2021
for (new i = 0, j = 0; i < 10; ++j) {} // warning 250: variable "i" used in loop condition not modified in loop body
2122

2223
// Case 2: Variable is used inside a loop condition and modified in the loop body.
2324
while (n != 0) { n++; }
25+
do { n++; } while (n < 10);
2426
for (new i = 0; i < 10; ) { i++; }
2527

2628
// Case 3: Variable is used inside a loop condition and modified in the
@@ -30,17 +32,21 @@ main()
3032
// Case 4: Variable is used and modified inside a loop condition.
3133
while (n++ != 0) {}
3234
while (++n != 0) {}
35+
do {} while (n++ != 0);
36+
do {} while (++n != 0);
3337
for (new i = 0; i++ < 10; ) {}
3438
for (new i = 0; ++i < 10; ) {}
3539

3640
// Case 5: Same variable is used inside a loop condition more than once
3741
// and it's not modified.
3842
while (n == 0 || n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body
43+
do {} while (n == 0 || n < 10); // warning 250: variable "n" used in loop condition not modified in loop body
3944
for (new i = 0; i == 0 || i < 10; ) {} // warning 250: variable "i" used in loop condition not modified in loop body
4045

4146
// Case 6: Same variable is used inside a loop condition more than once,
4247
// but it's modified.
4348
while (n == 0 || n < 10) { n++; }
49+
do { n++; } while (n == 0 || n < 10);
4450
for (new i = 0; i == 0 || i < 10; i++) {}
4551

4652
// Case 7: Two variables are used inside a loop condition, both aren't modified.
@@ -51,18 +57,21 @@ main()
5157
// Solution: introduce a warning that simply says that none of the variables
5258
// were modified, and let the user decide which variable should be modified.
5359
while (n < m) {} // warning 251: none of the variables used in loop condition are modified in loop body
60+
do {} while (n < m); // warning 251: none of the variables used in loop condition are modified in loop body
5461
for (new i = 0; i < m; ) {} // warning 251: none of the variables used in loop condition are modified in loop body
5562

5663
// Case 7: Two variables are used in a loop condition, but one of them
5764
// is modified inside the loop body (or the loop counter increment/decrement
5865
// section of a "for" loop), and the other one is not modified.
5966
while (n < m) { ++n; }
67+
do { --m; } while (n < m);
6068
for (new i = 0; i < m; ) { i++; }
6169
for (new i = 0; i < m; i++) {}
6270

6371
// Case 8: Two variables are used in a loop condition, but one of them
6472
// is being modified prior to being used, and the other one is not modified.
6573
while (++n < m) {}
74+
do {} while (++n < m);
6675
for (new i = 0; ++i < m; ) {}
6776

6877
// Case 9: Two variables are used in a loop condition, but one of them
@@ -89,14 +98,16 @@ main()
8998
// may be inaccurate otherwise.
9099
new File:f = fopen("test.txt", io_read);
91100
new line[128];
92-
while(fread(f,line,sizeof(line),false) < m) {} // shouldn't warn about "f" or "m" not being modified
101+
while (fread(f,line,sizeof(line),false) < m) {} // shouldn't warn about "f" or "m" not being modified
102+
do {} while (fread(f,line,sizeof(line),false) < m); // shouldn't warn about "f" or "m" not being modified
93103
fclose(f);
94104

95105
// Case 12: Warnings 250 and 251 shouldn't trigger when at least one global
96106
// variable is used inside the loop condition, as globals can be modified
97107
// from a function called from the loop body and currently there's no easy
98108
// way to track this.
99109
while (n < glbvar) {}
110+
do {} while (n < glbvar);
100111
for (new i = 0; i < glbvar; ) {}
101112

102113
// Case 13: Warnings 250 and 251 shouldn't trigger when the loop counter
@@ -111,4 +122,3 @@ main()
111122
while (n < 10) UseVarByConstRef(n); // warning 250: variable "n" used in loop condition not modified in loop body
112123
while (n < m) UseVarByConstRef(n); // warning 251: none of the variables used in loop condition are modified in loop body
113124
}
114-

0 commit comments

Comments
 (0)