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
80c03754
Commit
80c03754
authored
Jun 08, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #757 from benstraub/development
Tests: wrap 'getenv' and friends for Win32 tests.
parents
3f035860
e272efcb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
56 deletions
+64
-56
tests-clar/clar_helpers.c
+57
-0
tests-clar/clar_libgit2.h
+4
-0
tests-clar/core/env.c
+0
-53
tests-clar/refs/revparse.c
+3
-3
No files found.
tests-clar/clar_helpers.c
View file @
80c03754
...
...
@@ -48,6 +48,62 @@ void cl_git_rewritefile(const char *filename, const char *new_content)
cl_git_write2file
(
filename
,
new_content
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
);
}
#ifdef GIT_WIN32
#include "win32/utf-conv.h"
char
*
cl_getenv
(
const
char
*
name
)
{
wchar_t
*
name_utf16
=
gitwin_to_utf16
(
name
);
DWORD
value_len
,
alloc_len
;
wchar_t
*
value_utf16
;
char
*
value_utf8
;
cl_assert
(
name_utf16
);
alloc_len
=
GetEnvironmentVariableW
(
name_utf16
,
NULL
,
0
);
if
(
alloc_len
<=
0
)
return
NULL
;
cl_assert
(
value_utf16
=
git__calloc
(
alloc_len
,
sizeof
(
wchar_t
)));
value_len
=
GetEnvironmentVariableW
(
name_utf16
,
value_utf16
,
alloc_len
);
cl_assert_equal_i
(
value_len
,
alloc_len
-
1
);
cl_assert
(
value_utf8
=
gitwin_from_utf16
(
value_utf16
));
git__free
(
value_utf16
);
return
value_utf8
;
}
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
wchar_t
*
name_utf16
=
gitwin_to_utf16
(
name
);
wchar_t
*
value_utf16
=
value
?
gitwin_to_utf16
(
value
)
:
NULL
;
cl_assert
(
name_utf16
);
cl_assert
(
SetEnvironmentVariableW
(
name_utf16
,
value_utf16
));
git__free
(
name_utf16
);
git__free
(
value_utf16
);
return
0
;
}
#else
#include <stdlib.h>
char
*
cl_getenv
(
const
char
*
name
)
{
return
getenv
(
name
);
}
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
return
(
value
==
NULL
)
?
unsetenv
(
name
)
:
setenv
(
name
,
value
,
1
);
}
#endif
static
const
char
*
_cl_sandbox
=
NULL
;
static
git_repository
*
_cl_repo
=
NULL
;
...
...
@@ -98,3 +154,4 @@ void cl_git_sandbox_cleanup(void)
_cl_sandbox
=
NULL
;
}
}
tests-clar/clar_libgit2.h
View file @
80c03754
...
...
@@ -40,6 +40,10 @@ void cl_git_append2file(const char *filename, const char *new_content);
void
cl_git_rewritefile
(
const
char
*
filename
,
const
char
*
new_content
);
void
cl_git_write2file
(
const
char
*
filename
,
const
char
*
new_content
,
int
mode
);
/* Environment wrappers */
char
*
cl_getenv
(
const
char
*
name
);
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
);
/* Git sandbox setup helpers */
git_repository
*
cl_git_sandbox_init
(
const
char
*
sandbox
);
...
...
tests-clar/core/env.c
View file @
80c03754
...
...
@@ -3,59 +3,6 @@
#include "path.h"
#ifdef GIT_WIN32
#include "win32/utf-conv.h"
static
char
*
cl_getenv
(
const
char
*
name
)
{
wchar_t
*
name_utf16
=
gitwin_to_utf16
(
name
);
DWORD
value_len
,
alloc_len
;
wchar_t
*
value_utf16
;
char
*
value_utf8
;
cl_assert
(
name_utf16
);
alloc_len
=
GetEnvironmentVariableW
(
name_utf16
,
NULL
,
0
);
if
(
alloc_len
<=
0
)
return
NULL
;
cl_assert
(
value_utf16
=
git__calloc
(
alloc_len
,
sizeof
(
wchar_t
)));
value_len
=
GetEnvironmentVariableW
(
name_utf16
,
value_utf16
,
alloc_len
);
cl_assert_equal_i
(
value_len
,
alloc_len
-
1
);
cl_assert
(
value_utf8
=
gitwin_from_utf16
(
value_utf16
));
git__free
(
value_utf16
);
return
value_utf8
;
}
static
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
wchar_t
*
name_utf16
=
gitwin_to_utf16
(
name
);
wchar_t
*
value_utf16
=
value
?
gitwin_to_utf16
(
value
)
:
NULL
;
cl_assert
(
name_utf16
);
cl_assert
(
SetEnvironmentVariableW
(
name_utf16
,
value_utf16
));
git__free
(
name_utf16
);
git__free
(
value_utf16
);
return
0
;
}
#else
#include <stdlib.h>
#define cl_getenv(n) getenv(n)
static
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
return
(
value
==
NULL
)
?
unsetenv
(
name
)
:
setenv
(
name
,
value
,
1
);
}
#endif
#ifdef GIT_WIN32
static
char
*
env_userprofile
=
NULL
;
static
char
*
env_programfiles
=
NULL
;
#else
...
...
tests-clar/refs/revparse.c
View file @
80c03754
...
...
@@ -24,10 +24,10 @@ static void test_object(const char *spec, const char *expected_oid)
void
test_refs_revparse__initialize
(
void
)
{
char
*
tz
=
getenv
(
"TZ"
);
char
*
tz
=
cl_
getenv
(
"TZ"
);
if
(
tz
)
strcpy
(
g_orig_tz
,
tz
);
setenv
(
"TZ"
,
"UTC"
,
1
);
cl_setenv
(
"TZ"
,
"UTC"
);
g_repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
}
...
...
@@ -35,7 +35,7 @@ void test_refs_revparse__cleanup(void)
{
cl_git_sandbox_cleanup
();
g_obj
=
NULL
;
setenv
(
"TZ"
,
g_orig_tz
,
1
);
cl_setenv
(
"TZ"
,
g_orig_tz
);
}
...
...
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