Skip to content

Commit 9c5e05a

Browse files
committed
deprecation: move deprecated tests into their own file
Move the deprecated stream tests into their own compilation unit. This will allow us to disable any preprocessor directives that apply to deprecation just for these tests (eg, disabling `GIT_DEPRECATED_HARD`).
1 parent e09f0c1 commit 9c5e05a

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

tests/stream/deprecated.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "clar_libgit2.h"
2+
#include "git2/sys/stream.h"
3+
#include "streams/tls.h"
4+
#include "streams/socket.h"
5+
#include "stream.h"
6+
7+
static git_stream test_stream;
8+
static int ctor_called;
9+
10+
void test_stream_deprecated__cleanup(void)
11+
{
12+
cl_git_pass(git_stream_register(GIT_STREAM_TLS | GIT_STREAM_STANDARD, NULL));
13+
}
14+
15+
static int test_stream_init(git_stream **out, const char *host, const char *port)
16+
{
17+
GIT_UNUSED(host);
18+
GIT_UNUSED(port);
19+
20+
ctor_called = 1;
21+
*out = &test_stream;
22+
23+
return 0;
24+
}
25+
26+
void test_stream_deprecated__register_tls(void)
27+
{
28+
git_stream *stream;
29+
int error;
30+
31+
ctor_called = 0;
32+
cl_git_pass(git_stream_register_tls(test_stream_init));
33+
cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
34+
cl_assert_equal_i(1, ctor_called);
35+
cl_assert_equal_p(&test_stream, stream);
36+
37+
ctor_called = 0;
38+
stream = NULL;
39+
cl_git_pass(git_stream_register_tls(NULL));
40+
error = git_tls_stream_new(&stream, "localhost", "443");
41+
42+
/*
43+
* We don't have TLS support enabled, or we're on Windows,
44+
* which has no arbitrary TLS stream support.
45+
*/
46+
#if defined(GIT_WIN32) || !defined(GIT_HTTPS)
47+
cl_git_fail_with(-1, error);
48+
#else
49+
cl_git_pass(error);
50+
#endif
51+
52+
cl_assert_equal_i(0, ctor_called);
53+
cl_assert(&test_stream != stream);
54+
55+
git_stream_free(stream);
56+
}
Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
static git_stream test_stream;
88
static int ctor_called;
99

10-
void test_core_stream__cleanup(void)
10+
void test_stream_registration__cleanup(void)
1111
{
1212
cl_git_pass(git_stream_register(GIT_STREAM_TLS | GIT_STREAM_STANDARD, NULL));
1313
}
@@ -34,7 +34,7 @@ static int test_stream_wrap(git_stream **out, git_stream *in, const char *host)
3434
return 0;
3535
}
3636

37-
void test_core_stream__register_insecure(void)
37+
void test_stream_registration__insecure(void)
3838
{
3939
git_stream *stream;
4040
git_stream_registration registration = {0};
@@ -60,7 +60,7 @@ void test_core_stream__register_insecure(void)
6060
git_stream_free(stream);
6161
}
6262

63-
void test_core_stream__register_tls(void)
63+
void test_stream_registration__tls(void)
6464
{
6565
git_stream *stream;
6666
git_stream_registration registration = {0};
@@ -96,7 +96,7 @@ void test_core_stream__register_tls(void)
9696
git_stream_free(stream);
9797
}
9898

99-
void test_core_stream__register_both(void)
99+
void test_stream_registration__both(void)
100100
{
101101
git_stream *stream;
102102
git_stream_registration registration = {0};
@@ -117,35 +117,3 @@ void test_core_stream__register_both(void)
117117
cl_assert_equal_i(1, ctor_called);
118118
cl_assert_equal_p(&test_stream, stream);
119119
}
120-
121-
void test_core_stream__register_tls_deprecated(void)
122-
{
123-
git_stream *stream;
124-
int error;
125-
126-
ctor_called = 0;
127-
cl_git_pass(git_stream_register_tls(test_stream_init));
128-
cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
129-
cl_assert_equal_i(1, ctor_called);
130-
cl_assert_equal_p(&test_stream, stream);
131-
132-
ctor_called = 0;
133-
stream = NULL;
134-
cl_git_pass(git_stream_register_tls(NULL));
135-
error = git_tls_stream_new(&stream, "localhost", "443");
136-
137-
/*
138-
* We don't have TLS support enabled, or we're on Windows,
139-
* which has no arbitrary TLS stream support.
140-
*/
141-
#if defined(GIT_WIN32) || !defined(GIT_HTTPS)
142-
cl_git_fail_with(-1, error);
143-
#else
144-
cl_git_pass(error);
145-
#endif
146-
147-
cl_assert_equal_i(0, ctor_called);
148-
cl_assert(&test_stream != stream);
149-
150-
git_stream_free(stream);
151-
}

0 commit comments

Comments
 (0)