Skip to content

Commit 2e6cbff

Browse files
committed
tests: add missing error checks
We should always verify error codes returned by function calls in our test suite to not accidentally miss any weird results. Coverity reported missing checks in several locations, which this commit fixes.
1 parent 7d65d4c commit 2e6cbff

File tree

7 files changed

+11
-17
lines changed

7 files changed

+11
-17
lines changed

tests/config/global.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void test_config_global__lock_missing_global_config(void)
8181
git_config_entry *entry;
8282
git_transaction *transaction;
8383

84-
p_unlink("home/.gitconfig"); /* No global config */
84+
(void)p_unlink("home/.gitconfig"); /* No global config */
8585

8686
cl_git_pass(git_config_open_default(&cfg));
8787
cl_git_pass(git_config_lock(&transaction, cfg));

tests/config/new.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ void test_config_new__write_new_config(void)
3030
git_buf_dispose(&buf);
3131
git_config_free(config);
3232

33-
p_unlink(TEST_CONFIG);
33+
cl_must_pass(p_unlink(TEST_CONFIG));
3434
}

tests/ignore/path.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void test_ignore_path__globs_without_star(void)
255255
void test_ignore_path__skip_gitignore_directory(void)
256256
{
257257
cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
258-
p_unlink("attr/.gitignore");
258+
cl_must_pass(p_unlink("attr/.gitignore"));
259259
cl_assert(!git_path_exists("attr/.gitignore"));
260260
p_mkdir("attr/.gitignore", 0777);
261261
cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
@@ -268,12 +268,11 @@ void test_ignore_path__skip_gitignore_directory(void)
268268

269269
void test_ignore_path__subdirectory_gitignore(void)
270270
{
271-
p_unlink("attr/.gitignore");
271+
cl_must_pass(p_unlink("attr/.gitignore"));
272272
cl_assert(!git_path_exists("attr/.gitignore"));
273273
cl_git_mkfile(
274274
"attr/.gitignore",
275275
"file1\n");
276-
p_mkdir("attr/dir", 0777);
277276
cl_git_mkfile(
278277
"attr/dir/.gitignore",
279278
"file2/\n");

tests/index/nsec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static bool should_expect_nsecs(void)
5454

5555
expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);
5656

57-
p_unlink(nsec_path.ptr);
57+
cl_must_pass(p_unlink(nsec_path.ptr));
5858

5959
git_buf_dispose(&nsec_path);
6060

tests/index/tests.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ void test_index_tests__cannot_add_invalid_filename(void)
566566
{
567567
git_repository *repo;
568568

569-
p_mkdir("invalid", 0700);
570-
569+
cl_must_pass(p_mkdir("invalid", 0700));
571570
cl_git_pass(git_repository_init(&repo, "./invalid", 0));
572571
cl_must_pass(p_mkdir("./invalid/subdir", 0777));
573572

tests/network/refspecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void assert_invalid_rtransform(const char *refspec, const char *name)
153153
git_refspec spec;
154154
git_buf buf = GIT_BUF_INIT;
155155

156-
git_refspec__parse(&spec, refspec, true);
156+
cl_git_pass(git_refspec__parse(&spec, refspec, true));
157157
cl_git_fail(git_refspec_rtransform(&buf, &spec, name));
158158

159159
git_buf_dispose(&buf);

tests/notes/notes.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,11 @@ void test_notes_notes__can_read_a_note_from_a_commit(void)
400400
git_note *note;
401401

402402
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
403-
404403
cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1));
405-
406-
git_commit_lookup(&notes_commit, _repo, &notes_commit_oid);
407-
404+
cl_git_pass(git_commit_lookup(&notes_commit, _repo, &notes_commit_oid));
408405
cl_assert(notes_commit);
409406

410407
cl_git_pass(git_note_commit_read(&note, _repo, notes_commit, &oid));
411-
412408
cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n");
413409

414410
git_commit_free(notes_commit);
@@ -457,7 +453,7 @@ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
457453
git_note *_note;
458454

459455
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
460-
456+
461457
for (i = 0; i < MESSAGES_COUNT; i++) {
462458
cl_git_pass(git_note_create(&note_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0));
463459
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid));
@@ -511,7 +507,7 @@ void test_notes_notes__can_remove_a_note_from_commit(void)
511507

512508
cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0));
513509

514-
git_commit_lookup(&existing_notes_commit, _repo, &notes_commit_oid);
510+
cl_git_pass(git_commit_lookup(&existing_notes_commit, _repo, &notes_commit_oid));
515511

516512
cl_assert(existing_notes_commit);
517513

@@ -547,7 +543,7 @@ void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(voi
547543

548544
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
549545
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
550-
546+
551547
error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid);
552548
cl_git_fail(error);
553549
cl_assert_equal_i(GIT_ENOTFOUND, error);

0 commit comments

Comments
 (0)