Skip to content

Commit

Permalink
Merge pull request #367 from BartlomiejZalas/issue-276/empty-links-sh…
Browse files Browse the repository at this point in the history
…ould-not-be-errors
  • Loading branch information
mgautierfr authored Aug 21, 2023
2 parents 7b98129 + 17b718a commit 16ee85d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/zimcheck/checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ std::unordered_map<TestType, std::pair<LogTag, std::string>> errormapping = {
{ TestType::REDUNDANT, {LogTag::WARNING, "Redundant data found"}},
{ TestType::URL_INTERNAL, {LogTag::ERROR, "Invalid internal links found"}},
{ TestType::URL_EXTERNAL, {LogTag::ERROR, "Invalid external links found"}},
{ TestType::URL_EMPTY, {LogTag::WARNING, "Empty links found"}},
{ TestType::REDIRECT, {LogTag::ERROR, "Redirect loop(s) exist"}},
};

Expand All @@ -70,9 +71,9 @@ std::unordered_map<MsgId, MsgInfo> msgTable = {
{ MsgId::MAIN_PAGE, { TestType::MAIN_PAGE, "Main Page Index stored in Archive Header: {{&main_page_index}}" } },
{ MsgId::EMPTY_ENTRY, { TestType::EMPTY, "Entry {{&path}} is empty" } },
{ MsgId::OUTOFBOUNDS_LINK, { TestType::URL_INTERNAL, "{{&link}} is out of bounds. Article: {{&path}}" } },
{ MsgId::EMPTY_LINKS, { TestType::URL_INTERNAL, "Found {{&count}} empty links in article: {{&path}}" } },
{ MsgId::DANGLING_LINKS, { TestType::URL_INTERNAL, "The following links:\n{{#links}}- {{&value}}\n{{/links}}({{&normalized_link}}) were not found in article {{&path}}" } },
{ MsgId::EXTERNAL_LINK, { TestType::URL_EXTERNAL, "{{&link}} is an external dependence in article {{&path}}" } },
{ MsgId::EMPTY_LINKS, { TestType::URL_EMPTY, "Found {{&count}} empty links in article: {{&path}}" } },
{ MsgId::REDUNDANT_ITEMS, { TestType::REDUNDANT, "{{&path1}} and {{&path2}}" } },
{ MsgId::METADATA, { TestType::METADATA, "{{&error}}" } },
{ MsgId::REDIRECT_LOOP, { TestType::REDIRECT, "Redirect loop exists from entry {{&entry_path}}\n" } },
Expand Down Expand Up @@ -100,6 +101,7 @@ const char* toStr(TestType tt) {
case TestType::REDUNDANT: return "redundant";
case TestType::URL_INTERNAL: return "url_internal";
case TestType::URL_EXTERNAL: return "url_external";
case TestType::URL_EMPTY: return "url_empty";
case TestType::REDIRECT: return "redirect";
default: throw std::logic_error("Invalid TestType");
};
Expand Down
1 change: 1 addition & 0 deletions src/zimcheck/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class TestType {
REDUNDANT,
URL_INTERNAL,
URL_EXTERNAL,
URL_EMPTY,
REDIRECT,

COUNT
Expand Down
22 changes: 13 additions & 9 deletions test/zimcheck-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ TEST(zimcheck, json_goodzimfile)
" \"redundant\"," "\n"
" \"url_internal\"," "\n"
" \"url_external\"," "\n"
" \"url_empty\"," "\n"
" \"redirect\"" "\n"
" ]," "\n"
" \"file_name\" : \"data/zimfiles/good.zim\"," "\n"
Expand Down Expand Up @@ -620,8 +621,9 @@ TEST(zimcheck, internal_url_check_poorzimfile)
" The following links:" "\n"
"- A/non_existent.html" "\n"
"(A/non_existent.html) were not found in article dangling_link.html" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
" ../../oops.html is out of bounds. Article: outofbounds_link.html" "\n"
"[WARNING] Empty links found:" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
"[INFO] Overall Test Status: Fail" "\n"
"[INFO] Total time taken by zimcheck: <3 seconds." "\n"
);
Expand Down Expand Up @@ -737,12 +739,13 @@ const std::string ALL_CHECKS_OUTPUT_ON_POORZIMFILE(
" The following links:" "\n"
"- A/non_existent.html" "\n"
"(A/non_existent.html) were not found in article dangling_link.html" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
" ../../oops.html is out of bounds. Article: outofbounds_link.html" "\n"
"[ERROR] Invalid external links found:" "\n"
" http://a.io/pic.png is an external dependence in article external_image_http.html" "\n"
" https://a.io/pic.png is an external dependence in article external_image_https.html" "\n"
" //a.io/pic.png is an external dependence in article external_image_protocol_relative.html" "\n"
"[WARNING] Empty links found:" "\n"
" Found 1 empty links in article: empty_link.html" "\n"
"[ERROR] Redirect loop(s) exist:" "\n"
" Redirect loop exists from entry redirect_loop.html" "\n"
"" "\n"
Expand Down Expand Up @@ -823,6 +826,7 @@ TEST(zimcheck, json_poorzimfile)
" \"redundant\"," "\n"
" \"url_internal\"," "\n"
" \"url_external\"," "\n"
" \"url_empty\"," "\n"
" \"redirect\"" "\n"
" ]," "\n"
" \"file_name\" : \"data/zimfiles/poor.zim\"," "\n"
Expand Down Expand Up @@ -896,13 +900,6 @@ TEST(zimcheck, json_poorzimfile)
" {" "\n"
" \"check\" : \"url_internal\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Found 1 empty links in article: empty_link.html\"," "\n"
" \"count\" : \"1\"," "\n"
" \"path\" : \"empty_link.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_internal\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"../../oops.html is out of bounds. Article: outofbounds_link.html\"," "\n"
" \"link\" : \"../../oops.html\"," "\n"
" \"path\" : \"outofbounds_link.html\"" "\n"
Expand All @@ -929,6 +926,13 @@ TEST(zimcheck, json_poorzimfile)
" \"path\" : \"external_image_protocol_relative.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"url_empty\"," "\n"
" \"level\" : \"WARNING\"," "\n"
" \"message\" : \"Found 1 empty links in article: empty_link.html\"," "\n"
" \"count\" : \"1\"," "\n"
" \"path\" : \"empty_link.html\"" "\n"
" }," "\n"
" {" "\n"
" \"check\" : \"redirect\"," "\n"
" \"level\" : \"ERROR\"," "\n"
" \"message\" : \"Redirect loop exists from entry redirect_loop.html\\n\"," "\n"
Expand Down

0 comments on commit 16ee85d

Please sign in to comment.