Commit 2e6cbff8 by Patrick Steinhardt

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.
parent 7d65d4cb
...@@ -81,7 +81,7 @@ void test_config_global__lock_missing_global_config(void) ...@@ -81,7 +81,7 @@ void test_config_global__lock_missing_global_config(void)
git_config_entry *entry; git_config_entry *entry;
git_transaction *transaction; git_transaction *transaction;
p_unlink("home/.gitconfig"); /* No global config */ (void)p_unlink("home/.gitconfig"); /* No global config */
cl_git_pass(git_config_open_default(&cfg)); cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_lock(&transaction, cfg)); cl_git_pass(git_config_lock(&transaction, cfg));
......
...@@ -30,5 +30,5 @@ void test_config_new__write_new_config(void) ...@@ -30,5 +30,5 @@ void test_config_new__write_new_config(void)
git_buf_dispose(&buf); git_buf_dispose(&buf);
git_config_free(config); git_config_free(config);
p_unlink(TEST_CONFIG); cl_must_pass(p_unlink(TEST_CONFIG));
} }
...@@ -255,7 +255,7 @@ void test_ignore_path__globs_without_star(void) ...@@ -255,7 +255,7 @@ void test_ignore_path__globs_without_star(void)
void test_ignore_path__skip_gitignore_directory(void) void test_ignore_path__skip_gitignore_directory(void)
{ {
cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder"); cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
p_unlink("attr/.gitignore"); cl_must_pass(p_unlink("attr/.gitignore"));
cl_assert(!git_path_exists("attr/.gitignore")); cl_assert(!git_path_exists("attr/.gitignore"));
p_mkdir("attr/.gitignore", 0777); p_mkdir("attr/.gitignore", 0777);
cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n"); cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
...@@ -268,12 +268,11 @@ void test_ignore_path__skip_gitignore_directory(void) ...@@ -268,12 +268,11 @@ void test_ignore_path__skip_gitignore_directory(void)
void test_ignore_path__subdirectory_gitignore(void) void test_ignore_path__subdirectory_gitignore(void)
{ {
p_unlink("attr/.gitignore"); cl_must_pass(p_unlink("attr/.gitignore"));
cl_assert(!git_path_exists("attr/.gitignore")); cl_assert(!git_path_exists("attr/.gitignore"));
cl_git_mkfile( cl_git_mkfile(
"attr/.gitignore", "attr/.gitignore",
"file1\n"); "file1\n");
p_mkdir("attr/dir", 0777);
cl_git_mkfile( cl_git_mkfile(
"attr/dir/.gitignore", "attr/dir/.gitignore",
"file2/\n"); "file2/\n");
......
...@@ -54,7 +54,7 @@ static bool should_expect_nsecs(void) ...@@ -54,7 +54,7 @@ static bool should_expect_nsecs(void)
expect = try_create_file_with_nsec_timestamp(nsec_path.ptr); expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);
p_unlink(nsec_path.ptr); cl_must_pass(p_unlink(nsec_path.ptr));
git_buf_dispose(&nsec_path); git_buf_dispose(&nsec_path);
......
...@@ -566,8 +566,7 @@ void test_index_tests__cannot_add_invalid_filename(void) ...@@ -566,8 +566,7 @@ void test_index_tests__cannot_add_invalid_filename(void)
{ {
git_repository *repo; git_repository *repo;
p_mkdir("invalid", 0700); cl_must_pass(p_mkdir("invalid", 0700));
cl_git_pass(git_repository_init(&repo, "./invalid", 0)); cl_git_pass(git_repository_init(&repo, "./invalid", 0));
cl_must_pass(p_mkdir("./invalid/subdir", 0777)); cl_must_pass(p_mkdir("./invalid/subdir", 0777));
......
...@@ -153,7 +153,7 @@ static void assert_invalid_rtransform(const char *refspec, const char *name) ...@@ -153,7 +153,7 @@ static void assert_invalid_rtransform(const char *refspec, const char *name)
git_refspec spec; git_refspec spec;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
git_refspec__parse(&spec, refspec, true); cl_git_pass(git_refspec__parse(&spec, refspec, true));
cl_git_fail(git_refspec_rtransform(&buf, &spec, name)); cl_git_fail(git_refspec_rtransform(&buf, &spec, name));
git_buf_dispose(&buf); git_buf_dispose(&buf);
......
...@@ -400,15 +400,11 @@ void test_notes_notes__can_read_a_note_from_a_commit(void) ...@@ -400,15 +400,11 @@ void test_notes_notes__can_read_a_note_from_a_commit(void)
git_note *note; git_note *note;
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1)); cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1));
cl_git_pass(git_commit_lookup(&notes_commit, _repo, &notes_commit_oid));
git_commit_lookup(&notes_commit, _repo, &notes_commit_oid);
cl_assert(notes_commit); cl_assert(notes_commit);
cl_git_pass(git_note_commit_read(&note, _repo, notes_commit, &oid)); cl_git_pass(git_note_commit_read(&note, _repo, notes_commit, &oid));
cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n"); cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n");
git_commit_free(notes_commit); git_commit_free(notes_commit);
...@@ -457,7 +453,7 @@ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void) ...@@ -457,7 +453,7 @@ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
git_note *_note; git_note *_note;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
for (i = 0; i < MESSAGES_COUNT; i++) { for (i = 0; i < MESSAGES_COUNT; i++) {
cl_git_pass(git_note_create(&note_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0)); cl_git_pass(git_note_create(&note_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0));
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid)); 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) ...@@ -511,7 +507,7 @@ void test_notes_notes__can_remove_a_note_from_commit(void)
cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); cl_git_pass(git_note_commit_create(&notes_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0));
git_commit_lookup(&existing_notes_commit, _repo, &notes_commit_oid); cl_git_pass(git_commit_lookup(&existing_notes_commit, _repo, &notes_commit_oid));
cl_assert(existing_notes_commit); cl_assert(existing_notes_commit);
...@@ -547,7 +543,7 @@ void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(voi ...@@ -547,7 +543,7 @@ void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(voi
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid); error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid);
cl_git_fail(error); cl_git_fail(error);
cl_assert_equal_i(GIT_ENOTFOUND, error); cl_assert_equal_i(GIT_ENOTFOUND, error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment