merge with master

This commit is contained in:
ado
2021-01-21 01:54:20 +01:00
18 changed files with 330 additions and 6306 deletions

37
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.14)
project(ssp_tests CXX)
# ---- Dependencies ----
set(
ssp_INCLUDE_WITHOUT_SYSTEM
YES
CACHE
INTERNAL
"Turn the warning guard off to have errors appear in test builds"
)
include(FetchContent)
FetchContent_Declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
FetchContent_MakeAvailable(ssp)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(ssp INTERFACE -Wall -Wextra)
endif()
find_package(doctest 2.4.4 CONFIG REQUIRED)
# for doctest_discover_tests
include(doctest)
# ---- Test ----
enable_testing()
foreach(name IN ITEMS test_splitter test_parser test_converter test_extractions)
add_executable("${name}" "${name}.cpp")
target_link_libraries("${name}" PRIVATE ssp::ssp doctest::doctest)
target_compile_definitions("${name}" PRIVATE
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI)
doctest_discover_tests("${name}")
endforeach()

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +0,0 @@
CXX=g++
CXXFLAGS=-Wall -Wextra -std=c++17 -lstdc++fs
TESTS=test_parser test_converter test_extractions test_splitter
all: $(TESTS)
# pattern rule, replacing built-in implicit .cpp-suffix rule
%: %.cpp
$(CXX) $(CXXFLAGS) $< -o $@
debug: CXXFLAGS += -g
debug: all
clean:
@$(RM) -fv $(TESTS)
@$(RM) *.csv
test:
@for i in $(TESTS); do \
./$$i; \
done
# don't use any implicit rules
.SUFFIXES:
# these rules won't actually build the targets they're named after
.PHONY: all clean run debug

19
test/meson.build Normal file
View File

@@ -0,0 +1,19 @@
test_sources = files([
'test_main.cpp',
'test_splitter.cpp',
'test_converter.cpp',
'test_parser.cpp',
'test_extractions.cpp',
])
doctest_proj = subproject('doctest')
doctest_dep = doctest_proj.get_variable('doctest_dep')
test_exe = executable('test_ssp',
sources: test_sources,
dependencies: doctest_dep,
include_directories: includes,
cpp_args: '-lstdc++fs'
)
test('tests_ssp', test_exe)

View File

