Commit 50e46d6018ede64e3e4b177baa4ad8156d928fbd

Russell Belfer 2014-04-18T10:58:01

Cleanup tests with helper functions

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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
diff --git a/tests/attr/ignore.c b/tests/attr/ignore.c
index a83c5bd..6887519 100644
--- a/tests/attr/ignore.c
+++ b/tests/attr/ignore.c
@@ -16,7 +16,7 @@ void test_attr_ignore__cleanup(void)
 	g_repo = NULL;
 }
 
-void assert_is_ignored_(
+static void assert_is_ignored_(
 	bool expected, const char *filepath, const char *file, int line)
 {
 	int is_ignored = 0;
diff --git a/tests/status/ignore.c b/tests/status/ignore.c
index eb171de..15c85e2 100644
--- a/tests/status/ignore.c
+++ b/tests/status/ignore.c
@@ -16,6 +16,23 @@ void test_status_ignore__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
+static void assert_ignored_(
+	bool expected, const char *filepath, const char *file, int line)
+{
+	int is_ignored = 0;
+	cl_git_pass_(
+		git_status_should_ignore(&is_ignored, g_repo, filepath), file, line);
+	clar__assert(
+		(expected != 0) == (is_ignored != 0),
+		file, line, "expected != is_ignored", filepath, 1);
+}
+#define assert_ignored(expected, filepath) \
+	assert_ignored_(expected, filepath, __FILE__, __LINE__)
+#define assert_is_ignored(filepath) \
+	assert_ignored_(true, filepath, __FILE__, __LINE__)
+#define refute_is_ignored(filepath) \
+	assert_ignored_(false, filepath, __FILE__, __LINE__)
+
 void test_status_ignore__0(void)
 {
 	struct {
@@ -47,11 +64,8 @@ void test_status_ignore__0(void)
 
 	g_repo = cl_git_sandbox_init("attr");
 
-	for (one_test = test_cases; one_test->path != NULL; one_test++) {
-		int ignored;
-		cl_git_pass(git_status_should_ignore(&ignored, g_repo, one_test->path));
-		cl_assert_(ignored == one_test->expected, one_test->path);
-	}
+	for (one_test = test_cases; one_test->path != NULL; one_test++)
+		assert_ignored(one_test->expected, one_test->path);
 
 	/* confirm that ignore files were cached */
 	cl_assert(git_attr_cache__is_cached(
@@ -63,37 +77,22 @@ void test_status_ignore__0(void)
 
 void test_status_ignore__1(void)
 {
-	int ignored;
-
 	g_repo = cl_git_sandbox_init("attr");
 
 	cl_git_rewritefile("attr/.gitignore", "/*.txt\n/dir/\n");
 	git_attr_cache_flush(g_repo);
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "root_test4.txt"));
-	cl_assert(ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/subdir_test2.txt"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir"));
-	cl_assert(ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "dir/"));
-	cl_assert(ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "sub/dir/"));
-	cl_assert(!ignored);
+	assert_is_ignored("root_test4.txt");
+	refute_is_ignored("sub/subdir_test2.txt");
+	assert_is_ignored("dir");
+	assert_is_ignored("dir/");
+	refute_is_ignored("sub/dir");
+	refute_is_ignored("sub/dir/");
 }
 
-
 void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
 {
 	status_entry_single st;
-	int ignored;
 
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
@@ -108,8 +107,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
 	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
 	cl_assert(st.status == GIT_STATUS_WT_NEW);
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
-	cl_assert(!ignored);
+	refute_is_ignored("look-ma.txt");
 
 	cl_git_rewritefile("empty_standard_repo/.gitignore", "*.nomatch\n");
 
@@ -121,8 +119,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
 	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
 	cl_assert(st.status == GIT_STATUS_WT_NEW);
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
-	cl_assert(!ignored);
+	refute_is_ignored("look-ma.txt");
 
 	cl_git_rewritefile("empty_standard_repo/.gitignore", "*.txt\n");
 
@@ -134,8 +131,7 @@ void test_status_ignore__empty_repo_with_gitignore_rewrite(void)
 	cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
 	cl_assert(st.status == GIT_STATUS_IGNORED);
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "look-ma.txt"));
-	cl_assert(ignored);
+	assert_is_ignored("look-ma.txt");
 }
 
 void test_status_ignore__ignore_pattern_contains_space(void)
