Skip to content

Commit

Permalink
Cleaning up tests (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
hummeltech authored Mar 28, 2024
1 parent 7f91d53 commit 0cc76cb
Show file tree
Hide file tree
Showing 13 changed files with 2,865 additions and 858 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ render_old_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS) $(INIPARSER_LDFLAGS)
#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c

noinst_LIBRARIES = catch_main.o catch_test_common.o
catch_main_o_SOURCES = tests/catch/catch_main.cpp
catch_test_common_o_SOURCES = tests/catch/catch_test_common.cpp
catch_main_o_SOURCES = tests/catch_main.cpp
catch_test_common_o_SOURCES = tests/catch_test_common.cpp

gen_tile_test_SOURCES = \
tests/gen_tile_test.cpp \
Expand Down
8 changes: 5 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,8 @@ endforeach()
#-----------------------------------------------------------------------------

add_library(catch_main_o OBJECT
catch/catch_main.cpp
${PROJECT_SOURCE_DIR}/tests/catch/catch_test_common.cpp
${PROJECT_SOURCE_DIR}/tests/catch_main.cpp
${PROJECT_SOURCE_DIR}/tests/catch_test_common.cpp
)
target_include_directories(catch_main_o PRIVATE ${GLIB_INCLUDE_DIRS})

Expand All @@ -1147,7 +1147,9 @@ target_include_directories(catch_main_o PRIVATE ${GLIB_INCLUDE_DIRS})
#
#-----------------------------------------------------------------------------

add_library(catch_test_common_o OBJECT ${PROJECT_SOURCE_DIR}/tests/catch/catch_test_common.cpp)
add_library(catch_test_common_o OBJECT
${PROJECT_SOURCE_DIR}/tests/catch_test_common.cpp
)
target_include_directories(catch_test_common_o PRIVATE ${GLIB_INCLUDE_DIRS})

#-----------------------------------------------------------------------------
Expand Down
25 changes: 1 addition & 24 deletions tests/catch/catch_main.cpp → tests/catch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,7 @@

#define CATCH_CONFIG_MAIN

#include "catch.hpp"
#include "catch/catch.hpp"
#include "catch_test_common.hpp"

int foreground = 1;

struct CaptureListener : Catch::TestEventListenerBase {

using TestEventListenerBase::TestEventListenerBase;

void testCaseStarting(Catch::TestCaseInfo const &testCaseInfo) override
{
start_capture();
}

void testCaseEnded(Catch::TestCaseStats const &testCaseStats) override
{
bool print = false;

if (testCaseStats.totals.assertions.failed > 0) {
print = true;
}

end_capture(print);
}
};

CATCH_REGISTER_LISTENER(CaptureListener)
32 changes: 32 additions & 0 deletions tests/catch/catch_test_common.cpp → tests/catch_test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,44 @@
#include <unistd.h>

#include "catch_test_common.hpp"
#include "pstreams/pstream.hpp"

extern int foreground;

std::string err_log_lines, out_log_lines;

captured_stdio captured_stderr;
captured_stdio captured_stdout;

int run_command(std::string file, std::vector<std::string> argv, std::string input)
{
auto mode = redi::pstreams::pstdout | redi::pstreams::pstderr | redi::pstreams::pstdin;

argv.insert(argv.begin(), file);

redi::pstream proc(file, argv, mode);

std::string line;
err_log_lines = "";
out_log_lines = "";

if (!input.empty()) {
proc << input << redi::peof;
}

while (std::getline(proc.err(), line)) {
err_log_lines += line;
}

proc.clear();

while (std::getline(proc.out(), line)) {
out_log_lines += line;
}

return proc.close();
}

std::string read_stderr(int buffer_size)
{
char buffer[buffer_size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <string>
#include <vector>

#ifndef CATCH_TEST_COMMON_HPP
#define CATCH_TEST_COMMON_HPP
Expand All @@ -37,4 +38,6 @@ std::string get_captured_stdout(bool print = false);
void start_capture(bool debug = false);
std::tuple<std::string, std::string> end_capture(bool print = false);

int run_command(std::string file, std::vector<std::string> argv = {}, std::string input = "");

#endif
4 changes: 1 addition & 3 deletions tests/gen_tile_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include <cstdio>
#include <glib.h>
#include <iostream>
#include <limits.h>
#include <mapnik/version.hpp>
#include <math.h>
#include <pthread.h>
Expand All @@ -37,7 +35,7 @@
#include <unistd.h>

#include "catch/catch.hpp"
#include "catch/catch_test_common.hpp"
#include "catch_test_common.hpp"
#include "config.h"
#include "g_logger.h"
#include "gen_tile.h"
Expand Down
Loading

0 comments on commit 0cc76cb

Please sign in to comment.