From 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 22 Feb 2022 17:03:21 +0100 Subject: Initial self-hosting commit This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche Co-authored-by: Victor Moreno --- test/buildtool/crypto/TARGETS | 13 ++++++++ test/buildtool/crypto/crypto.test.cpp | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/buildtool/crypto/TARGETS create mode 100644 test/buildtool/crypto/crypto.test.cpp (limited to 'test/buildtool/crypto') diff --git a/test/buildtool/crypto/TARGETS b/test/buildtool/crypto/TARGETS new file mode 100644 index 00000000..2f604833 --- /dev/null +++ b/test/buildtool/crypto/TARGETS @@ -0,0 +1,13 @@ +{ "crypto": + { "type": ["@", "rules", "CC/test", "test"] + , "name": ["crypto"] + , "srcs": ["crypto.test.cpp"] + , "deps": + [ ["@", "catch2", "", "catch2"] + , ["test", "catch-main"] + , ["src/buildtool/crypto", "hash_generator"] + ] + , "stage": ["test", "buildtool", "crypto"] + } +, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["crypto"]} +} \ No newline at end of file diff --git a/test/buildtool/crypto/crypto.test.cpp b/test/buildtool/crypto/crypto.test.cpp new file mode 100644 index 00000000..78bea66b --- /dev/null +++ b/test/buildtool/crypto/crypto.test.cpp @@ -0,0 +1,57 @@ +#include + +#include "catch2/catch.hpp" +#include "src/buildtool/crypto/hash_generator.hpp" + +template +void test_single_hash(std::string const& bytes, std::string const& result) { + HashGenerator hash_gen{type}; + auto digest = hash_gen.Run(bytes); + CHECK(digest.HexString() == result); +} + +template +void test_increment_hash(std::string const& bytes, std::string const& result) { + HashGenerator hash_gen{type}; + auto hasher = hash_gen.IncrementalHasher(); + hasher.Update(bytes); + auto digest = std::move(hasher).Finalize(); + CHECK(digest); + CHECK(digest->HexString() == result); +} + +TEST_CASE("Hash Generator", "[crypto]") { + std::string bytes{"test"}; + + SECTION("MD5") { + // same as: echo -n test | md5sum + test_single_hash( + bytes, "098f6bcd4621d373cade4e832627b4f6"); + test_increment_hash( + bytes, "098f6bcd4621d373cade4e832627b4f6"); + } + + SECTION("SHA-1") { + // same as: echo -n test | sha1sum + test_single_hash( + bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); + test_increment_hash( + bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); + } + + SECTION("SHA-256") { + // same as: echo -n test | sha256sum + test_single_hash( + bytes, + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); + test_increment_hash( + bytes, + "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); + } + + SECTION("Git") { + // same as: echo -n test | git hash-object --stdin + test_single_hash( + bytes, "30d74d258442c7c65512eafab474568dd706c430"); + } +} -- cgit v1.2.3