@@ -181,7 +177,6 @@ void test_status_ignore__ignore_pattern_ignorecase(void)
 void test_status_ignore__subdirectories(void)
 {
 	status_entry_single st;
-	int ignored;
 
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
@@ -198,8 +193,7 @@ void test_status_ignore__subdirectories(void)
 	cl_git_pass(git_status_file(&st.status, g_repo, "ignore_me"));
 	cl_assert(st.status == GIT_STATUS_IGNORED);
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "ignore_me"));
-	cl_assert(ignored);
+	assert_is_ignored("ignore_me");
 
 	/* I've changed libgit2 so that the behavior here now differs from
 	 * core git but seems to make more sense.  In core git, the following
@@ -225,9 +219,7 @@ void test_status_ignore__subdirectories(void)
 	cl_git_pass(git_status_file(&st.status, g_repo, "test/ignore_me/file"));
 	cl_assert(st.status == GIT_STATUS_IGNORED);
 
-	cl_git_pass(
-		git_status_should_ignore(&ignored, g_repo, "test/ignore_me/file"));
-	cl_assert(ignored);
+	assert_is_ignored("test/ignore_me/file");
 }
 
 static void make_test_data(const char *reponame, const char **files)
@@ -439,7 +431,6 @@ void test_status_ignore__contained_dir_with_matching_name(void)
 	static const unsigned int expected_statuses[] = {
 		GIT_STATUS_WT_NEW,  GIT_STATUS_WT_NEW,  GIT_STATUS_IGNORED
 	};
-	int ignored;
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	status_entry_counts counts;
 
@@ -447,13 +438,8 @@ void test_status_ignore__contained_dir_with_matching_name(void)
 	cl_git_mkfile(
 		"empty_standard_repo/subdir_match/.gitignore", "*_ignoreme\n");
 
-	cl_git_pass(git_status_should_ignore(
-		&ignored, g_repo, "subdir_match/aaa/subdir_match/file"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(
-		&ignored, g_repo, "subdir_match/zzz_ignoreme"));
-	cl_assert(ignored);
+	refute_is_ignored("subdir_match/aaa/subdir_match/file");
+	assert_is_ignored("subdir_match/zzz_ignoreme");
 
 	memset(&counts, 0x0, sizeof(status_entry_counts));
 	counts.expected_entry_count = 3;
@@ -472,149 +458,102 @@ void test_status_ignore__contained_dir_with_matching_name(void)
 
 void test_status_ignore__adding_internal_ignores(void)
 {
-	int ignored;
-
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(!ignored);
+	refute_is_ignored("one.txt");
+	refute_is_ignored("two.bar");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, "*.nomatch\n"));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(!ignored);
+	refute_is_ignored("one.txt");
+	refute_is_ignored("two.bar");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, "*.txt\n"));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(!ignored);
+	assert_is_ignored("one.txt");
+	refute_is_ignored("two.bar");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, "*.bar\n"));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(ignored);
+	assert_is_ignored("one.txt");
+	assert_is_ignored("two.bar");
 
 	cl_git_pass(git_ignore_clear_internal_rules(g_repo));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(!ignored);
+	refute_is_ignored("one.txt");
+	refute_is_ignored("two.bar");
 
 	cl_git_pass(git_ignore_add_rule(
 		g_repo, "multiple\n*.rules\n# comment line\n*.bar\n"));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.txt"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(ignored);
+	refute_is_ignored("one.txt");
+	assert_is_ignored("two.bar");
 }
 
 void test_status_ignore__add_internal_as_first_thing(void)
 {
-	int ignored;
 	const char *add_me = "\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n\n";
 
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, add_me));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.tmp"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
-	cl_assert(!ignored);
+	assert_is_ignored("one.tmp");
+	refute_is_ignored("two.bar");
 }
 
 void test_status_ignore__internal_ignores_inside_deep_paths(void)
 {
-	int ignored;
 	const char *add_me = "Debug\nthis/is/deep\npatterned*/dir\n";
 
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, add_me));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/Debug"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "really/Debug/this/file"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "Debug/what/I/say"));
-	cl_assert(ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/NoDebug"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "NoDebug/this"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "please/NoDebug/this"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep"));
-	cl_assert(ignored);
+	assert_is_ignored("Debug");
+	assert_is_ignored("and/Debug");
+	assert_is_ignored("really/Debug/this/file");
+	assert_is_ignored("Debug/what/I/say");
+
+	refute_is_ignored("and/NoDebug");
+	refute_is_ignored("NoDebug/this");
+	refute_is_ignored("please/NoDebug/this");
+
+	assert_is_ignored("this/is/deep");
 	/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "and/this/is/deep"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deep/too"));
