Skip to content

When running with CTest, don't register all tests. #883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libbson/tests/test-bson-corpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,6 @@ void
test_bson_corpus_install (TestSuite *suite)
{
install_json_test_suite_with_check (
suite, BSON_JSON_DIR "/bson_corpus", test_bson_corpus_cb);
suite, BSON_JSON_DIR, "bson_corpus", test_bson_corpus_cb);
TestSuite_Add (suite, "/bson_corpus/prose_1", test_bson_corpus_prose_1);
}
8 changes: 7 additions & 1 deletion src/libmongoc/tests/TestSuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ _V_TestSuite_AddFull (TestSuite *suite,
Test *test;
Test *iter;

if (suite->ctest_run && (0 != strcmp (suite->ctest_run, name))) {
return NULL;
}

test = (Test *) calloc (1, sizeof *test);
test->name = bson_strdup (name);
test->func = func;
Expand Down Expand Up @@ -393,7 +397,9 @@ _TestSuite_AddMockServerTest (TestSuite *suite,
test = _V_TestSuite_AddFull (suite, name, (TestFuncWC) func, NULL, NULL, ap);
va_end (ap);

_TestSuite_AddCheck (test, TestSuite_CheckMockServerAllowed, name);
if (test) {
_TestSuite_AddCheck (test, TestSuite_CheckMockServerAllowed, name);
}
}


Expand Down
22 changes: 18 additions & 4 deletions src/libmongoc/tests/json-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,8 @@ _skip_if_unsupported (const char *test_name, bson_t *original)
*/
void
_install_json_test_suite_with_check (TestSuite *suite,
const char *dir_path,
const char *base,
const char *subdir,
test_hook callback,
...)
{
Expand All @@ -1926,9 +1927,21 @@ _install_json_test_suite_with_check (TestSuite *suite,
char *skip_json;
char *ext;
va_list ap;
char joined[PATH_MAX];
char resolved[PATH_MAX];

snprintf (joined, PATH_MAX, "%s/%s", base, subdir);
ASSERT (realpath (joined, resolved));

if (suite->ctest_run) {
const char *found = strstr (suite->ctest_run, subdir);
if (found != suite->ctest_run && found != suite->ctest_run + 1) {
return;
}
}

num_tests =
collect_tests_from_dir (&test_paths[0], dir_path, 0, MAX_NUM_TESTS);
collect_tests_from_dir (&test_paths[0], resolved, 0, MAX_NUM_TESTS);

for (i = 0; i < num_tests; i++) {
test = get_bson_from_json_file (test_paths[i]);
Expand Down Expand Up @@ -1971,9 +1984,10 @@ _install_json_test_suite_with_check (TestSuite *suite,
*/
void
install_json_test_suite (TestSuite *suite,
const char *dir_path,
const char *base,
const char *subdir,
test_hook callback)
{
install_json_test_suite_with_check (
suite, dir_path, callback, TestSuite_CheckLive);
suite, base, subdir, callback, TestSuite_CheckLive);
}
11 changes: 7 additions & 4 deletions src/libmongoc/tests/json-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,20 @@ json_test_config_cleanup (json_test_config_t *config);

void
_install_json_test_suite_with_check (TestSuite *suite,
const char *dir_path,
const char *base,
const char *subdir,
test_hook callback,
...);

void
install_json_test_suite (TestSuite *suite,
const char *dir_path,
const char *base,
const char *subdir,
test_hook callback);

#define install_json_test_suite_with_check(_suite, _dir_path, ...) \
_install_json_test_suite_with_check (_suite, _dir_path, __VA_ARGS__, NULL)
#define install_json_test_suite_with_check(_suite, _base, _subdir, ...) \
_install_json_test_suite_with_check ( \
_suite, _base, _subdir, __VA_ARGS__, NULL)

void
set_uri_opts_from_bson (mongoc_uri_t *uri, const bson_t *opts);
Expand Down
10 changes: 0 additions & 10 deletions src/libmongoc/tests/test-libmongoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2682,16 +2682,6 @@ test_framework_skip_if_no_setenv (void)
return 1;
}

void
test_framework_resolve_path (const char *path, char *resolved)
{
if (!realpath (path, resolved)) {
MONGOC_ERROR ("Cannot resolve path %s\n", path);
MONGOC_ERROR ("Run test-libmongoc in repository root directory.\n");
ASSERT (false);
}
}

bool
test_framework_is_serverless (void)
{
Expand Down
3 changes: 0 additions & 3 deletions src/libmongoc/tests/test-libmongoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ test_framework_skip_if_no_client_side_encryption (void);
int
test_framework_skip_if_time_sensitive (void);

void
test_framework_resolve_path (const char *path, char *resolved);

int
test_framework_skip_if_no_aws (void);

Expand Down
11 changes: 5 additions & 6 deletions src/libmongoc/tests/test-mongoc-change-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
request_t *_request = mock_server_receives_command ( \
server, \
"db", \
MONGOC_QUERY_SECONDARY_OK, \
MONGOC_QUERY_SECONDARY_OK, \
"{ 'killCursors' : 'coll', 'cursors' : [ " #cursor_id " ] }"); \
mock_server_replies_simple (_request, \
"{ 'cursorsKilled': [ " #cursor_id " ] }"); \
Expand Down Expand Up @@ -1766,7 +1766,7 @@ change_stream_spec_after_test_cb (json_test_ctx_t *test_ctx, const bson_t *test)
}

/* iterate over the change stream, and verify that the document exists.
*/
*/
for (i = 0; i < num_iterations; i++) {
char *key = bson_strdup_printf ("%d", i);
ret = _iterate_until_error_or_event (
Expand All @@ -1782,7 +1782,7 @@ change_stream_spec_after_test_cb (json_test_ctx_t *test_ctx, const bson_t *test)
}

/* check that everything in the "result.success" array is contained in
* our captured changes. */
* our captured changes. */
while (bson_iter_next (&expected_iter)) {
bson_t expected_doc;
match_ctx_t match_ctx = {{0}};
Expand Down Expand Up @@ -2610,7 +2610,6 @@ prose_test_18 (void)
void
test_change_stream_install (TestSuite *suite)
{
char resolved[PATH_MAX];
TestSuite_AddMockServerTest (
suite, "/change_stream/pipeline", test_change_stream_pipeline);

Expand Down Expand Up @@ -2774,6 +2773,6 @@ test_change_stream_install (TestSuite *suite)
TestSuite_AddMockServerTest (
suite, "/change_streams/prose_test_18", prose_test_18);

test_framework_resolve_path (JSON_DIR "/change_streams/legacy", resolved);
install_json_test_suite (suite, resolved, &test_change_stream_spec_cb);
install_json_test_suite (
suite, JSON_DIR, "change_streams/legacy", &test_change_stream_spec_cb);
}
6 changes: 2 additions & 4 deletions src/libmongoc/tests/test-mongoc-client-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2795,8 +2795,6 @@ test_sessions_snapshot_prose_test_1 (void *ctx)
void
test_session_install (TestSuite *suite)
{
char resolved[PATH_MAX];

TestSuite_Add (suite, "/Session/opts/clone", test_session_opts_clone);
TestSuite_Add (suite,
"/Session/opts/causal_consistency_and_snapshot",
Expand Down Expand Up @@ -3151,9 +3149,9 @@ test_session_install (TestSuite *suite)
false,
false);

ASSERT (realpath (JSON_DIR "/sessions/legacy", resolved));
install_json_test_suite_with_check (suite,
resolved,
JSON_DIR,
"sessions/legacy",
test_sessions_spec_cb,
test_framework_skip_if_no_sessions);

Expand Down
6 changes: 2 additions & 4 deletions src/libmongoc/tests/test-mongoc-client-side-encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -3146,12 +3146,10 @@ test_kms_tls_options_extra_rejected (void *unused)
void
test_client_side_encryption_install (TestSuite *suite)
{
char resolved[PATH_MAX];

ASSERT (realpath (JSON_DIR "/client_side_encryption", resolved));
install_json_test_suite_with_check (
suite,
resolved,
JSON_DIR,
"client_side_encryption",
test_client_side_encryption_cb,
test_framework_skip_if_no_client_side_encryption);
/* Prose tests from the spec. */
Expand Down
12 changes: 5 additions & 7 deletions src/libmongoc/tests/test-mongoc-command-monitoring.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ test_command_monitoring_cb (bson_t *scenario)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

run_unified_tests (suite, JSON_DIR "/command_monitoring/unified");

test_framework_resolve_path (JSON_DIR "/command_monitoring/legacy",
resolved);
install_json_test_suite (suite, resolved, &test_command_monitoring_cb);
run_unified_tests (suite, JSON_DIR, "command_monitoring/unified");
install_json_test_suite (suite,
JSON_DIR,
"command_monitoring/legacy",
&test_command_monitoring_cb);
}


Expand Down
15 changes: 5 additions & 10 deletions src/libmongoc/tests/test-mongoc-connection-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,11 @@ test_connection_uri_cb (bson_t *scenario)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (JSON_DIR "/uri-options", resolved);
install_json_test_suite (suite, resolved, &test_connection_uri_cb);

test_framework_resolve_path (JSON_DIR "/connection_uri", resolved);
install_json_test_suite (suite, resolved, &test_connection_uri_cb);

test_framework_resolve_path (JSON_DIR "/auth", resolved);
install_json_test_suite (suite, resolved, &test_connection_uri_cb);
install_json_test_suite (
suite, JSON_DIR, "uri-options", &test_connection_uri_cb);
install_json_test_suite (
suite, JSON_DIR, "connection_uri", &test_connection_uri_cb);
install_json_test_suite (suite, JSON_DIR, "auth", &test_connection_uri_cb);
}


Expand Down
17 changes: 7 additions & 10 deletions src/libmongoc/tests/test-mongoc-crud.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,19 @@ test_crud_cb (bson_t *scenario)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (JSON_DIR "/crud/legacy", resolved);

install_json_test_suite_with_check (suite,
resolved,
JSON_DIR,
"crud/legacy",
&test_crud_cb,
test_framework_skip_if_no_crypto,
TestSuite_CheckLive);

/* Read/write concern spec tests use the same format. */
test_framework_resolve_path (JSON_DIR "/read_write_concern/operation",
resolved);

install_json_test_suite_with_check (
suite, resolved, &test_crud_cb, TestSuite_CheckLive);
install_json_test_suite_with_check (suite,
JSON_DIR,
"read_write_concern/operation",
&test_crud_cb,
TestSuite_CheckLive);
}

static void
Expand Down
39 changes: 18 additions & 21 deletions src/libmongoc/tests/test-mongoc-dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,29 +420,26 @@ test_null_error_pointer (void *ctx)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (
JSON_DIR "/initial_dns_seedlist_discovery/replica-set", resolved);
install_json_test_suite_with_check (suite,
resolved,
test_dns,
test_dns_check_replset,
test_framework_skip_if_no_crypto);

test_framework_resolve_path (
JSON_DIR "/initial_dns_seedlist_discovery/load-balanced", resolved);
install_json_test_suite_with_check (suite,
resolved,
test_dns,
test_dns_check_loadbalanced,
test_framework_skip_if_no_crypto);

test_framework_resolve_path (
JSON_DIR "/initial_dns_seedlist_discovery/sharded", resolved);
install_json_test_suite_with_check (
suite,
resolved,
JSON_DIR,
"initial_dns_seedlist_discovery/replica-set",
test_dns,
test_dns_check_replset,
test_framework_skip_if_no_crypto);

install_json_test_suite_with_check (
suite,
JSON_DIR,
"initial_dns_seedlist_discovery/load-balanced",
test_dns,
test_dns_check_loadbalanced,
test_framework_skip_if_no_crypto);

install_json_test_suite_with_check (
suite,
JSON_DIR,
"/initial_dns_seedlist_discovery/sharded",
test_dns,
/* Topology of load-balancer tests satisfy topology requirements of
* sharded tests, even though a load balancer is not required. */
Expand Down
5 changes: 1 addition & 4 deletions src/libmongoc/tests/test-mongoc-gridfs-bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,7 @@ test_gridfs_cb (bson_t *scenario)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (JSON_DIR "/gridfs", resolved);
install_json_test_suite (suite, resolved, &test_gridfs_cb);
install_json_test_suite (suite, JSON_DIR, "gridfs", &test_gridfs_cb);
}

static void
Expand Down
6 changes: 2 additions & 4 deletions src/libmongoc/tests/test-mongoc-max-staleness.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,8 @@ test_last_write_date_absent_pooled (void *ctx)
static void
test_all_spec_tests (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (JSON_DIR "/max_staleness", resolved);
install_json_test_suite (suite, resolved, &test_server_selection_logic_cb);
install_json_test_suite (
suite, JSON_DIR, "max_staleness", &test_server_selection_logic_cb);
}

void
Expand Down
7 changes: 2 additions & 5 deletions src/libmongoc/tests/test-mongoc-mongohouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,9 @@ test_mongohouse_no_auth ()
void
test_mongohouse_install (TestSuite *suite)
{
char resolved[PATH_MAX];

test_framework_resolve_path (JSON_DIR "/mongohouse", resolved);

install_json_test_suite_with_check (suite,
resolved,
JSON_DIR,
"mongohouse",
&test_mongohouse_cb,
test_framework_skip_if_no_mongohouse);

Expand Down
17 changes: 8 additions & 9 deletions src/libmongoc/tests/test-mongoc-read-write-concern.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ test_rw_concern_document (bson_t *scenario)
void
test_read_write_concern_install (TestSuite *suite)
{
char resolved[PATH_MAX];

ASSERT (
realpath (JSON_DIR "/read_write_concern/connection-string", resolved));
install_json_test_suite (suite, resolved, &test_rw_concern_uri);

test_framework_resolve_path (JSON_DIR "/read_write_concern/document",
resolved);
install_json_test_suite (suite, resolved, &test_rw_concern_document);
install_json_test_suite (suite,
JSON_DIR,
"read_write_concern/connection-string",
&test_rw_concern_uri);
install_json_test_suite (suite,
JSON_DIR,
"read_write_concern/document",
&test_rw_concern_document);
}
Loading