Merge pull request #4 from red0124/feature/meson

add meson support, update pipeline
This commit is contained in:
red0124 2021-01-21 01:49:39 +01:00 committed by GitHub
commit fe00b99ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 77 additions and 42 deletions

View File

@ -4,11 +4,12 @@ on:
push: push:
branches: branches:
- master - master
- testing - /^feature/$/
pull_request: pull_request:
branches: branches:
- master - master
- /^feature/$/
jobs: jobs:
clang_tests: clang_tests:

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
compile_commands.json compile_commands.json
.clang-format .clang-format
experiment/ experiment/
build/
subprojects/*
!subprojects/*.wrap

View File

@ -9,9 +9,9 @@
#include <vector> #include <vector>
namespace ss { namespace ss {
INIT_HAS_METHOD(tied); INIT_HAS_METHOD(tied)
INIT_HAS_METHOD(ss_valid); INIT_HAS_METHOD(ss_valid)
INIT_HAS_METHOD(error); INIT_HAS_METHOD(error)
//////////////// ////////////////
// replace validator // replace validator
@ -147,7 +147,7 @@ public:
no_void_validator_tup_t<T, Ts...> convert(const split_input& elems) { no_void_validator_tup_t<T, Ts...> convert(const split_input& elems) {
if constexpr (sizeof...(Ts) == 0 && if constexpr (sizeof...(Ts) == 0 &&
is_instance_of<T, std::tuple>::value) { is_instance_of<T, std::tuple>::value) {
return convert_impl(elems, (T*){}); return convert_impl(elems, static_cast<T*>(nullptr));
} else if constexpr (tied_class_v<T, Ts...>) { } else if constexpr (tied_class_v<T, Ts...>) {
using arg_ref_tuple = using arg_ref_tuple =
@ -156,7 +156,8 @@ public:
using arg_tuple = using arg_tuple =
typename apply_trait<std::decay, arg_ref_tuple>::type; typename apply_trait<std::decay, arg_ref_tuple>::type;
return to_object<T>(convert_impl(elems, (arg_tuple*){})); return to_object<T>(
convert_impl(elems, static_cast<arg_tuple*>(nullptr)));
} else { } else {
return convert_impl<T, Ts...>(elems); return convert_impl<T, Ts...>(elems);
} }
@ -167,13 +168,9 @@ public:
: bool_error_ == false; : bool_error_ == false;
} }
const std::string& error_msg() const { const std::string& error_msg() const { return string_error_; }
return string_error_;
}
void set_error_mode(error_mode mode) { void set_error_mode(error_mode mode) { error_mode_ = mode; }
error_mode_ = mode;
}
// 'splits' string by given delimiter, returns vector of pairs which // 'splits' string by given delimiter, returns vector of pairs which
// contain the beginings and the ends of each column of the string // contain the beginings and the ends of each column of the string
@ -286,9 +283,7 @@ private:
return input_; return input_;
} }
bool no_match(const char* end, char delim) const { bool no_match(const char* end, char delim) const { return *end != delim; }
return *end != delim;
}
bool no_match(const char* end, const std::string& delim) const { bool no_match(const char* end, const std::string& delim) const {
return strncmp(end, delim.c_str(), delim.size()) != 0; return strncmp(end, delim.c_str(), delim.size()) != 0;
@ -361,7 +356,7 @@ private:
no_void_validator_tup_t<Ts...> ret; no_void_validator_tup_t<Ts...> ret;
extract_multiple<0, 0, Ts...>(ret, elems); extract_multiple<0, 0, Ts...>(ret, elems);
return ret; return ret;
}; }
//////////////// ////////////////
// members // members

View File

@ -181,7 +181,7 @@ public:
using Ret = no_void_validator_tup_t<Ts...>; using Ret = no_void_validator_tup_t<Ts...>;
return try_invoke_and_make_composite< return try_invoke_and_make_composite<
std::optional<Ret>>(get_next<Ts...>(), std::forward<Fun>(fun)); std::optional<Ret>>(get_next<Ts...>(), std::forward<Fun>(fun));
}; }
// identical to try_next but returns composite with object instead of a // identical to try_next but returns composite with object instead of a
// tuple // tuple
@ -189,7 +189,7 @@ public:
composite<std::optional<T>> try_object(Fun&& fun = none{}) { composite<std::optional<T>> try_object(Fun&& fun = none{}) {
return try_invoke_and_make_composite< return try_invoke_and_make_composite<
std::optional<T>>(get_object<T, Ts...>(), std::forward<Fun>(fun)); std::optional<T>>(get_object<T, Ts...>(), std::forward<Fun>(fun));
}; }
private: private:
template <typename...> template <typename...>

8
meson.build Normal file
View File

@ -0,0 +1,8 @@
project('ssp', 'cpp',
default_options :
['warning_level=3',
'cpp_std=c++17',
'buildtype=debug'])
includes = include_directories('include')
subdir('test')

3
subprojects/doctest.wrap Normal file
View File

@ -0,0 +1,3 @@
[wrap-git]
url = https://github.com/onqtam/doctest
revision = 2.4.4

View File

@ -31,6 +31,7 @@ enable_testing()
foreach(name IN ITEMS test_parser test_converter test_extractions) foreach(name IN ITEMS test_parser test_converter test_extractions)
add_executable("${name}" "${name}.cpp") add_executable("${name}" "${name}.cpp")
target_link_libraries("${name}" PRIVATE ssp::ssp doctest::doctest) target_link_libraries("${name}" PRIVATE ssp::ssp doctest::doctest)
target_compile_definitions("${name}" PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) target_compile_definitions("${name}" PRIVATE
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI)
doctest_discover_tests("${name}") doctest_discover_tests("${name}")
endforeach() endforeach()

18
test/meson.build Normal file
View File

@ -0,0 +1,18 @@
test_sources = files([
'test_main.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,7 +1,12 @@
#include <algorithm> #include <algorithm>
#include <doctest/doctest.h>
#include <ss/converter.hpp> #include <ss/converter.hpp>
#ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h>
#else
#include <doctest.h>
#endif
TEST_CASE("testing split") { TEST_CASE("testing split") {
ss::converter c; ss::converter c;

View File

@ -1,7 +1,12 @@
#include <ss/extract.hpp> #include <ss/extract.hpp>
#include <doctest/doctest.h>
#include <algorithm> #include <algorithm>
#ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h>
#else
#include <doctest.h>
#endif
constexpr auto eps = 0.000001; constexpr auto eps = 0.000001;
using ld = long double; 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,17 +1,20 @@
#include <ss/parser.hpp>
#include <doctest/doctest.h>
#include <algorithm> #include <algorithm>
#include <filesystem> #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 { struct unique_file_name {
const std::string name; const std::string name;
unique_file_name() : name{std::tmpnam(nullptr)} { unique_file_name() : name{std::tmpnam(nullptr)} {}
}
~unique_file_name() { ~unique_file_name() { std::filesystem::remove(name); }
std::filesystem::remove(name);
}
}; };
struct X { struct X {
@ -27,9 +30,7 @@ struct X {
.append(delim) .append(delim)
.append(s); .append(s);
} }
auto tied() const { auto tied() const { return std::tie(i, d, s); }
return std::tie(i, d, s);
}
}; };
template <typename T> template <typename T>
@ -165,13 +166,10 @@ struct test_struct {
int i; int i;
double d; double d;
char c; char c;
auto tied() { auto tied() { return std::tie(i, d, c); }
return std::tie(i, d, c);
}
}; };
void expect_test_struct(const test_struct&) { void expect_test_struct(const test_struct&) {}
}
// various scenarios // various scenarios
TEST_CASE("testing composite conversion") { TEST_CASE("testing composite conversion") {
@ -393,9 +391,7 @@ struct my_string {
my_string() = default; my_string() = default;
~my_string() { ~my_string() { delete[] data; }
delete[] data;
}
// make sure no object is copied // make sure no object is copied
my_string(const my_string&) = delete; my_string(const my_string&) = delete;
@ -426,9 +422,7 @@ struct xyz {
my_string x; my_string x;
my_string y; my_string y;
my_string z; my_string z;
auto tied() { auto tied() { return std::tie(x, y, z); }
return std::tie(x, y, z);
}
}; };
TEST_CASE("testing the moving of parsed values") { TEST_CASE("testing the moving of parsed values") {