This commit is contained in:
chatlanin 2022-02-28 12:44:18 +03:00
commit 0ad600c339
12 changed files with 145 additions and 0 deletions

0
README.md Normal file
View File

6
bin/main.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "src/string/string.hpp"
int main(int argc, char *argv[])
{
return 0;
}

7
bin/meson.build Normal file
View File

@ -0,0 +1,7 @@
deps += string_dep
executable(
'hack', 'main.cpp',
dependencies : deps,
cpp_args: args
)

25
meson.build Normal file
View File

@ -0,0 +1,25 @@
# https://pixorblog.wordpress.com/2019/07/27/a-meson-starter-script-for-c-projects
project(
'hack',
'cpp',
version : '0.0.1',
default_options : ['cpp_std=c++20']
)
add_project_arguments (
'-pedantic',
'-Wno-comment',
'-Wno-gnu-zero-variadic-macro-arguments',
'-Wunused-but-set-variable',
language: 'cpp'
)
args = []
deps = []
inc = []
inc += include_directories('.')
subdir('src')
subdir('bin')
subdir('tests')

12
run Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
TEST="meson test -C build"
RUN="./build/bin/hack"
command meson compile -C build
if [[ $1 == "test" ]]; then
command $TEST
else
command $RUN
fi

3
src/meson.build Normal file
View File

@ -0,0 +1,3 @@
inc += include_directories('.')
subdir('string')

14
src/string/meson.build Normal file
View File

@ -0,0 +1,14 @@
headers = ['string.hpp']
sources = ['string.cpp']
lib = library(
'string',
include_directories : inc,
install : true,
sources: [headers, sources]
)
string_dep = declare_dependency(
include_directories: inc,
link_with: lib
)

32
src/string/string.cpp Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include <string>
#ifndef ERROR_EXCEPTION
#define ERROR_EXCEPTION_1(in) { auto trace = std::string(LOGGER___TRACE_ON); \
throw tools::error::error_exception(in, in, "no internal system error", trace); }
#define ERROR_EXCEPTION_2(in, out) { auto trace = std::string(LOGGER___TRACE_ON); \
throw tools::error::error_exception(in, out, "no internal system err", trace); }
#define ERROR_EXCEPTION_3(in, out, err) { auto trace = std::string(LOGGER___TRACE_ON); \
throw tools::error::error_exception(in, out, err, trace); }
#define GET_MACRO(_1,_2,_3,NAME, ...) NAME
#define ERROR_EXCEPTION(...) GET_MACRO(__VA_ARGS__, ERROR_EXCEPTION_3, ERROR_EXCEPTION_2, ERROR_EXCEPTION_1)(__VA_ARGS__)
#endif
namespace tools::error
{
// implementation error exception
// example: if (1 < 0) ERROR_EXCEPTION("it's very strange");
// try {}
// catch(tools::error::error_exception& e) {}
struct error_exception : public std::exception
{
error_exception(std::string in, std::string out, std::string error, std::string trace) : in { in }, out { out }, error { error }, trace { trace } {};
std::string in;
std::string out;
std::string error;
std::string trace;
const char* what () const throw () { return in.c_str(); }
};
}

7
src/string/string.hpp Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <string>
namespace hack
{
}

15
subprojects/gtest.wrap Normal file
View File

@ -0,0 +1,15 @@
[wrap-file]
directory = googletest-release-1.11.0
source_url = https://github.com/google/googletest/archive/release-1.11.0.tar.gz
source_filename = gtest-1.11.0.tar.gz
source_hash = b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5
patch_filename = gtest_1.11.0-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.11.0-2/get_patch
patch_hash = 764530d812ac161c9eab02a8cfaec67c871fcfc5548e29fd3d488070913d4e94
[provide]
gtest = gtest_dep
gtest_main = gtest_main_dep
gmock = gmock_dep
gmock_main = gmock_main_dep

11
tests/meson.build Normal file
View File

@ -0,0 +1,11 @@
gtest_proj = subproject('gtest')
gtest_dep = gtest_proj.get_variable('gtest_main_dep')
test(
'split_str',
executable(
'split_str',
'split_str.cpp',
dependencies: [ string_dep, gtest_dep ]
)
)

13
tests/split_str.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include "string/string.hpp"
using v_str = std::vector<std::string>;
TEST(split_str, check__func)
{
// v_str res {"asdf","qwer","zxcv"};
// ASSERT_EQ(tools::func::split_str("asdf,qwer,zxcv", ','), res);
}