Depends: spdlog 1.4.2 | Depends: spdlog 1.4.2 | ||||
Depends: ms-wil 2019.11.10 | Depends: ms-wil 2019.11.10 | ||||
Depends: range-v3 0.9.1 | Depends: range-v3 0.9.1 | ||||
Depends: nlohmann-json 3.7.1 | |||||
Depends: nlohmann-json 3.7.1 | |||||
Test-Driver: Catch-Main |
#include <browns/output.hpp> | #include <browns/output.hpp> | ||||
#include <neo/buffer.hpp> | #include <neo/buffer.hpp> | ||||
#include <catch2/catch.hpp> | |||||
#include <iostream> | #include <iostream> | ||||
int check_hash(std::string_view str, std::string_view expect_md5) { | |||||
auto md5_hash_str(std::string_view s) { | |||||
browns::md5 hash; | browns::md5 hash; | ||||
hash.feed(neo::buffer(str)); | |||||
hash.feed(neo::buffer(s)); | |||||
hash.pad(); | hash.pad(); | ||||
auto dig = hash.digest(); | |||||
auto dig_str = browns::format_digest(dig); | |||||
if (dig_str != expect_md5) { | |||||
std::cerr << "Hash of '" << str << "' did not match. Expected '" << expect_md5 | |||||
<< "', but got '" << dig_str << "'\n"; | |||||
return 1; | |||||
} | |||||
return 0; | |||||
return browns::format_digest(hash.digest()); | |||||
} | } | ||||
int main() { | |||||
browns::md5 hash; | |||||
void check_hash(std::string_view str, std::string_view digest) { | |||||
INFO("Hashed string: " << str); | |||||
CHECK(md5_hash_str(str) == digest); | |||||
} | |||||
int n_fails = 0; | |||||
n_fails += check_hash("1234abcd1234abcd1234abcd1234abcd", "67aa636d72b967157c363f0acdf7011b"); | |||||
n_fails += check_hash("The quick brown fox jumps over the lazy dog", | |||||
"9e107d9d372bb6826bd81d3542a419d6"); | |||||
n_fails += check_hash("", "d41d8cd98f00b204e9800998ecf8427e"); | |||||
n_fails += check_hash( | |||||
TEST_CASE("Known hashes") { | |||||
check_hash("1234abcd1234abcd1234abcd1234abcd", "67aa636d72b967157c363f0acdf7011b"); | |||||
check_hash("The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6"); | |||||
check_hash("", "d41d8cd98f00b204e9800998ecf8427e"); | |||||
check_hash( | |||||
"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", | "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", | ||||
"967ce152b23edc20ebd23b7eba57277c"); | "967ce152b23edc20ebd23b7eba57277c"); | ||||
n_fails += check_hash("WWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "9aff577d3248b8889b22f24ee9665c17"); | |||||
return n_fails; | |||||
check_hash("WWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "9aff577d3248b8889b22f24ee9665c17"); | |||||
} | } |
#include <dds/proc.hpp> | #include <dds/proc.hpp> | ||||
#include <dds/util.test.hpp> | |||||
// #include <dds/util.test.hpp> | |||||
#include <catch2/catch.hpp> | |||||
namespace { | namespace { | ||||
void check_tc_compile(std::string_view tc_content, | void check_tc_compile(std::string_view tc_content, | ||||
std::string_view compile, | |||||
std::string_view compile_warnings, | |||||
std::string_view ar, | |||||
std::string_view exe) { | |||||
std::string_view expected_compile, | |||||
std::string_view expected_compile_warnings, | |||||
std::string_view expected_ar, | |||||
std::string_view expected_exe) { | |||||
auto tc = dds::parse_toolchain_dds(tc_content); | auto tc = dds::parse_toolchain_dds(tc_content); | ||||
bool any_error = false; | |||||
dds::compile_file_spec cf; | dds::compile_file_spec cf; | ||||
cf.source_path = "foo.cpp"; | cf.source_path = "foo.cpp"; | ||||
cf.out_path = "foo.o"; | cf.out_path = "foo.o"; | ||||
auto cf_cmd = tc.create_compile_command(cf); | auto cf_cmd = tc.create_compile_command(cf); | ||||
auto cf_cmd_str = dds::quote_command(cf_cmd); | auto cf_cmd_str = dds::quote_command(cf_cmd); | ||||
if (cf_cmd_str != compile) { | |||||
std::cerr << "Compile command came out incorrect!\n"; | |||||
std::cerr << " Expected: " << compile << '\n'; | |||||
std::cerr << " Actual: " << cf_cmd_str << "\n\n"; | |||||
any_error = true; | |||||
} | |||||
CHECK(cf_cmd_str == expected_compile); | |||||
cf.enable_warnings = true; | cf.enable_warnings = true; | ||||
cf_cmd = tc.create_compile_command(cf); | cf_cmd = tc.create_compile_command(cf); | ||||
cf_cmd_str = dds::quote_command(cf_cmd); | cf_cmd_str = dds::quote_command(cf_cmd); | ||||
if (cf_cmd_str != compile_warnings) { | |||||
std::cerr << "Compile command (with warnings) came out incorrect!\n"; | |||||
std::cerr << " Expected: " << compile_warnings << '\n'; | |||||
std::cerr << " Actual: " << cf_cmd_str << "\n\n"; | |||||
any_error = true; | |||||
} | |||||
CHECK(cf_cmd_str == expected_compile_warnings); | |||||
dds::archive_spec ar_spec; | dds::archive_spec ar_spec; | ||||
ar_spec.input_files.push_back("foo.o"); | ar_spec.input_files.push_back("foo.o"); | ||||
ar_spec.out_path = "stuff.a"; | ar_spec.out_path = "stuff.a"; | ||||
auto ar_cmd = tc.create_archive_command(ar_spec); | auto ar_cmd = tc.create_archive_command(ar_spec); | ||||
auto ar_cmd_str = dds::quote_command(ar_cmd); | auto ar_cmd_str = dds::quote_command(ar_cmd); | ||||
if (ar_cmd_str != ar) { | |||||
std::cerr << "Archive command came out incorrect!\n"; | |||||
std::cerr << " Expected: " << ar << '\n'; | |||||
std::cerr << " Actual: " << ar_cmd_str << "\n\n"; | |||||
any_error = true; | |||||
} | |||||
CHECK(ar_cmd_str == expected_ar); | |||||
dds::link_exe_spec exe_spec; | dds::link_exe_spec exe_spec; | ||||
exe_spec.inputs.push_back("foo.o"); | exe_spec.inputs.push_back("foo.o"); | ||||
exe_spec.output = "meow.exe"; | exe_spec.output = "meow.exe"; | ||||
auto exe_cmd = tc.create_link_executable_command(exe_spec); | auto exe_cmd = tc.create_link_executable_command(exe_spec); | ||||
auto exe_cmd_str = dds::quote_command(exe_cmd); | auto exe_cmd_str = dds::quote_command(exe_cmd); | ||||
if (exe_cmd_str != exe) { | |||||
std::cerr << "Executable linking command came out incorrect!\n"; | |||||
std::cerr << " Expected: " << exe << '\n'; | |||||
std::cerr << " Actual: " << exe_cmd_str << "\n\n"; | |||||
any_error = true; | |||||
} | |||||
if (any_error) { | |||||
std::cerr << "The error-producing toolchain file content:\n" << tc_content << '\n'; | |||||
dds::S_failed_checks++; | |||||
} | |||||
CHECK(exe_cmd_str == expected_exe); | |||||
} | } | ||||
void run_tests() { | |||||
TEST_CASE("Generating toolchain commands") { | |||||
check_tc_compile("Compiler-ID: GNU", | check_tc_compile("Compiler-ID: GNU", | ||||
"g++ -fPIC -fdiagnostics-color -pthread -c foo.cpp -ofoo.o", | "g++ -fPIC -fdiagnostics-color -pthread -c foo.cpp -ofoo.o", | ||||
"g++ -fPIC -fdiagnostics-color -pthread -Wall -Wextra -Wpedantic -Wconversion " | "g++ -fPIC -fdiagnostics-color -pthread -Wall -Wextra -Wpedantic -Wconversion " | ||||
} | } | ||||
} // namespace | } // namespace | ||||
DDS_TEST_MAIN; |
#include <dds/toolchain/toolchain.hpp> | #include <dds/toolchain/toolchain.hpp> | ||||
#include <dds/util.test.hpp> | |||||
using namespace dds; | |||||
namespace { | |||||
#include <catch2/catch.hpp> | |||||
#define CHECK_SHLEX(str, ...) \ | #define CHECK_SHLEX(str, ...) \ | ||||
do { \ | do { \ | ||||
CHECK(dds::split_shell_string(str) == std::vector<std::string>(__VA_ARGS__)); \ | |||||
INFO("Shell-lexing string: '" << str << "'"); CHECK(dds::split_shell_string(str) == std::vector<std::string>(__VA_ARGS__)); \ | |||||
} while (0) | } while (0) | ||||
void test_shlex() { | |||||
TEST_CASE("Shell lexer") { | |||||
CHECK_SHLEX("foo", {"foo"}); | CHECK_SHLEX("foo", {"foo"}); | ||||
CHECK_SHLEX("foo bar", {"foo", "bar"}); | CHECK_SHLEX("foo bar", {"foo", "bar"}); | ||||
CHECK_SHLEX("\"foo\" bar", {"foo", "bar"}); | CHECK_SHLEX("\"foo\" bar", {"foo", "bar"}); | ||||
CHECK_SHLEX("Foo\nBar", {"Foo", "Bar"}); | CHECK_SHLEX("Foo\nBar", {"Foo", "Bar"}); | ||||
CHECK_SHLEX("foo \"\" bar", {"foo", "", "bar"}); | CHECK_SHLEX("foo \"\" bar", {"foo", "", "bar"}); | ||||
} | } | ||||
void run_tests() { test_shlex(); } | |||||
} // namespace | |||||
DDS_TEST_MAIN; |
#pragma once | |||||
#include <iostream> | |||||
namespace dds { | |||||
int S_failed_checks = 0; | |||||
struct requirement_failed {}; | |||||
#define CHECK(...) \ | |||||
do { \ | |||||
if (!(__VA_ARGS__)) { \ | |||||
++::dds::S_failed_checks; \ | |||||
std::cerr << "Check failed at " << __FILE__ << ':' << __LINE__ << ": " << #__VA_ARGS__ \ | |||||
<< "\n"; \ | |||||
} \ | |||||
} while (0) | |||||
#define REQUIRE(...) \ | |||||
do { \ | |||||
if (!(__VA_ARGS__)) { \ | |||||
++::dds::S_failed_checks; \ | |||||
std::cerr << "Check failed at " << __FILE__ << ':' << __LINE__ << ": " << #__VA_ARGS__ \ | |||||
<< "\n"; \ | |||||
throw ::dds::requirement_failed(); \ | |||||
} \ | |||||
} while (0) | |||||
#define DDS_TEST_MAIN \ | |||||
int main() { \ | |||||
try { \ | |||||
run_tests(); \ | |||||
} catch (const ::dds::requirement_failed&) { \ | |||||
return ::dds::S_failed_checks; \ | |||||
} catch (const std::exception& e) { \ | |||||
std::cerr << "An unhandled exception occured: " << e.what() << '\n'; \ | |||||
return 2; \ | |||||
} \ | |||||
return ::dds::S_failed_checks; \ | |||||
} \ | |||||
static_assert(true) | |||||
} // namespace dds |
#include <dds/util/string.hpp> | #include <dds/util/string.hpp> | ||||
#include <dds/util.test.hpp> | |||||
#include <catch2/catch.hpp> | |||||
using namespace dds; | using namespace dds; | ||||
namespace { | |||||
#define CHECK_SPLIT(str, key, ...) \ | #define CHECK_SPLIT(str, key, ...) \ | ||||
do { \ | do { \ | ||||
CHECK(dds::split(str, key) == std::vector<std::string>(__VA_ARGS__)); \ | CHECK(dds::split(str, key) == std::vector<std::string>(__VA_ARGS__)); \ | ||||
} while (0) | } while (0) | ||||
void test_starts_with() { | |||||
TEST_CASE("starts_with") { | |||||
CHECK(starts_with("foo", "foo")); | CHECK(starts_with("foo", "foo")); | ||||
CHECK(starts_with("foo.bar", "foo")); | CHECK(starts_with("foo.bar", "foo")); | ||||
CHECK(starts_with("foo", "f")); | CHECK(starts_with("foo", "f")); | ||||
CHECK(!starts_with("foo.bar", "bar")); | CHECK(!starts_with("foo.bar", "bar")); | ||||
} | } | ||||
void test_ends_with() { | |||||
TEST_CASE("ends_with") { | |||||
CHECK(ends_with("foo", "foo")); | CHECK(ends_with("foo", "foo")); | ||||
CHECK(ends_with("foo.bar", "bar")); | CHECK(ends_with("foo.bar", "bar")); | ||||
CHECK(ends_with("foo", "o")); | CHECK(ends_with("foo", "o")); | ||||
CHECK(!ends_with("foo.bar", "foo")); | CHECK(!ends_with("foo.bar", "foo")); | ||||
} | } | ||||
void test_trim() { | |||||
TEST_CASE( "trim" ) { | |||||
CHECK(trim_view("foo") == "foo"); | CHECK(trim_view("foo") == "foo"); | ||||
CHECK(trim_view("foo ") == "foo"); | CHECK(trim_view("foo ") == "foo"); | ||||
CHECK(trim_view(" ").size() == 0); | CHECK(trim_view(" ").size() == 0); | ||||
} | } | ||||
void test_contains() { | |||||
TEST_CASE( "contains" ) { | |||||
CHECK(contains("foo", "foo")); | CHECK(contains("foo", "foo")); | ||||
CHECK(contains("foo", "")); | CHECK(contains("foo", "")); | ||||
CHECK(contains("foo", "o")); | CHECK(contains("foo", "o")); | ||||
CHECK(!contains("foo", "bar")); | CHECK(!contains("foo", "bar")); | ||||
} | } | ||||
void test_split() { | |||||
TEST_CASE( "split" ) { | |||||
CHECK_SPLIT("foo.bar", ".", {"foo", "bar"}); | CHECK_SPLIT("foo.bar", ".", {"foo", "bar"}); | ||||
CHECK_SPLIT("foo.bar.baz", ".", {"foo", "bar", "baz"}); | CHECK_SPLIT("foo.bar.baz", ".", {"foo", "bar", "baz"}); | ||||
CHECK_SPLIT(".", ".", {"", ""}); | CHECK_SPLIT(".", ".", {"", ""}); | ||||
CHECK_SPLIT("", ",", {""}); | CHECK_SPLIT("", ",", {""}); | ||||
} | } | ||||
void run_tests() { | |||||
test_trim(); | |||||
test_starts_with(); | |||||
test_ends_with(); | |||||
test_contains(); | |||||
test_split(); | |||||
} | |||||
} // namespace | |||||
DDS_TEST_MAIN; |
#include <dds/util.test.hpp> | |||||
#include <libman/parse.hpp> | #include <libman/parse.hpp> | ||||
#include <catch2/catch.hpp> | |||||
#include <iostream> | #include <iostream> | ||||
using namespace lm; | using namespace lm; | ||||
void test_simple() { | |||||
TEST_CASE("Simple") { | |||||
auto lm_src = ""; | auto lm_src = ""; | ||||
auto kvs = parse_string(lm_src); | auto kvs = parse_string(lm_src); | ||||
CHECK(kvs.size() == 0); | CHECK(kvs.size() == 0); | ||||
CHECK(kvs.find("foo")->value == "# Not a comment"); | CHECK(kvs.find("foo")->value == "# Not a comment"); | ||||
} | } | ||||
void test_multi() { | |||||
TEST_CASE("Multiple") { | |||||
auto kvs = parse_string("Foo: bar\nbaz: qux"); | auto kvs = parse_string("Foo: bar\nbaz: qux"); | ||||
CHECK(kvs.size() == 2); | CHECK(kvs.size() == 2); | ||||
REQUIRE(kvs.find("Foo")); | REQUIRE(kvs.find("Foo")); | ||||
CHECK(!iter); | CHECK(!iter); | ||||
} | } | ||||
void test_nested_kvlist() { | |||||
TEST_CASE("Nested kv-lists") { | |||||
auto check_1 = [](auto str) { | auto check_1 = [](auto str) { | ||||
INFO("Testing string: '" << str << "'"); | |||||
auto result = nested_kvlist::parse(str); | auto result = nested_kvlist::parse(str); | ||||
CHECK(result.primary == "Foo"); | CHECK(result.primary == "Foo"); | ||||
CHECK(result.pairs.size() == 1); | CHECK(result.pairs.size() == 1); | ||||
check_1("Foo;bar=baz"); | check_1("Foo;bar=baz"); | ||||
auto check_2 = [](auto str) { | auto check_2 = [](auto str) { | ||||
INFO("Testing string: '" << str << "'"); | |||||
auto result = nested_kvlist::parse(str); | auto result = nested_kvlist::parse(str); | ||||
CHECK(result.primary == "Foo"); | CHECK(result.primary == "Foo"); | ||||
CHECK(result.pairs.size() == 0); | CHECK(result.pairs.size() == 0); | ||||
check_2("Foo; "); | check_2("Foo; "); | ||||
auto check_3 = [](auto str) { | auto check_3 = [](auto str) { | ||||
INFO("Testing string: '" << str << "'"); | |||||
auto result = nested_kvlist::parse(str); | auto result = nested_kvlist::parse(str); | ||||
CHECK(result.primary == "Foo bar"); | CHECK(result.primary == "Foo bar"); | ||||
CHECK(result.pairs.size() == 2); | CHECK(result.pairs.size() == 2); | ||||
check_3("Foo bar ; quux= baz=meow"); | check_3("Foo bar ; quux= baz=meow"); | ||||
check_3("Foo bar ;quux= baz=meow"); | check_3("Foo bar ;quux= baz=meow"); | ||||
} | } | ||||
void run_tests() { | |||||
test_simple(); | |||||
test_multi(); | |||||
test_nested_kvlist(); | |||||
} | |||||
DDS_TEST_MAIN; |
#include <neo/buffer.hpp> | |||||
#include <neo/buffer.test.hpp> | |||||
#include <neo/buffer_algorithm.hpp> | |||||
#include <array> | |||||
#include <string> | |||||
struct my_simple_struct { | |||||
int a; | |||||
int b; | |||||
}; | |||||
int main() { | |||||
// std::string s = "I am a string!"; | |||||
// auto s_buf = neo::buffer(s); | |||||
// CHECK(s_buf.data() == s.data()); | |||||
my_simple_struct foo; | |||||
foo.a = 12; | |||||
foo.b = 3; | |||||
neo::mutable_buffer pod_buf = neo::buffer(foo); | |||||
CHECK(pod_buf.size() == sizeof(foo)); | |||||
my_simple_struct bar; | |||||
neo::buffer_copy(neo::buffer(bar), pod_buf); | |||||
CHECK(bar.a == foo.a); | |||||
CHECK(bar.b == foo.b); | |||||
bar.b = 55; | |||||
std::array<char, sizeof bar> buf; | |||||
neo::buffer_copy(neo::buffer(buf), neo::buffer(bar)); | |||||
neo::buffer_copy(neo::buffer(foo), neo::buffer(buf)); | |||||
CHECK(foo.b == 55); | |||||
} |
#pragma once | |||||
#include <iostream> | |||||
#define CHECK(...) \ | |||||
do { \ | |||||
if (!(__VA_ARGS__)) { \ | |||||
std::cerr << "Check failed: " << (#__VA_ARGS__) << '\n'; \ | |||||
return 1; \ | |||||
} \ | |||||
} while (0) |
#include <neo/buffer_algorithm.hpp> | |||||
#include <neo/buffer.test.hpp> | |||||
#include <neo/const_buffer.hpp> | |||||
#include <string_view> | |||||
int main() { | |||||
auto buf = neo::const_buffer("A string"); | |||||
auto buf_iter = neo::buffer_sequence_begin(buf); | |||||
CHECK(buf_iter->data() == buf.data()); | |||||
CHECK(buf_iter != neo::buffer_sequence_end(buf)); | |||||
CHECK(neo::buffer_size(buf) == buf.size()); | |||||
// neo::buffer_size(12); | |||||
} |
#include <neo/buffer.test.hpp> | |||||
#include <neo/const_buffer.hpp> | |||||
#include <iostream> | |||||
int main() { | |||||
neo::const_buffer buf; | |||||
CHECK(buf.size() == 0); | |||||
buf = neo::const_buffer("meow"); | |||||
CHECK(buf.size() == 4); | |||||
auto buf2 = buf + 3; | |||||
CHECK(buf2.size() == 1); | |||||
CHECK(buf2.data()[0] == std::byte('w')); | |||||
buf2 += 1; | |||||
CHECK(buf2.size() == 0); | |||||
} |
#include <neo/mutable_buffer.hpp> | |||||
int main() {} |
#include "./version.hpp" | #include "./version.hpp" | ||||
#include <dds/util.test.hpp> | |||||
#include <catch2/catch.hpp> | |||||
namespace { | |||||
void test_simple_parse() { | |||||
TEST_CASE("Parsing") { | |||||
auto v1 = semver::version::parse("1.2.3"); | auto v1 = semver::version::parse("1.2.3"); | ||||
CHECK(v1.major == 1); | CHECK(v1.major == 1); | ||||
CHECK(v1.minor == 2); | CHECK(v1.minor == 2); | ||||
v1.major = 999999; | v1.major = 999999; | ||||
CHECK(v1.to_string() == "999999.2.55"); | CHECK(v1.to_string() == "999999.2.55"); | ||||
} | } | ||||
void run_tests() { test_simple_parse(); } | |||||
} // namespace | |||||
DDS_TEST_MAIN; |