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"
#ifdef __FreeBSD__
@ -30,11 +30,9 @@
#define PROJECT_BINARY_DIR "."
#endif
#ifndef RENDERD_CONF
#define RENDERD_CONF "./etc/renderd/renderd.conf"
#endif
std::string test_binary = (std::string)PROJECT_BINARY_DIR + "/" + "renderd";
int found;
std::string err_log_lines;
TEST_CASE("renderd common", "common testing")
{
@ -84,25 +82,44 @@ TEST_CASE("renderd common", "common testing")
}
SECTION("--config invalid file", "should return 1") {
std::string option = "--config /path/is/invalid";
std::string command = test_binary + " " + option;
std::string renderd_conf = "/path/is/invalid";
std::string option = "--config " + renderd_conf;
std::string command = test_binary + " --foreground " + 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("renderd specific", "specific testing")
{
std::string option = "--slave";
SECTION("--slave is positive with --help", "should return 0") {
std::string command = test_binary + " --foreground " + option + " 1 --help";
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
REQUIRE(WEXITSTATUS(status) == 0);
}
SECTION("--slave subceeds minimum of 0", "should return 1") {
std::string option = "--slave -1";
std::string command = test_binary + " " + option;
std::string command = test_binary + " --foreground " + option + " -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("must be >= 0 (-1 was provided)");
REQUIRE(found > -1);
}
}