Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
c515b5bf
Commit
c515b5bf
authored
Nov 18, 2011
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for renaming a file and adding it to the index
Thanks to Emeric.
parent
472d4d85
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
2 deletions
+72
-2
tests-clay/clay.h
+1
-0
tests-clay/clay_main.c
+11
-2
tests-clay/index/rename.c
+60
-0
No files found.
tests-clay/clay.h
View file @
c515b5bf
...
...
@@ -85,6 +85,7 @@ extern void test_core_strtol__int64(void);
extern
void
test_core_vector__0
(
void
);
extern
void
test_core_vector__1
(
void
);
extern
void
test_core_vector__2
(
void
);
extern
void
test_index_rename__single_file
(
void
);
extern
void
test_network_remotes__cleanup
(
void
);
extern
void
test_network_remotes__fnmatch
(
void
);
extern
void
test_network_remotes__initialize
(
void
);
...
...
tests-clay/clay_main.c
View file @
c515b5bf
...
...
@@ -146,6 +146,9 @@ static const struct clay_func _clay_cb_core_vector[] = {
{
"1"
,
&
test_core_vector__1
},
{
"2"
,
&
test_core_vector__2
}
};
static
const
struct
clay_func
_clay_cb_index_rename
[]
=
{
{
"single_file"
,
&
test_index_rename__single_file
}
};
static
const
struct
clay_func
_clay_cb_network_remotes
[]
=
{
{
"fnmatch"
,
&
test_network_remotes__fnmatch
},
{
"parsing"
,
&
test_network_remotes__parsing
},
...
...
@@ -267,6 +270,12 @@ static const struct clay_suite _clay_suites[] = {
_clay_cb_core_vector
,
3
},
{
"index::rename"
,
{
NULL
,
NULL
},
{
NULL
,
NULL
},
_clay_cb_index_rename
,
1
},
{
"network::remotes"
,
{
"initialize"
,
&
test_network_remotes__initialize
},
{
"cleanup"
,
&
test_network_remotes__cleanup
},
...
...
@@ -340,8 +349,8 @@ static const struct clay_suite _clay_suites[] = {
}
};
static
size_t
_clay_suite_count
=
2
1
;
static
size_t
_clay_callback_count
=
6
4
;
static
size_t
_clay_suite_count
=
2
2
;
static
size_t
_clay_callback_count
=
6
5
;
/* Core test functions */
static
void
...
...
tests-clay/index/rename.c
0 → 100644
View file @
c515b5bf
#include "clay_libgit2.h"
#include "posix.h"
static
void
file_create
(
const
char
*
filename
,
const
char
*
content
)
{
int
fd
;
fd
=
p_creat
(
filename
,
0666
);
cl_assert
(
fd
!=
0
);
cl_git_pass
(
p_write
(
fd
,
content
,
strlen
(
content
)));
cl_git_pass
(
p_close
(
fd
))
}
void
test_index_rename__single_file
(
void
)
{
git_repository
*
repo
;
git_index
*
index
;
int
position
;
git_oid
expected
;
git_index_entry
*
entry
;
p_mkdir
(
"rename"
,
0700
);
cl_git_pass
(
git_repository_init
(
&
repo
,
"./rename"
,
0
));
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_assert
(
git_index_entrycount
(
index
)
==
0
);
file_create
(
"./rename/lame.name.txt"
,
"new_file
\n
"
);
/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
cl_git_pass
(
git_index_add
(
index
,
"lame.name.txt"
,
0
));
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
cl_git_pass
(
git_oid_fromstr
(
&
expected
,
"d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"
));
position
=
git_index_find
(
index
,
"lame.name.txt"
);
entry
=
git_index_get
(
index
,
position
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
/* This removes the entry from the index, but not from the object database */
cl_git_pass
(
git_index_remove
(
index
,
position
));
cl_assert
(
git_index_entrycount
(
index
)
==
0
);
p_rename
(
"./rename/lame.name.txt"
,
"./rename/fancy.name.txt"
);
cl_git_pass
(
git_index_add
(
index
,
"fancy.name.txt"
,
0
));
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
position
=
git_index_find
(
index
,
"fancy.name.txt"
);
entry
=
git_index_get
(
index
,
position
);
cl_assert
(
git_oid_cmp
(
&
expected
,
&
entry
->
oid
)
==
0
);
git_index_free
(
index
);
git_repository_free
(
repo
);
cl_fixture_cleanup
(
"rename"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment