diff options
| author | Stefan Boberg <[email protected]> | 2021-09-20 10:15:12 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-20 10:15:12 +0200 |
| commit | 8d3024a7e09246e44bf6d9ea14a36e6b03032e85 (patch) | |
| tree | c18c2536d108378e5cddcac21398efd8d28e437d /zencore | |
| parent | Added testing.h to wrap doctest.h (diff) | |
| download | zen-8d3024a7e09246e44bf6d9ea14a36e6b03032e85.tar.xz zen-8d3024a7e09246e44bf6d9ea14a36e6b03032e85.zip | |
It's not possible to compile out tests
Tests are now compiled in if `ZEN_WITH_TESTS=1`, and compiled out if not. Compiling tests out reduces the footprint of the resulting executables quite significantly.
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/blake3.cpp | 6 | ||||
| -rw-r--r-- | zencore/compactbinary.cpp | 6 | ||||
| -rw-r--r-- | zencore/compactbinarybuilder.cpp | 5 | ||||
| -rw-r--r-- | zencore/compactbinarypackage.cpp | 7 | ||||
| -rw-r--r-- | zencore/compactbinaryvalidation.cpp | 5 | ||||
| -rw-r--r-- | zencore/compositebuffer.cpp | 5 | ||||
| -rw-r--r-- | zencore/compress.cpp | 5 | ||||
| -rw-r--r-- | zencore/include/zencore/testing.h | 4 | ||||
| -rw-r--r-- | zencore/include/zencore/zencore.h | 4 | ||||
| -rw-r--r-- | zencore/intmath.cpp | 6 | ||||
| -rw-r--r-- | zencore/iobuffer.cpp | 9 | ||||
| -rw-r--r-- | zencore/iohash.cpp | 2 | ||||
| -rw-r--r-- | zencore/md5.cpp | 6 | ||||
| -rw-r--r-- | zencore/memory.cpp | 7 | ||||
| -rw-r--r-- | zencore/refcount.cpp | 7 | ||||
| -rw-r--r-- | zencore/sha1.cpp | 6 | ||||
| -rw-r--r-- | zencore/sharedbuffer.cpp | 7 | ||||
| -rw-r--r-- | zencore/snapshot_manifest.cpp | 10 | ||||
| -rw-r--r-- | zencore/stats.cpp | 9 | ||||
| -rw-r--r-- | zencore/stream.cpp | 7 | ||||
| -rw-r--r-- | zencore/string.cpp | 11 | ||||
| -rw-r--r-- | zencore/timer.cpp | 8 | ||||
| -rw-r--r-- | zencore/uid.cpp | 7 | ||||
| -rw-r--r-- | zencore/xxhash.cpp | 2 | ||||
| -rw-r--r-- | zencore/zencore.cpp | 2 |
25 files changed, 115 insertions, 38 deletions
diff --git a/zencore/blake3.cpp b/zencore/blake3.cpp index 090eb6897..663f21b6d 100644 --- a/zencore/blake3.cpp +++ b/zencore/blake3.cpp @@ -4,12 +4,12 @@ #include <zencore/compositebuffer.h> #include <zencore/string.h> +#include <zencore/testing.h> #include <zencore/zencore.h> #include "../3rdparty/BLAKE3/c/blake3.h" #pragma comment(lib, "blake3.lib") -#include <doctest/doctest.h> #include <string.h> ////////////////////////////////////////////////////////////////////////// @@ -123,6 +123,8 @@ BLAKE3Stream::GetHash() // Testing related code follows... // +#if ZEN_WITH_TESTS + doctest::String toString(const BLAKE3& value) { @@ -169,4 +171,6 @@ TEST_CASE("BLAKE3") } } +#endif + } // namespace zen diff --git a/zencore/compactbinary.cpp b/zencore/compactbinary.cpp index b508d8fe8..f4908aa9a 100644 --- a/zencore/compactbinary.cpp +++ b/zencore/compactbinary.cpp @@ -2,12 +2,12 @@ #include "zencore/compactbinary.h" +#include <zencore/compactbinaryvalidation.h> #include <zencore/compress.h> #include <zencore/endian.h> #include <zencore/stream.h> -#include "zencore/compactbinaryvalidation.h" +#include <zencore/testing.h> -#include <doctest/doctest.h> #include <string_view> namespace zen { @@ -1146,6 +1146,7 @@ SaveCompactBinary(BinaryWriter& Ar, const CbObjectView& Object) ////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS void uson_forcelink() { @@ -1297,5 +1298,6 @@ TEST_CASE("uson.null") CHECK(Field.IsNull() == false); } } +#endif } // namespace zen diff --git a/zencore/compactbinarybuilder.cpp b/zencore/compactbinarybuilder.cpp index 08f37a23d..fa5b6a69b 100644 --- a/zencore/compactbinarybuilder.cpp +++ b/zencore/compactbinarybuilder.cpp @@ -7,12 +7,11 @@ #include <zencore/endian.h> #include <zencore/stream.h> #include <zencore/string.h> +#include <zencore/testing.h> #define _USE_MATH_DEFINES #include <math.h> -#include <doctest/doctest.h> - namespace zen { template<typename T> @@ -700,6 +699,7 @@ operator<<(CbWriter& Writer, const TimeSpan Value) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS void usonbuilder_forcelink() { @@ -1534,5 +1534,6 @@ TEST_CASE("usonbuilder.stream") CHECK(ValidateCompactBinary(Object.GetBuffer(), CbValidateMode::All) == CbValidateError::None); } } +#endif } // namespace zen diff --git a/zencore/compactbinarypackage.cpp b/zencore/compactbinarypackage.cpp index 9a7e7c098..fbdcd24e9 100644 --- a/zencore/compactbinarypackage.cpp +++ b/zencore/compactbinarypackage.cpp @@ -5,8 +5,7 @@ #include <zencore/compactbinaryvalidation.h> #include <zencore/endian.h> #include <zencore/stream.h> - -#include <doctest/doctest.h> +#include <zencore/testing.h> namespace zen { @@ -747,6 +746,8 @@ namespace legacy { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS + void usonpackage_forcelink() { @@ -1253,4 +1254,6 @@ TEST_CASE("usonpackage.serialization") } } +#endif + } // namespace zen diff --git a/zencore/compactbinaryvalidation.cpp b/zencore/compactbinaryvalidation.cpp index dafd1bcc8..3d72148f9 100644 --- a/zencore/compactbinaryvalidation.cpp +++ b/zencore/compactbinaryvalidation.cpp @@ -6,11 +6,10 @@ #include <zencore/endian.h> #include <zencore/memory.h> #include <zencore/string.h> +#include <zencore/testing.h> #include <algorithm> -#include <doctest/doctest.h> - namespace zen { namespace CbValidationPrivate { @@ -649,6 +648,7 @@ ValidateCompactBinaryPackage(MemoryView View, CbValidateMode Mode) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS void usonvalidation_forcelink() { @@ -658,5 +658,6 @@ TEST_CASE("usonvalidation") { SUBCASE("Basic") {} } +#endif } // namespace zen diff --git a/zencore/compositebuffer.cpp b/zencore/compositebuffer.cpp index 9349c014f..0e27e6f0e 100644 --- a/zencore/compositebuffer.cpp +++ b/zencore/compositebuffer.cpp @@ -3,8 +3,7 @@ #include <zencore/compositebuffer.h> #include <zencore/sharedbuffer.h> - -#include <doctest/doctest.h> +#include <zencore/testing.h> namespace zen { @@ -168,6 +167,7 @@ CompositeBuffer::IterateRange(uint64_t Offset, } } +#if ZEN_WITH_TESTS TEST_CASE("CompositeBuffer Null") { CompositeBuffer Buffer; @@ -337,5 +337,6 @@ void compositebuffer_forcelink() { } +#endif } // namespace zen diff --git a/zencore/compress.cpp b/zencore/compress.cpp index 12a7b9ef8..8ca799e39 100644 --- a/zencore/compress.cpp +++ b/zencore/compress.cpp @@ -6,13 +6,13 @@ #include <zencore/compositebuffer.h> #include <zencore/crc32.h> #include <zencore/endian.h> +#include <zencore/testing.h> #include "../3rdparty/Oodle/include/oodle2.h" #if ZEN_PLATFORM_WINDOWS # pragma comment(lib, "oo2core_win64.lib") #endif -#include <doctest/doctest.h> #include <lz4.h> #include <functional> #include <limits> @@ -823,6 +823,8 @@ CompressedBuffer::TryGetCompressParameters(OodleCompressor& OutCompressor, Oodle \/ \/ \/ */ +#if ZEN_WITH_TESTS + TEST_CASE("CompressedBuffer") { uint8_t Zeroes[1024]{}; @@ -908,5 +910,6 @@ void compress_forcelink() { } +#endif } // namespace zen diff --git a/zencore/include/zencore/testing.h b/zencore/include/zencore/testing.h index 75efb06e2..80aebc26e 100644 --- a/zencore/include/zencore/testing.h +++ b/zencore/include/zencore/testing.h @@ -2,9 +2,7 @@ #pragma once -#ifndef ZEN_WITH_TESTS -# define ZEN_WITH_TESTS 1 -#endif +#include <zencore/zencore.h> #if ZEN_WITH_TESTS # include <doctest/doctest.h> diff --git a/zencore/include/zencore/zencore.h b/zencore/include/zencore/zencore.h index 310f6c4ed..4fad0b7a4 100644 --- a/zencore/include/zencore/zencore.h +++ b/zencore/include/zencore/zencore.h @@ -6,6 +6,10 @@ #include <stdexcept> #include <string> +#ifndef ZEN_WITH_TESTS +# define ZEN_WITH_TESTS 1 +#endif + ////////////////////////////////////////////////////////////////////////// // Platform // diff --git a/zencore/intmath.cpp b/zencore/intmath.cpp index 2acfaebd8..f11f5e8aa 100644 --- a/zencore/intmath.cpp +++ b/zencore/intmath.cpp @@ -2,7 +2,7 @@ #include <zencore/intmath.h> -#include <doctest/doctest.h> +#include <zencore/testing.h> namespace zen { @@ -11,6 +11,8 @@ namespace zen { // Testing related code follows... // +#if ZEN_WITH_TESTS + void intmath_forcelink() { @@ -53,4 +55,6 @@ TEST_CASE("intmath") CHECK(CountTrailingZeros64(0x0000'0001'0000'0000ull) == 32); } +#endif + } // namespace zen diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index ee06f379e..bcecc768f 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -2,13 +2,14 @@ #include <zencore/iobuffer.h> -#include <doctest/doctest.h> -#include <memory.h> #include <zencore/filesystem.h> #include <zencore/fmtutils.h> #include <zencore/logging.h> #include <zencore/memory.h> +#include <zencore/testing.h> #include <zencore/thread.h> + +#include <memory.h> #include <system_error> #include <atlfile.h> @@ -382,6 +383,8 @@ IoBufferBuilder::MakeFromTemporaryFile(const wchar_t* FileName) ////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS + void iobuffer_forcelink() { @@ -394,4 +397,6 @@ TEST_CASE("IoBuffer") zen::IoBuffer buffer3(buffer2, 0, buffer2.Size()); } +#endif + } // namespace zen diff --git a/zencore/iohash.cpp b/zencore/iohash.cpp index ad8d89ff0..77076c133 100644 --- a/zencore/iohash.cpp +++ b/zencore/iohash.cpp @@ -5,8 +5,8 @@ #include <zencore/blake3.h> #include <zencore/compositebuffer.h> #include <zencore/string.h> +#include <zencore/testing.h> -#include <doctest/doctest.h> #include <gsl/gsl-lite.hpp> namespace zen { diff --git a/zencore/md5.cpp b/zencore/md5.cpp index 228c0feff..237f6cfdd 100644 --- a/zencore/md5.cpp +++ b/zencore/md5.cpp @@ -2,9 +2,9 @@ #include <zencore/md5.h> #include <zencore/string.h> +#include <zencore/testing.h> #include <zencore/zencore.h> -#include <doctest/doctest.h> #include <string.h> // big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN @@ -425,6 +425,8 @@ MD5::ToHexString(StringBuilderBase& outBuilder) const // Testing related code follows... // +#if ZEN_WITH_TESTS + void md5_forcelink() { @@ -443,4 +445,6 @@ TEST_CASE("MD5") { } +#endif + } // namespace zen diff --git a/zencore/memory.cpp b/zencore/memory.cpp index 26c8321e5..613b6ba67 100644 --- a/zencore/memory.cpp +++ b/zencore/memory.cpp @@ -2,6 +2,7 @@ #include <zencore/intmath.h> #include <zencore/memory.h> +#include <zencore/testing.h> #ifdef ZEN_PLATFORM_WINDOWS # include <malloc.h> @@ -9,8 +10,6 @@ # include <cstdlib> #endif -#include <doctest/doctest.h> - namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -147,6 +146,8 @@ ChunkingLinearAllocator::Alloc(size_t Size, size_t Alignment) // Unit tests // +#if ZEN_WITH_TESTS + TEST_CASE("ChunkingLinearAllocator") { ChunkingLinearAllocator Allocator(4096); @@ -194,4 +195,6 @@ memory_forcelink() { } +#endif + } // namespace zen diff --git a/zencore/refcount.cpp b/zencore/refcount.cpp index 943635552..33b530b90 100644 --- a/zencore/refcount.cpp +++ b/zencore/refcount.cpp @@ -2,7 +2,8 @@ #include <zencore/refcount.h> -#include <doctest/doctest.h> +#include <zencore/testing.h> + #include <functional> namespace zen { @@ -12,6 +13,8 @@ namespace zen { // Testing related code follows... // +#if ZEN_WITH_TESTS + struct TestRefClass : public RefCounted { ~TestRefClass() @@ -93,4 +96,6 @@ TEST_CASE("RefPtr on Stack allocated object") CHECK(IsDestroyed == true); } +#endif + } // namespace zen diff --git a/zencore/sha1.cpp b/zencore/sha1.cpp index 3cc2f5cdf..8b4e7897f 100644 --- a/zencore/sha1.cpp +++ b/zencore/sha1.cpp @@ -6,9 +6,9 @@ #include <zencore/sha1.h> #include <zencore/string.h> +#include <zencore/testing.h> #include <zencore/zencore.h> -#include <doctest/doctest.h> #include <string.h> // big endian architectures need #define __BYTE_ORDER __BIG_ENDIAN @@ -357,6 +357,8 @@ SHA1::ToHexString(StringBuilderBase& outBuilder) const // Testing related code follows... // +#if ZEN_WITH_TESTS + void sha1_forcelink() { @@ -436,4 +438,6 @@ TEST_CASE("SHA1") } } +#endif + } // namespace zen diff --git a/zencore/sharedbuffer.cpp b/zencore/sharedbuffer.cpp index 2761d0b4d..200e06972 100644 --- a/zencore/sharedbuffer.cpp +++ b/zencore/sharedbuffer.cpp @@ -2,7 +2,8 @@ #include <zencore/sharedbuffer.h> -#include <doctest/doctest.h> +#include <zencore/testing.h> + #include <memory.h> #include <gsl/gsl-lite.hpp> @@ -129,6 +130,8 @@ SharedBuffer::Clone(MemoryView View) ////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS + void sharedbuffer_forcelink() { @@ -138,4 +141,6 @@ TEST_CASE("SharedBuffer") { } +#endif + } // namespace zen diff --git a/zencore/snapshot_manifest.cpp b/zencore/snapshot_manifest.cpp index 87625fb7f..6e9945cf0 100644 --- a/zencore/snapshot_manifest.cpp +++ b/zencore/snapshot_manifest.cpp @@ -1,15 +1,13 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <doctest/doctest.h> #include <zencore/snapshot_manifest.h> #include <zencore/stream.h> #include <zencore/streamutil.h> #include <zencore/string.h> -#include <ostream> +#include <zencore/testing.h> #include <filesystem> - -#include <atlbase.h> +#include <ostream> // Used for getting My Documents for default snapshot dir #include <ShlObj.h> @@ -257,6 +255,8 @@ ManifestSpecToPath(const char* ManifestSpec) // Testing related code follows... // +#if ZEN_WITH_TESTS + void snapshotmanifest_forcelink() { @@ -280,4 +280,6 @@ TEST_CASE("Snapshot manifest") CHECK(Manifest.ChunkHash == Manifest2.ChunkHash); } +#endif + } // namespace zen diff --git a/zencore/stats.cpp b/zencore/stats.cpp index f8cdc8fbb..c5187940e 100644 --- a/zencore/stats.cpp +++ b/zencore/stats.cpp @@ -1,10 +1,13 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "zencore/stats.h" -#include <doctest/doctest.h> #include <cmath> #include "zencore/timer.h" +#if ZEN_WITH_TESTS +# include <zencore/testing.h> +#endif + // // Derived from https://github.com/dln/medida/blob/master/src/medida/stats/ewma.cc // @@ -47,6 +50,8 @@ EWMA::Rate() const ////////////////////////////////////////////////////////////////////////// +#if ZEN_WITH_TESTS + TEST_CASE("Stats") { SUBCASE("Simple") @@ -70,4 +75,6 @@ stats_forcelink() { } +#endif + } // namespace zen diff --git a/zencore/stream.cpp b/zencore/stream.cpp index 8687d5501..ead0b014b 100644 --- a/zencore/stream.cpp +++ b/zencore/stream.cpp @@ -1,9 +1,10 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <doctest/doctest.h> #include <stdarg.h> #include <zencore/memory.h> #include <zencore/stream.h> +#include <zencore/testing.h> + #include <algorithm> #include <stdexcept> @@ -279,6 +280,8 @@ IndentTextWriter::Write(const void* data, size_t byteCount) // Testing related code follows... // +#if ZEN_WITH_TESTS + void stream_forcelink() { @@ -336,4 +339,6 @@ TEST_CASE("BinaryWriter and BinaryWriter") CHECK(i64 == 42); } +#endif + } // namespace zen diff --git a/zencore/string.cpp b/zencore/string.cpp index ce1b6d675..6dcdc9542 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -1,11 +1,12 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <doctest/doctest.h> +#include <zencore/memory.h> +#include <zencore/string.h> +#include <zencore/testing.h> + #include <inttypes.h> #include <math.h> #include <stdio.h> -#include <zencore/memory.h> -#include <zencore/string.h> #include <exception> #include <ostream> #include <stdexcept> @@ -452,6 +453,8 @@ template class StringBuilderImpl<wchar_t>; // Unit tests // +#if ZEN_WITH_TESTS + TEST_CASE("niceNum") { char Buffer[16]; @@ -952,4 +955,6 @@ TEST_CASE("string") } } +#endif + } // namespace zen diff --git a/zencore/timer.cpp b/zencore/timer.cpp index 08b5e06d2..1e73a7532 100644 --- a/zencore/timer.cpp +++ b/zencore/timer.cpp @@ -1,8 +1,10 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <doctest/doctest.h> #include <zencore/thread.h> #include <zencore/timer.h> + +#include <zencore/testing.h> + #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> #elif ZEN_PLATFORM_LINUX @@ -62,6 +64,8 @@ GetHifreqTimerFrequencySafe() // Testing related code follows... // +#if ZEN_WITH_TESTS + void timer_forcelink() { @@ -79,4 +83,6 @@ TEST_CASE("Timer") CHECK_NE(s0, s1); } +#endif + } // namespace zen diff --git a/zencore/uid.cpp b/zencore/uid.cpp index ed00b1814..d4b708288 100644 --- a/zencore/uid.cpp +++ b/zencore/uid.cpp @@ -4,6 +4,7 @@ #include <zencore/endian.h> #include <zencore/string.h> +#include <zencore/testing.h> #include <atomic> #include <bit> @@ -12,8 +13,6 @@ #include <set> #include <unordered_map> -#include <doctest/doctest.h> - namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -109,6 +108,8 @@ Oid::ToString(StringBuilderBase& OutString) const return OutString; } +#if ZEN_WITH_TESTS + TEST_CASE("Oid") { SUBCASE("Basic") @@ -143,4 +144,6 @@ uid_forcelink() { } +#endif + } // namespace zen diff --git a/zencore/xxhash.cpp b/zencore/xxhash.cpp index a20ee10bd..450131d19 100644 --- a/zencore/xxhash.cpp +++ b/zencore/xxhash.cpp @@ -3,8 +3,8 @@ #include <zencore/xxhash.h> #include <zencore/string.h> +#include <zencore/testing.h> -#include <doctest/doctest.h> #include <gsl/gsl-lite.hpp> namespace zen { diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index 122719d90..185b191f4 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -102,6 +102,7 @@ RequestApplicationExit(int ExitCode) s_ApplicationExitRequested = true; } +#if ZEN_WITH_TESTS void zencore_forcelinktests() { @@ -124,5 +125,6 @@ zencore_forcelinktests() zen::usonbuilder_forcelink(); zen::usonpackage_forcelink(); } +#endif } // namespace zen |