aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-20 10:15:12 +0200
committerStefan Boberg <[email protected]>2021-09-20 10:15:12 +0200
commit8d3024a7e09246e44bf6d9ea14a36e6b03032e85 (patch)
treec18c2536d108378e5cddcac21398efd8d28e437d
parentAdded testing.h to wrap doctest.h (diff)
downloadzen-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.
-rw-r--r--zen/chunk/chunk.cpp4
-rw-r--r--zen/zen.cpp56
-rw-r--r--zencore-test/zencore-test.cpp20
-rw-r--r--zencore/blake3.cpp6
-rw-r--r--zencore/compactbinary.cpp6
-rw-r--r--zencore/compactbinarybuilder.cpp5
-rw-r--r--zencore/compactbinarypackage.cpp7
-rw-r--r--zencore/compactbinaryvalidation.cpp5
-rw-r--r--zencore/compositebuffer.cpp5
-rw-r--r--zencore/compress.cpp5
-rw-r--r--zencore/include/zencore/testing.h4
-rw-r--r--zencore/include/zencore/zencore.h4
-rw-r--r--zencore/intmath.cpp6
-rw-r--r--zencore/iobuffer.cpp9
-rw-r--r--zencore/iohash.cpp2
-rw-r--r--zencore/md5.cpp6
-rw-r--r--zencore/memory.cpp7
-rw-r--r--zencore/refcount.cpp7
-rw-r--r--zencore/sha1.cpp6
-rw-r--r--zencore/sharedbuffer.cpp7
-rw-r--r--zencore/snapshot_manifest.cpp10
-rw-r--r--zencore/stats.cpp9
-rw-r--r--zencore/stream.cpp7
-rw-r--r--zencore/string.cpp11
-rw-r--r--zencore/timer.cpp8
-rw-r--r--zencore/uid.cpp7
-rw-r--r--zencore/xxhash.cpp2
-rw-r--r--zencore/zencore.cpp2
-rw-r--r--zenhttp/httpclient.cpp7
-rw-r--r--zenhttp/httpserver.cpp7
-rw-r--r--zenserver-test/zenserver-test.cpp15
-rw-r--r--zenserver/vfs.cpp2
-rw-r--r--zenserver/zenserver.cpp9
-rw-r--r--zenstore-test/zenstore-test.cpp19
-rw-r--r--zenstore/CAS.cpp6
-rw-r--r--zenstore/basicfile.cpp6
-rw-r--r--zenstore/filecas.h2
37 files changed, 206 insertions, 100 deletions
diff --git a/zen/chunk/chunk.cpp b/zen/chunk/chunk.cpp
index a5f010dbe..18748e921 100644
--- a/zen/chunk/chunk.cpp
+++ b/zen/chunk/chunk.cpp
@@ -1,7 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "chunk.h"
-#include <doctest/doctest.h>
#include <gsl/gsl-lite.hpp>
@@ -12,6 +11,7 @@
#include <zencore/scopeguard.h>
#include <zencore/sha1.h>
#include <zencore/string.h>
+#include <zencore/testing.h>
#include <zencore/thread.h>
#include <zencore/timer.h>
#include <zenstore/cas.h>
@@ -1056,6 +1056,7 @@ ChunkCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
TEST_CASE("chunking")
{
using namespace zen;
@@ -1158,3 +1159,4 @@ TEST_CASE("chunking")
SUBCASE("mod method") { test(/* UseThreshold */ false, /* Random */ Random, 2048, 1 * 1024 * 1024); }
}
+#endif \ No newline at end of file
diff --git a/zen/zen.cpp b/zen/zen.cpp
index 9c373face..00505be75 100644
--- a/zen/zen.cpp
+++ b/zen/zen.cpp
@@ -1,9 +1,7 @@
// Zen command line client utility
//
-#define DOCTEST_CONFIG_IMPLEMENT
-#include <doctest/doctest.h>
-#undef DOCTEST_CONFIG_IMPLEMENT
+#include <zencore/zencore.h>
#include "zen.h"
@@ -23,17 +21,10 @@
#include <zencore/string.h>
#include <zenstore/cas.h>
-#if TEST_UWS
-# pragma warning(push)
-# pragma warning(disable : 4458)
-# pragma warning(disable : 4324)
-# pragma warning(disable : 4100)
-# pragma warning(disable : 4706)
-# include <uwebsockets/App.h>
-# pragma warning(pop)
-
-# pragma comment(lib, "Iphlpapi.lib")
-# pragma comment(lib, "userenv.lib")
+#if ZEN_WITH_TESTS
+# define DOCTEST_CONFIG_IMPLEMENT
+# include <zencore/testing.h>
+# undef DOCTEST_CONFIG_IMPLEMENT
#endif
#include <gsl/gsl-lite.hpp>
@@ -58,6 +49,8 @@ private:
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
+
class RunTestsCommand : public ZenCmdBase
{
public:
@@ -87,6 +80,8 @@ private:
cxxopts::Options m_Options{"runtests", "Run tests"};
};
+#endif
+
//////////////////////////////////////////////////////////////////////////
// TODO: should make this Unicode-aware so we can pass anything in on the
// command line.
@@ -104,19 +99,22 @@ main(int argc, char** argv)
auto _ = zen::MakeGuard([] { spdlog::shutdown(); });
- HashCommand HashCmd;
- CopyCommand CopyCmd;
- DedupCommand DedupCmd;
- DeployCommand DeployCmd;
- DropCommand DropCmd;
- ChunkCommand ChunkCmd;
+ HashCommand HashCmd;
+ CopyCommand CopyCmd;
+ DedupCommand DedupCmd;
+ DeployCommand DeployCmd;
+ DropCommand DropCmd;
+ ChunkCommand ChunkCmd;
+ RunCommand RunCmd;
+ StatusCommand StatusCmd;
+ TopCommand TopCmd;
+ PsCommand PsCmd;
+ UpCommand UpCmd;
+ DownCommand DownCmd;
+
+#if ZEN_WITH_TESTS
RunTestsCommand RunTestsCmd;
- RunCommand RunCmd;
- StatusCommand StatusCmd;
- TopCommand TopCmd;
- PsCommand PsCmd;
- UpCommand UpCmd;
- DownCommand DownCmd;
+#endif
const struct CommandInfo
{
@@ -131,14 +129,16 @@ main(int argc, char** argv)
{"dedup", &DedupCmd, "Dedup files"},
{"drop", &DropCmd, "Drop cache bucket(s)"},
{"hash", &HashCmd, "Compute file hashes"},
- {"runtests", &RunTestsCmd, "Run zen tests"},
{"run", &RunCmd, "Remote execution"},
{"status", &StatusCmd, "Show zen status"},
{"ps", &PsCmd, "Enumerate running zen server instances"},
{"top", &TopCmd, "Monitor zen server activity"},
{"up", &UpCmd, "Bring zen server up"},
{"down", &DownCmd, "Bring zen server down"},
- // clang-format on
+ // clang-format on
+#if ZEN_WITH_TESTS
+ {"runtests", &RunTestsCmd, "Run zen tests"},
+#endif
};
// Build set containing available commands
diff --git a/zencore-test/zencore-test.cpp b/zencore-test/zencore-test.cpp
index 7242a30ec..cd4ce3e0a 100644
--- a/zencore-test/zencore-test.cpp
+++ b/zencore-test/zencore-test.cpp
@@ -4,20 +4,22 @@
#include <zencore/logging.h>
#include <zencore/zencore.h>
-#define DOCTEST_CONFIG_IMPLEMENT
-#include <doctest/doctest.h>
-#undef DOCTEST_CONFIG_IMPLEMENT
+#if ZEN_WITH_TESTS
+# define DOCTEST_CONFIG_IMPLEMENT
+# include <zencore/testing.h>
+# undef DOCTEST_CONFIG_IMPLEMENT
+#endif
-void
-forceLinkTests()
+int
+main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
+#if ZEN_WITH_TESTS
zen::zencore_forcelinktests();
-}
-int
-main(int argc, char* argv[])
-{
zen::logging::InitializeLogging();
return doctest::Context(argc, argv).run();
+#else
+ return 0;
+#endif
}
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
diff --git a/zenhttp/httpclient.cpp b/zenhttp/httpclient.cpp
index fb1df30b2..20550b0c9 100644
--- a/zenhttp/httpclient.cpp
+++ b/zenhttp/httpclient.cpp
@@ -10,10 +10,9 @@
#include <zencore/session.h>
#include <zencore/sharedbuffer.h>
#include <zencore/stream.h>
+#include <zencore/testing.h>
#include <zenhttp/httpshared.h>
-#include <doctest/doctest.h>
-
static std::atomic<uint32_t> HttpClientRequestIdCounter{0};
namespace zen {
@@ -159,6 +158,8 @@ HttpClient::Delete(std::string_view Url)
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
+
TEST_CASE("httpclient")
{
using namespace std::literals;
@@ -171,4 +172,6 @@ httpclient_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp
index 62ee66a08..599c99a18 100644
--- a/zenhttp/httpserver.cpp
+++ b/zenhttp/httpserver.cpp
@@ -13,6 +13,7 @@
#include <zencore/refcount.h>
#include <zencore/stream.h>
#include <zencore/string.h>
+#include <zencore/testing.h>
#include <zencore/thread.h>
#include <zenhttp/httpshared.h>
@@ -23,8 +24,6 @@
#include <span>
#include <string_view>
-#include <doctest/doctest.h>
-
namespace zen {
using namespace std::literals;
@@ -525,6 +524,8 @@ CreateHttpServer()
//////////////////////////////////////////////////////////////////////////
+#if ZEN_WITH_TESTS
+
TEST_CASE("http.common")
{
using namespace std::literals;
@@ -566,4 +567,6 @@ http_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp
index a556d896e..0608fe8f3 100644
--- a/zenserver-test/zenserver-test.cpp
+++ b/zenserver-test/zenserver-test.cpp
@@ -51,9 +51,11 @@
//////////////////////////////////////////////////////////////////////////
-#define DOCTEST_CONFIG_IMPLEMENT
-#include <doctest/doctest.h>
-#undef DOCTEST_CONFIG_IMPLEMENT
+#if ZEN_WITH_TESTS
+# define DOCTEST_CONFIG_IMPLEMENT
+# include <zencore/testing.h>
+# undef DOCTEST_CONFIG_IMPLEMENT
+#endif
using namespace fmt::literals;
@@ -657,7 +659,7 @@ main()
[](auto req) { return req->create_response().set_body("Hello, World!").done(); }));
return 0;
}
-#else
+#elif ZEN_WITH_TESTS
zen::ZenServerEnvironment TestEnv;
@@ -2056,4 +2058,9 @@ TEST_CASE("lifetime.owner.2")
# endif
} // namespace zen::tests
+#else
+int
+main()
+{
+}
#endif
diff --git a/zenserver/vfs.cpp b/zenserver/vfs.cpp
index 86e265b20..b98801116 100644
--- a/zenserver/vfs.cpp
+++ b/zenserver/vfs.cpp
@@ -532,7 +532,7 @@ retry:
}
else if (hRes == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
- throw zen::WindowsException(hRes, "Failed to initialize root placeholder");
+ ThrowSystemException(hRes, "Failed to initialize root placeholder");
}
// Ignore error, problems will be reported below anyway
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index ea4a2915e..529972cc0 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -24,15 +24,18 @@
#include <lua.hpp>
#include <optional>
#include <regex>
+#include <set>
#include <unordered_map>
//////////////////////////////////////////////////////////////////////////
// We don't have any doctest code in this file but this is needed to bring
// in some shared code into the executable
-#define DOCTEST_CONFIG_IMPLEMENT
-#include <doctest/doctest.h>
-#undef DOCTEST_CONFIG_IMPLEMENT
+#if ZEN_WITH_TESTS
+# define DOCTEST_CONFIG_IMPLEMENT
+# include <zencore/testing.h>
+# undef DOCTEST_CONFIG_IMPLEMENT
+#endif
//////////////////////////////////////////////////////////////////////////
diff --git a/zenstore-test/zenstore-test.cpp b/zenstore-test/zenstore-test.cpp
index ed9a12566..e6bd92ab9 100644
--- a/zenstore-test/zenstore-test.cpp
+++ b/zenstore-test/zenstore-test.cpp
@@ -4,20 +4,21 @@
#include <zencore/zencore.h>
#include <zenstore/zenstore.h>
-#define DOCTEST_CONFIG_IMPLEMENT
-#include <doctest/doctest.h>
-#undef DOCTEST_CONFIG_IMPLEMENT
+#if ZEN_WITH_TESTS
+# define DOCTEST_CONFIG_IMPLEMENT
+# include <zencore/testing.h>
+# undef DOCTEST_CONFIG_IMPLEMENT
+#endif
-void
-forceLinkTests()
+int
+main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
+#if ZEN_WITH_TESTS
zen::zenstore_forcelinktests();
-}
-int
-main(int argc, char* argv[])
-{
zen::logging::InitializeLogging();
return doctest::Context(argc, argv).run();
+#else
+#endif
}
diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp
index a143230d3..320ca9e5a 100644
--- a/zenstore/CAS.cpp
+++ b/zenstore/CAS.cpp
@@ -5,12 +5,12 @@
#include "compactcas.h"
#include "filecas.h"
-#include <doctest/doctest.h>
#include <zencore/except.h>
#include <zencore/fmtutils.h>
#include <zencore/logging.h>
#include <zencore/memory.h>
#include <zencore/string.h>
+#include <zencore/testing.h>
#include <zencore/testutils.h>
#include <zencore/thread.h>
#include <zencore/uid.h>
@@ -194,6 +194,8 @@ CreateCasStore()
// Testing related code follows...
//
+#if ZEN_WITH_TESTS
+
TEST_CASE("CasStore")
{
ScopedTemporaryDirectory TempDir;
@@ -237,4 +239,6 @@ CAS_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
index 0b92a8979..fe54184cf 100644
--- a/zenstore/basicfile.cpp
+++ b/zenstore/basicfile.cpp
@@ -5,9 +5,9 @@
#include <zencore/except.h>
#include <zencore/filesystem.h>
#include <zencore/fmtutils.h>
+#include <zencore/testing.h>
#include <zencore/testutils.h>
-#include <doctest/doctest.h>
#include <fmt/format.h>
#include <gsl/gsl-lite.hpp>
@@ -158,6 +158,8 @@ BasicFile::FileSize()
return uint64_t(liFileSize.QuadPart);
}
+#if ZEN_WITH_TESTS
+
TEST_CASE("BasicFile")
{
ScopedCurrentDirectoryChange _;
@@ -174,4 +176,6 @@ basicfile_forcelink()
{
}
+#endif
+
} // namespace zen
diff --git a/zenstore/filecas.h b/zenstore/filecas.h
index 885973810..18102968a 100644
--- a/zenstore/filecas.h
+++ b/zenstore/filecas.h
@@ -17,7 +17,7 @@ namespace zen {
class BasicFile;
/** CAS storage strategy using a file-per-chunk storage strategy
-*/
+ */
struct FileCasStrategy
{