-	cl_assert(ignored);
+	refute_is_ignored("and/this/is/deep");
+	assert_is_ignored("this/is/deep/too");
 	/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "but/this/is/deep/and/ignored"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/not/deep"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "is/this/not/as/deep"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/is/deepish"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "xthis/is/deep"));
-	cl_assert(!ignored);
+	refute_is_ignored("but/this/is/deep/and/ignored");
+
+	refute_is_ignored("this/is/not/deep");
+	refute_is_ignored("is/this/not/as/deep");
+	refute_is_ignored("this/is/deepish");
+	refute_is_ignored("xthis/is/deep");
 }
 
 void test_status_ignore__automatically_ignore_bad_files(void)
 {
-	int ignored;
-
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
-	cl_assert(!ignored);
+	assert_is_ignored(".git");
+	assert_is_ignored("this/file/.");
+	assert_is_ignored("path/../funky");
+	refute_is_ignored("path/whatever.c");
 
 	cl_git_pass(git_ignore_add_rule(g_repo, "*.c\n"));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
-	cl_assert(ignored);
+	assert_is_ignored(".git");
+	assert_is_ignored("this/file/.");
+	assert_is_ignored("path/../funky");
+	assert_is_ignored("path/whatever.c");
 
 	cl_git_pass(git_ignore_clear_internal_rules(g_repo));
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, ".git"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "this/file/."));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/../funky"));
-	cl_assert(ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "path/whatever.c"));
-	cl_assert(!ignored);
+	assert_is_ignored(".git");
+	assert_is_ignored("this/file/.");
+	assert_is_ignored("path/../funky");
+	refute_is_ignored("path/whatever.c");
 }
 
 void test_status_ignore__filenames_with_special_prefixes_do_not_interfere_with_status_retrieval(void)
@@ -653,7 +592,6 @@ void test_status_ignore__filenames_with_special_prefixes_do_not_interfere_with_s
 
 void test_status_ignore__issue_1766_negated_ignores(void)
 {
-	int ignored = 0;
 	unsigned int status;
 
 	g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -665,11 +603,8 @@ void test_status_ignore__issue_1766_negated_ignores(void)
 	cl_git_mkfile(
 		"empty_standard_repo/a/ignoreme", "I should be ignored\n");
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/.gitignore"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/ignoreme"));
-	cl_assert(ignored);
+	refute_is_ignored("a/.gitignore");
+	assert_is_ignored("a/ignoreme");
 
 	cl_git_pass(git_futils_mkdir_r(
 		"empty_standard_repo/b", NULL, 0775));
@@ -678,18 +613,12 @@ void test_status_ignore__issue_1766_negated_ignores(void)
 	cl_git_mkfile(
 		"empty_standard_repo/b/ignoreme", "I should be ignored\n");
 
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "b/.gitignore"));
-	cl_assert(!ignored);
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "b/ignoreme"));
-	cl_assert(ignored);
+	refute_is_ignored("b/.gitignore");
+	assert_is_ignored("b/ignoreme");
 
 	/* shouldn't have changed results from first couple either */
-
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/.gitignore"));
-	cl_assert(!ignored);
-	cl_git_pass(git_status_should_ignore(&ignored, g_repo, "a/ignoreme"));
-	cl_assert(ignored);
+	refute_is_ignored("a/.gitignore");
+	assert_is_ignored("a/ignoreme");
 
 	/* status should find the two ignore files and nothing else */