Skip to content

Commit 341783a

Browse files
committed
test(doc-links): read index_status's doc_links block up to the next key
index_status now ends with a watch object (DeusData#2167) whose hint names index_repository. The checks searched from doc_links: to the end of the text, so the watch hint failed the no-hint check and could have satisfied the hint and index_repository checks of the error cases. dm_doc_links_block cuts the text at the next top-level key. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 8207f8a commit 341783a

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎tests/test_doc_mentions.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static bool dm_namespace_published(const char *db, const char *project, bool val
327327
dm_row(db, "Healthy.cs", "Hidden", conflict_reason, sizeof(conflict_reason), NULL, 0);
328328
int errors = dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'");
329329
char *status = dm_index_status(project, false);
330-
const char *block = status ? strstr(status, "doc_links:\n") : NULL;
330+
const char *block = dm_doc_links_block(status);
331331
bool status_ok = block && strstr(block, "\n status: ok");
332332
int from_bad = dm_mentions_from(db, "Bad.FromBad");
333333
bool inside_ok = valid
@@ -687,7 +687,7 @@ static bool dm_control_published(const char *db, const char *project, const char
687687
dm_row(db, "Healthy.cs", "Hidden", conflict_reason, sizeof(conflict_reason), NULL, 0);
688688
int errors = dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'");
689689
char *status = dm_index_status(project, false);
690-
const char *block = status ? strstr(status, "doc_links:\n") : NULL;
690+
const char *block = dm_doc_links_block(status);
691691
bool status_ok = block && strstr(block, "\n status: ok");
692692
bool correct = healthy == 1 && tail == 1 && !tail_reason[0] && conflict == 0 &&
693693
strcmp(conflict_reason, "graph_gap") == 0 && errors == 0 && status_ok;
@@ -4356,7 +4356,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
43564356
/* doc_links: the edge count, every reason with its row count, the status */
43574357
char *text = dm_index_status(project, false);
43584358
ASSERT_NOT_NULL(text);
4359-
const char *block = strstr(text, "doc_links:\n");
4359+
const char *block = dm_doc_links_block(text);
43604360
ASSERT_NOT_NULL(block);
43614361
char want[64];
43624362
snprintf(want, sizeof(want), "\n mentions: %d\n", edges);
@@ -4371,7 +4371,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
43714371
free(text);
43724372
text = dm_index_status(project, true);
43734373
ASSERT_NOT_NULL(text);
4374-
block = strstr(text, "doc_links:\n");
4374+
block = dm_doc_links_block(text);
43754375
ASSERT_NOT_NULL(block);
43764376
ASSERT_NOT_NULL(strstr(block, "samples"));
43774377
ASSERT_NOT_NULL(strstr(block, "TestOnlyThing"));
@@ -4389,7 +4389,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
43894389
ASSERT_EQ(dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'"), 1);
43904390
text = dm_index_status(project, false);
43914391
ASSERT_NOT_NULL(text);
4392-
block = strstr(text, "doc_links:\n");
4392+
block = dm_doc_links_block(text);
43934393
ASSERT_NOT_NULL(block);
43944394
ASSERT_NOT_NULL(strstr(block, "\n mentions: 0\n"));
43954395
ASSERT_NOT_NULL(strstr(block, "\n status: error"));
@@ -4421,7 +4421,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
44214421
cbm_store_close(s);
44224422
text = dm_index_status(project, true);
44234423
ASSERT_NOT_NULL(text);
4424-
block = strstr(text, "doc_links:\n");
4424+
block = dm_doc_links_block(text);
44254425
ASSERT_NOT_NULL(block);
44264426
ASSERT_NOT_NULL(strstr(block, "\n status: error"));
44274427
ASSERT_NOT_NULL(strstr(block, "hint"));
@@ -4447,7 +4447,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
44474447
sqlite3_close(h);
44484448
text = dm_index_status(project, false);
44494449
ASSERT_NOT_NULL(text);
4450-
block = strstr(text, "doc_links:\n");
4450+
block = dm_doc_links_block(text);
44514451
ASSERT_NOT_NULL(block);
44524452
ASSERT_NOT_NULL(strstr(block, "\n status: error"));
44534453
ASSERT_NOT_NULL(strstr(block, "predates"));
@@ -4458,7 +4458,7 @@ static int dm_index_status_checks(const char *tmp, const char *repo, const char
44584458
ASSERT_GT(dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved"), rows_before);
44594459
text = dm_index_status(project, false);
44604460
ASSERT_NOT_NULL(text);
4461-
block = strstr(text, "doc_links:\n");
4461+
block = dm_doc_links_block(text);
44624462
ASSERT_NOT_NULL(block);
44634463
ASSERT_NOT_NULL(strstr(block, "\n status: ok"));
44644464
free(text);

‎tests/test_doc_mentions_helpers.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ static inline char *dm_index_status(const char *project, bool full) {
382382
return text;
383383
}
384384

385+
/* The doc_links block of an index_status text, cut at the next top-level key
386+
* (the watch object follows it), so an assertion on the block never matches
387+
* another block's lines. Truncates text in place; NULL when absent. */
388+
static inline const char *dm_doc_links_block(char *text) {
389+
char *block = text ? strstr(text, "doc_links:\n") : NULL;
390+
for (char *p = block ? strchr(block, '\n') : NULL; p && p[1]; p = strchr(p + 1, '\n')) {
391+
if (p[1] != ' ') {
392+
p[1] = '\0';
393+
break;
394+
}
395+
}
396+
return block;
397+
}
398+
385399
/* Every reason the table holds is listed under doc_links.unresolved with its
386400
* row count. The number of reasons checked; -1 when a line is missing. */
387401
static inline int dm_reason_lines(const char *db, const char *block) {

0 commit comments

Comments
 (0)