commit 0ad600c33989f81cbe4d1fbb6e3f80ab25507583 Author: chatlanin Date: Mon Feb 28 12:44:18 2022 +0300 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/bin/main.cpp b/bin/main.cpp new file mode 100644 index 0000000..9359c6f --- /dev/null +++ b/bin/main.cpp @@ -0,0 +1,6 @@ +#include "src/string/string.hpp" + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/bin/meson.build b/bin/meson.build new file mode 100644 index 0000000..ddaf903 --- /dev/null +++ b/bin/meson.build @@ -0,0 +1,7 @@ +deps += string_dep + +executable( + 'hack', 'main.cpp', + dependencies : deps, + cpp_args: args +) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..788e89d --- /dev/null +++ b/meson.build @@ -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') diff --git a/run b/run new file mode 100755 index 0000000..d4075e9 --- /dev/null +++ b/run @@ -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 diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..0cb5b45 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,3 @@ +inc += include_directories('.') + +subdir('string') diff --git a/src/string/meson.build b/src/string/meson.build new file mode 100644 index 0000000..a1f161d --- /dev/null +++ b/src/string/meson.build @@ -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 +) diff --git a/src/string/string.cpp b/src/string/string.cpp new file mode 100644 index 0000000..82191c7 --- /dev/null +++ b/src/string/string.cpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#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(); } + }; +} + diff --git a/src/string/string.hpp b/src/string/string.hpp new file mode 100644 index 0000000..fe96435 --- /dev/null +++ b/src/string/string.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace hack +{ +} diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000..730de1a --- /dev/null +++ b/subprojects/gtest.wrap @@ -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 + diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..fb6c145 --- /dev/null +++ b/tests/meson.build @@ -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 ] + ) +) diff --git a/tests/split_str.cpp b/tests/split_str.cpp new file mode 100644 index 0000000..b2e2627 --- /dev/null +++ b/tests/split_str.cpp @@ -0,0 +1,13 @@ +#include +#include +#include + +#include "string/string.hpp" + +using v_str = std::vector; + +TEST(split_str, check__func) +{ + // v_str res {"asdf","qwer","zxcv"}; + // ASSERT_EQ(tools::func::split_str("asdf,qwer,zxcv", ','), res); +}