Skip to content

Commit 2fc0fcb

Browse files
authored
Merge pull request libgit2#6262 from libgit2/ethomson/zero_stat
tests: support flaky stat
2 parents 4e85b4f + e7fce1b commit 2fc0fcb

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ jobs:
248248
-e CMAKE_GENERATOR \
249249
-e CMAKE_OPTIONS \
250250
-e GITTEST_NEGOTIATE_PASSWORD \
251+
-e GITTEST_FLAKY_STAT \
251252
-e PKG_CONFIG_PATH \
252253
-e SKIP_NEGOTIATE_TESTS \
253254
-e SKIP_SSH_TESTS \

.github/workflows/nightly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ jobs:
247247
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
248248
RUN_INVASIVE_TESTS: true
249249
SKIP_PROXY_TESTS: true
250+
GITTEST_FLAKY_STAT: true
250251
os: ubuntu-latest
251252
- name: "Linux (arm64, Bionic, GCC, OpenSSL)"
252253
container:
@@ -305,6 +306,7 @@ jobs:
305306
-e CMAKE_GENERATOR \
306307
-e CMAKE_OPTIONS \
307308
-e GITTEST_NEGOTIATE_PASSWORD \
309+
-e GITTEST_FLAKY_STAT \
308310
-e PKG_CONFIG_PATH \
309311
-e SKIP_NEGOTIATE_TESTS \
310312
-e SKIP_SSH_TESTS \

tests/libgit2/diff/workdir.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ void test_diff_workdir__can_diff_empty_file(void)
12381238
git_tree *tree;
12391239
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
12401240
git_patch *patch;
1241+
struct stat st = {0};
12411242

12421243
g_repo = cl_git_sandbox_init("attr_index");
12431244

@@ -1252,13 +1253,10 @@ void test_diff_workdir__can_diff_empty_file(void)
12521253
/* empty contents of file */
12531254
cl_git_rewritefile("attr_index/README.txt", "");
12541255

1255-
#if !defined(__arm__) || !defined(GIT_ARCH_32)
1256-
{
1257-
struct stat st;
1258-
cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st));
1259-
cl_assert(st.st_size == 0);
1260-
}
1261-
#endif
1256+
cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st));
1257+
1258+
if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
1259+
cl_assert_equal_sz(0, st.st_size);
12621260

12631261
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
12641262
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));

tests/util/copy.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
void test_copy__file(void)
66
{
7-
struct stat st;
7+
struct stat st = {0};
88
const char *content = "This is some stuff to copy\n";
99

1010
cl_git_mkfile("copy_me", content);
@@ -13,15 +13,17 @@ void test_copy__file(void)
1313

1414
cl_git_pass(git_fs_path_lstat("copy_me_two", &st));
1515
cl_assert(S_ISREG(st.st_mode));
16-
cl_assert(strlen(content) == (size_t)st.st_size);
16+
17+
if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
18+
cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
1719

1820
cl_git_pass(p_unlink("copy_me_two"));
1921
cl_git_pass(p_unlink("copy_me"));
2022
}
2123

2224
void test_copy__file_in_dir(void)
2325
{
24-
struct stat st;
26+
struct stat st = {0};
2527
const char *content = "This is some other stuff to copy\n";
2628

2729
cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH));
@@ -38,7 +40,9 @@ void test_copy__file_in_dir(void)
3840

3941
cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st));
4042
cl_assert(S_ISREG(st.st_mode));
41-
cl_assert(strlen(content) == (size_t)st.st_size);
43+
44+
if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
45+
cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
4246

4347
cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES));
4448
cl_assert(!git_fs_path_isdir("an_dir"));
@@ -97,11 +101,15 @@ void test_copy__tree(void)
97101
cl_assert(git_fs_path_isfile("t1/c/d/f4"));
98102
cl_assert(!git_fs_path_isfile("t1/c/d/.f5"));
99103

104+
memset(&st, 0, sizeof(struct stat));
100105
cl_git_pass(git_fs_path_lstat("t1/c/f3", &st));
101106
cl_assert(S_ISREG(st.st_mode));
102-
cl_assert(strlen(content) == (size_t)st.st_size);
107+
108+
if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
109+
cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
103110

104111
#ifndef GIT_WIN32
112+
memset(&st, 0, sizeof(struct stat));
105113
cl_git_pass(git_fs_path_lstat("t1/c/d/l1", &st));
106114
cl_assert(S_ISLNK(st.st_mode));
107115
#endif
@@ -127,6 +135,7 @@ void test_copy__tree(void)
127135
cl_assert(git_fs_path_isfile("t2/c/d/.f5"));
128136

129137
#ifndef GIT_WIN32
138+
memset(&st, 0, sizeof(struct stat));
130139
cl_git_fail(git_fs_path_lstat("t2/c/d/l1", &st));
131140
#endif
132141

0 commit comments

Comments
 (0)