History

add tests for cleanup loop

- Also fix some gcc warning

matthias committed 7 years ago

Commit cf3d2371 parent 14be3a12 files · +79 −2Browse files

Unified · Split

2 files
  1. tests/tests2/101_cleanup.c +45 −1
  2. tests/tests2/101_cleanup.expect +34 −1
tests/tests2/101_cleanup.c+45−1
@@ -149,10 +149,53 @@ int test3(void) { · 148 unmodified lines
149149 return 0;
150150 }
151151
152+void cl(int *ip)
153+{
154+ printf("%d\n", *ip);
155+}
156+
157+void loop_cleanups(void)
158+{
159+ __attribute__((cleanup(cl))) int l = 1000;
160+
161+ printf("-- loop 0 --\n");
162+ for ( __attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
163+ __attribute__((cleanup(cl))) int j = 100;
164+ }
165+
166+ printf("-- loop 1 --\n");
167+ for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
168+ __attribute__((cleanup(cl))) int j = 200;
169+ continue;
170+ }
171+
172+ printf("-- loop 2 --\n");
173+ for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
174+ __attribute__((cleanup(cl))) int j = 300;
175+ break;
176+ }
177+
178+ printf("-- loop 3 --\n");
179+ for (int i = 0; i < 2; ++i) {
180+ __attribute__((cleanup(cl))) int j = 400;
181+ switch (i) {
182+ case 0:
183+ continue;
184+ default:
185+ {
186+ __attribute__((cleanup(cl))) int jj = 500;
187+ break;
188+ }
189+ }
190+ }
191+ printf("after break\n");
192+}
193+
152194 int main()
153195 {
154196 int i __attribute__ ((__cleanup__(check))) = 0, not_i;
155197 int chk = 0;
198+ (void)not_i;
156199
157200 {
158201 __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a';
@@ -169,11 +212,12 @@ int main() · 10 unmodified lines
169212 goto naaaaaaaa;
170213 }
171214 i = 105;
172− printf("because what if free was call inside cleanup function\n", test());
215+ printf("because what if free was call inside cleanup function %s\n", test());
173216 test_ret();
174217 test_ret2();
175218 test2();
176219 test3();
220+ loop_cleanups();
177221 return i;
178222 }
179223
tests/tests2/101_cleanup.expect+34−1
@@ -4,7 +4,7 @@ glob_i: 65536 · 3 unmodified lines
44 oo: 2.600000
55 c: f
66 str: I don't think this should be print(but gcc got it wrong too)
7−because what if free was call inside cleanup function
7+because what if free was call inside cleanup function I don't think this should be print(but gcc got it wrong too)
88 should be print before
99 str: that
1010 str: this should appear only once
@@ -15,6 +15,39 @@ str: one · 4 unmodified lines
1515 ---- 1
1616 str: two
1717 str: three
18+-- loop 0 --
19+100
20+100
21+100
22+100
23+100
24+100
25+100
26+100
27+100
28+100
29+10
30+-- loop 1 --
31+200
32+200
33+200
34+200
35+200
36+200
37+200
38+200
39+200
40+200
41+10
42+-- loop 2 --
43+300
44+0
45+-- loop 3 --
46+400
47+500
48+400
49+after break
50+1000
1851 ---- 0
1952 ---- 1
2053 str: plop

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t