Test error output in catch tests (#419)

This commit is contained in:
Hummeltech
2024-03-23 21:58:30 -07:00
committed by GitHub
parent 743cf651b1
commit 2ce51df526
12 changed files with 989 additions and 497 deletions

View File

@ -16,10 +16,10 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "catch/catch.hpp"
#include "catch/catch_test_common.hpp"
#include "config.h"
#include "render_config.h"
@ -32,10 +32,12 @@
#endif
#ifndef RENDERD_CONF
#define RENDERD_CONF "./etc/renderd/renderd.conf"
#define RENDERD_CONF "./etc/renderd/renderd.conf.examples"
#endif
std::string test_binary = (std::string)PROJECT_BINARY_DIR + "/" + "render_expired";
int found;
std::string err_log_lines;
TEST_CASE("render_expired common", "common testing")
{
@ -85,83 +87,59 @@ TEST_CASE("render_expired common", "common testing")
}
SECTION("--config invalid file", "should return 1") {
std::string option = "--config /path/is/invalid";
std::string renderd_conf = "/path/is/invalid";
std::string option = "--config " + renderd_conf;
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("Config file '" + renderd_conf + "' does not exist, please specify a valid file");
REQUIRE(found > -1);
}
}
TEST_CASE("render_expired specific", "specific testing")
{
SECTION("--num-threads subceeds minimum of 1", "should return 1") {
std::string option = "--num-threads 0";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--min-zoom/--max-zoom exceeds maximum of MAX_ZOOM", "should return 1") {
std::string option = GENERATE("--max-zoom", "--min-zoom");
std::string command = test_binary + " " + option + " " + std::to_string(MAX_ZOOM + 1);
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--min-zoom exceeds --max-zoom", "should return 1") {
std::string option = "--max-zoom " + std::to_string(MAX_ZOOM - 2) + " --min-zoom " + std::to_string(MAX_ZOOM - 1);
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--config without maps", "should return 1") {
std::string option = "--config " + (std::string)RENDERD_CONF;
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("--config with invalid --map", "should return 1") {
std::string renderd_conf_examples = (std::string)RENDERD_CONF + ".examples";
std::string option = "--config " + renderd_conf_examples + " --map invalid";
std::string renderd_conf = (std::string)RENDERD_CONF;
std::string option = "--config " + renderd_conf + " --map invalid";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("Map section 'invalid' does not exist in config file '" + renderd_conf + "'.");
REQUIRE(found > -1);
}
SECTION("--config with valid --map and --tile-dir with invalid path", "should return 1") {
std::string renderd_conf_examples = (std::string)RENDERD_CONF + ".examples";
std::string option = "--config " + renderd_conf_examples + " --map example-map --tile-dir /path/is/invalid";
std::string renderd_conf = (std::string)RENDERD_CONF;
std::string option = "--config " + renderd_conf + " --map example-map --tile-dir /path/is/invalid";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("init_storage_backend: Failed to stat /path/is/invalid with error: No such file or directory");
REQUIRE(found > -1);
found = err_log_lines.find("Failed to initialise storage backend /path/is/invalid");
REQUIRE(found > -1);
}
SECTION("--config with valid --map, --verbose and bad input lines", "should return 0") {
std::string renderd_conf_examples = (std::string)RENDERD_CONF + ".examples";
std::string option = "--config " + renderd_conf_examples + " --map example-map --tile-dir " + P_tmpdir + " --verbose";
std::string renderd_conf = (std::string)RENDERD_CONF;
std::string option = "--config " + renderd_conf + " --map example-map --tile-dir " + P_tmpdir + " --verbose";
std::string command = test_binary + " " + option;
// flawfinder: ignore
@ -170,6 +148,12 @@ TEST_CASE("render_expired specific", "specific testing")
fputs("x y z\n", pipe);
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
err_log_lines = read_stderr();
found = err_log_lines.find("bad line 0: z/x/y");
REQUIRE(found > -1);
found = err_log_lines.find("bad line 0: x y z");
REQUIRE(found > -1);
}
SECTION("--tile-dir with invalid option", "should return 1") {
@ -180,6 +164,12 @@ TEST_CASE("render_expired specific", "specific testing")
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("init_storage_backend: No valid storage backend found for options: invalid");
REQUIRE(found > -1);
found = err_log_lines.find("Failed to initialise storage backend invalid");
REQUIRE(found > -1);
}
SECTION("--tile-dir with invalid path", "should return 1") {
@ -190,6 +180,54 @@ TEST_CASE("render_expired specific", "specific testing")
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("init_storage_backend: Failed to stat /path/is/invalid with error: No such file or directory");
REQUIRE(found > -1);
found = err_log_lines.find("Failed to initialise storage backend /path/is/invalid");
REQUIRE(found > -1);
}
SECTION("--num-threads subceeds minimum of 1", "should return 1") {
std::string option = "--num-threads 0";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("Invalid number of threads, must be >= 1 (0 was provided)");
REQUIRE(found > -1);
}
SECTION("--min-zoom/--max-zoom exceeds maximum of MAX_ZOOM", "should return 1") {
std::string option = GENERATE("--max-zoom", "--min-zoom");
std::string command = test_binary + " " + option + " " + std::to_string(MAX_ZOOM + 1);
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("zoom, must be <= 20 (21 was provided)");
REQUIRE(found > -1);
}
SECTION("--min-zoom exceeds --max-zoom", "should return 1") {
std::string option = "--max-zoom 1 --min-zoom 2";
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
err_log_lines = read_stderr();
found = err_log_lines.find("Specified min zoom (2) is larger than max zoom (1).");
REQUIRE(found > -1);
}
}
@ -197,7 +235,7 @@ TEST_CASE("render_expired min/max int generator", "min/max int generator testing
{
std::string option = GENERATE("--delete-from", "--max-load", "--max-zoom", "--min-zoom", "--num-threads", "--touch-from");
SECTION("option is positive with --help", "should return 0") {
SECTION(option + " option is positive with --help", "should return 0") {
std::string command = test_binary + " " + option + " 1 --help";
// flawfinder: ignore
@ -205,31 +243,4 @@ TEST_CASE("render_expired min/max int generator", "min/max int generator testing
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("option is negative", "should return 1") {
std::string command = test_binary + " " + option + " -1";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is float", "should return 1") {
std::string command = test_binary + " " + option + " 1.23456789";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
SECTION("option is not an integer", "should return 1") {
std::string command = test_binary + " " + option + " invalid";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 1);
}
}