@@ -1,8 +1,11 @@
#include <iostream>
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../include/ss/converter.hpp"
#include "doctest.h"
#include <algorithm>
#include <ss/converter.hpp>
#ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h>
#else
#include <doctest.h>
#endif
class buffer {
constexpr static auto buff_size = 1024;
@@ -83,17 +86,17 @@ TEST_CASE("testing valid conversions") {
{
auto tup = c.convert<int, double, void>(buff("5,6.6,junk"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{5, 6.6});
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup = c.convert<int, void, double>(buff("5,junk,6.6"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{5, 6.6});
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup = c.convert<void, int, double>(buff("junk;5;6.6"), ";");
REQUIRE(c.valid());
CHECK(tup == std::tuple{5, 6.6});
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup =
@@ -101,7 +104,7 @@ TEST_CASE("testing valid conversions") {
";");
REQUIRE(c.valid());
REQUIRE(std::get<0>(tup).has_value());
CHECK(tup == std::tuple{5, 6.6});
CHECK(tup == std::make_tuple(5, 6.6));
}
{
auto tup =
@@ -109,21 +112,21 @@ TEST_CASE("testing valid conversions") {
";");
REQUIRE(c.valid());
REQUIRE(!std::get<0>(tup).has_value());
CHECK(tup == std::tuple{std::nullopt, 6.6});
CHECK(tup == std::make_tuple(std::optional<int>{}, 6.6));
}
{
auto tup = c.convert<void, std::variant<int, double>,
double>(buff("junk;5;6.6"), ";");
REQUIRE(c.valid());
REQUIRE(std::holds_alternative<int>(std::get<0>(tup)));
CHECK(tup == std::tuple{std::variant<int, double>{5}, 6.6});
CHECK(tup == std::make_tuple(std::variant<int, double>{5}, 6.6));
}
{
auto tup = c.convert<void, std::variant<int, double>,
double>(buff("junk;5.5;6.6"), ";");
REQUIRE(c.valid());
REQUIRE(std::holds_alternative<double>(std::get<0>(tup)));
CHECK(tup == std::tuple{std::variant<int, double>{5.5}, 6.6});
CHECK(tup == std::make_tuple(std::variant<int, double>{5.5}, 6.6));
}
}
@@ -182,13 +185,13 @@ TEST_CASE("testing ss:ax restriction (all except)") {
std::tuple<char, int> tup =
c.convert<char, ss::ax<int, 1>>(buff("c,3"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{'c', 3});
CHECK(tup == std::make_tuple('c', 3));
}
{
std::tuple<int, char> tup =
c.convert<ss::ax<int, 1>, char>(buff("3,c"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{3, 'c'});
CHECK(tup == std::make_tuple(3, 'c'));
}
}
@@ -218,12 +221,12 @@ TEST_CASE("testing ss:nx restriction (none except)") {
auto tup =
c.convert<char, void, ss::nx<int, 0, 1, 2>>(buff("c,junk,1"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{'c', 1});
CHECK(tup == std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::nx<int, 1>, char>(buff("1,c"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{1, 'c'});
CHECK(tup == std::make_tuple(1, 'c'));
}
}
@@ -252,12 +255,12 @@ TEST_CASE("testing ss:ir restriction (in range)") {
{
auto tup = c.convert<char, void, ss::ir<int, 0, 1>>(buff("c,junk,1"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{'c', 1});
CHECK(tup == std::make_tuple('c', 1));
}
{
auto tup = c.convert<ss::ir<int, 1, 20>, char>(buff("1,c"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{1, 'c'});
CHECK(tup == std::make_tuple(1, 'c'));
}
}
@@ -285,13 +288,13 @@ TEST_CASE("testing ss:oor restriction (out of range)") {
{
auto tup = c.convert<char, void, ss::oor<int, 4, 69>>(buff("c,junk,3"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{'c', 3});
CHECK(tup == std::make_tuple('c', 3));
}
{
auto tup = c.convert<ss::oor<int, 1, 2>, char>(buff("3,c"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{3, 'c'});
CHECK(tup == std::make_tuple(3, 'c'));
}
}
@@ -335,7 +338,7 @@ TEST_CASE("testing ss:ne restriction (not empty)") {
auto tup =
c.convert<std::optional<int>, ss::ne<std::string>>(buff("1,s"));
REQUIRE(c.valid());
CHECK(tup == std::tuple{1, "s"});
CHECK(tup == std::make_tuple(1, "s"));
}
{
auto tup = c.convert<ss::ne<std::vector<int>>>(buff("{1 2 3}"));

View File

@@ -1,8 +1,12 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../include/ss/extract.hpp"
#include "doctest.h"
#include <ss/extract.hpp>
#include <algorithm>
#ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h>
#else
#include <doctest.h>
#endif
constexpr auto eps = 0.000001;
using ld = long double;

2
test/test_main.cpp Normal file
View File

@@ -0,0 +1,2 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>

View File

@@ -1,18 +1,20 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../include/ss/parser.hpp"
#include "doctest.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <ss/parser.hpp>
#ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h>
#else
#include <doctest.h>
#endif
struct unique_file_name {
const std::string name;
unique_file_name() : name{std::tmpnam(nullptr)} {
}
unique_file_name() : name{std::tmpnam(nullptr)} {}
~unique_file_name() {
std::filesystem::remove(name);
}
~unique_file_name() { std::filesystem::remove(name); }
};
struct X {
@@ -28,9 +30,7 @@ struct X {
.append(delim)
.append(s);
}
auto tied() const {
return std::tie(i, d, s);
}
auto tied() const { return std::tie(i, d, s); }
};
template <typename T>
@@ -167,13 +167,10 @@ struct test_struct {
int i;
double d;
char c;
auto tied() {
return std::tie(i, d, c);
}
auto tied() { return std::tie(i, d, c); }
};
void expect_test_struct(const test_struct&) {
}
void expect_test_struct(const test_struct&) {}
// various scenarios
TEST_CASE("testing composite conversion") {
@@ -395,9 +392,7 @@ struct my_string {
my_string() = default;
~my_string() {
delete[] data;
}
~my_string() { delete[] data; }
// make sure no object is copied
my_string(const my_string&) = delete;
@@ -428,9 +423,7 @@ struct xyz {
my_string x;
my_string y;
my_string z;
auto tied() {
return std::tie(x, y, z);
}
auto tied() { return std::tie(x, y, z); }
};
TEST_CASE("testing the moving of parsed values") {