Skip to content

Commit 953427b

Browse files
authored
Merge pull request libgit2#4269 from pks-t/pks/tests
Test improvements
2 parents 2ca088b + a180e7d commit 953427b

File tree

6 files changed

+294
-33
lines changed

6 files changed

+294
-33
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,6 @@ IF (MSVC)
468468
SET(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
469469

470470
SET(WIN_RC "src/win32/git2.rc")
471-
472-
# Precompiled headers
473-
474471
ELSE ()
475472
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
476473

@@ -481,9 +478,7 @@ ELSE ()
481478
SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
482479
ENDIF()
483480

484-
IF (WIN32 AND NOT CYGWIN)
485-
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
486-
ENDIF ()
481+
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
487482

488483
IF (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
489484
STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")

tests/core/structinit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,9 @@ void test_core_structinit__compare(void)
165165
CHECK_MACRO_FUNC_INIT_EQUAL( \
166166
git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
167167
GIT_SUBMODULE_UPDATE_OPTIONS_INIT, git_submodule_update_init_options);
168+
169+
/* submodule update */
170+
CHECK_MACRO_FUNC_INIT_EQUAL( \
171+
git_proxy_options, GIT_PROXY_OPTIONS_VERSION, \
172+
GIT_PROXY_OPTIONS_INIT, git_proxy_init_options);
168173
}

tests/network/remote/local.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "buffer.h"
33
#include "path.h"
44
#include "posix.h"
5+
#include "git2/sys/repository.h"
56

67
static git_repository *repo;
78
static git_buf file_path_buf = GIT_BUF_INIT;

tests/odb/backend/backend_helpers.c

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44

55
static int search_object(const fake_object **out, fake_backend *fake, const git_oid *oid, size_t len)
66
{
7-
const fake_object *obj = fake->objects;
7+
const fake_object *obj = fake->objects, *found = NULL;
88

99
while (obj && obj->oid) {
1010
git_oid current_oid;
1111

1212
git_oid_fromstr(&current_oid, obj->oid);
1313

1414
if (git_oid_ncmp(&current_oid, oid, len) == 0) {
15-
if (out)
16-
*out = obj;
17-
return 0;
15+
if (found)
16+
return GIT_EAMBIGUOUS;
17+
found = obj;
1818
}
1919

2020
obj++;
2121
}
2222

23-
return GIT_ENOTFOUND;
23+
if (found && out)
24+
*out = found;
25+
26+
return found ? GIT_OK : GIT_ENOTFOUND;
2427
}
2528

2629
static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
@@ -31,7 +34,27 @@ static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
3134

3235
fake->exists_calls++;
3336

34-
return search_object(NULL, fake, oid, GIT_OID_RAWSZ) == GIT_OK;
37+
return search_object(NULL, fake, oid, GIT_OID_HEXSZ) == GIT_OK;
38+
}
39+
40+
static int fake_backend__exists_prefix(
41+
git_oid *out, git_odb_backend *backend, const git_oid *oid, size_t len)
42+
{
43+
const fake_object *obj;
44+
fake_backend *fake;
45+
int error;
46+
47+
fake = (fake_backend *)backend;
48+
49+
fake->exists_prefix_calls++;
50+
51+
if ((error = search_object(&obj, fake, oid, len)) < 0)
52+
return error;
53+
54+
if (out)
55+
git_oid_fromstr(out, obj->oid);
56+
57+
return 0;
3558
}
3659

3760
static int fake_backend__read(
@@ -40,19 +63,20 @@ static int fake_backend__read(
4063
{
4164
const fake_object *obj;
4265
fake_backend *fake;
66+
int error;
4367

4468
fake = (fake_backend *)backend;
4569

4670
fake->read_calls++;
4771

48-
if (search_object(&obj, fake, oid, GIT_OID_RAWSZ) == 0) {
49-
*len_p = strlen(obj->content);
50-
*buffer_p = git__strdup(obj->content);
51-
*type_p = GIT_OBJ_BLOB;
52-
return 0;
53-
}
72+
if ((error = search_object(&obj, fake, oid, GIT_OID_HEXSZ)) < 0)
73+
return error;
5474

55-
return GIT_ENOTFOUND;
75+
*len_p = strlen(obj->content);
76+
*buffer_p = git__strdup(obj->content);
77+
*type_p = GIT_OBJ_BLOB;
78+
79+
return 0;
5680
}
5781

5882
static int fake_backend__read_header(
@@ -61,18 +85,19 @@ static int fake_backend__read_header(
6185
{
6286
const fake_object *obj;
6387
fake_backend *fake;
88+
int error;
6489

6590
fake = (fake_backend *)backend;
6691

6792
fake->read_header_calls++;
6893

69-
if (search_object(&obj, fake, oid, GIT_OID_RAWSZ) == 0) {
70-
*len_p = strlen(obj->content);
71-
*type_p = GIT_OBJ_BLOB;
72-
return 0;
73-
}
94+
if ((error = search_object(&obj, fake, oid, GIT_OID_HEXSZ)) < 0)
95+
return error;
7496

75-
return GIT_ENOTFOUND;
97+
*len_p = strlen(obj->content);
98+
*type_p = GIT_OBJ_BLOB;
99+
100+
return 0;
76101
}
77102

78103
static int fake_backend__read_prefix(
@@ -81,20 +106,21 @@ static int fake_backend__read_prefix(
81106
{
82107
const fake_object *obj;
83108
fake_backend *fake;
109+
int error;
84110

85111
fake = (fake_backend *)backend;
86112

87113
fake->read_prefix_calls++;
88114

89-
if (search_object(&obj, fake, short_oid, len) == 0) {
90-
git_oid_fromstr(out_oid, obj->oid);
91-
*len_p = strlen(obj->content);
92-
*buffer_p = git__strdup(obj->content);
93-
*type_p = GIT_OBJ_BLOB;
94-
return 0;
95-
}
115+
if ((error = search_object(&obj, fake, short_oid, len)) < 0)
116+
return error;
96117

97-
return GIT_ENOTFOUND;
118+
git_oid_fromstr(out_oid, obj->oid);
119+
*len_p = strlen(obj->content);
120+
*buffer_p = git__strdup(obj->content);
121+
*type_p = GIT_OBJ_BLOB;
122+
123+
return 0;
98124
}
99125

100126
static void fake_backend__free(git_odb_backend *_backend)
@@ -124,6 +150,7 @@ int build_fake_backend(
124150
backend->parent.read_prefix = fake_backend__read_prefix;
125151
backend->parent.read_header = fake_backend__read_header;
126152
backend->parent.exists = fake_backend__exists;
153+
backend->parent.exists_prefix = fake_backend__exists_prefix;
127154
backend->parent.free = &fake_backend__free;
128155

129156
*out = (git_odb_backend *)backend;

tests/odb/backend/backend_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct {
99
git_odb_backend parent;
1010

1111
int exists_calls;
12+
int exists_prefix_calls;
1213
int read_calls;
1314
int read_header_calls;
1415
int read_prefix_calls;

0 commit comments

Comments
 (0)