Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving to simpler, faster, and safer ut #1041

Merged
merged 12 commits into from
May 30, 2024
9 changes: 9 additions & 0 deletions include/glaze/util/for_each.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ namespace glz
(f(std::integral_constant<std::size_t, I>{}) || ...);
}(std::make_index_sequence<N>{});
}

template <class Func, class Tuple>
constexpr void for_each_apply(Func&& f, Tuple&& t)
{
constexpr size_t N = glz::tuple_size_v<std::decay_t<Tuple>>;
[&]<std::size_t... I>(std::index_sequence<I...>) constexpr {
(f(std::get<I>(t)), ...);
}(std::make_index_sequence<N>{});
}
}
8 changes: 4 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(BOOST_UT_DISABLE_MODULE ON CACHE INTERNAL "")

FetchContent_Declare(
ut
GIT_REPOSITORY https://github.com/boost-ext/ut
GIT_TAG master
GIT_REPOSITORY https://github.com/openalgz/ut
GIT_TAG v0.0.3
GIT_SHALLOW TRUE
)

Expand All @@ -23,7 +23,7 @@ add_code_coverage_all_targets()

add_library(glz_test_common INTERFACE)
target_compile_features(glz_test_common INTERFACE cxx_std_20)
target_link_libraries(glz_test_common INTERFACE Boost::ut glaze::glaze)
target_link_libraries(glz_test_common INTERFACE ut::ut glaze::glaze)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(glz_test_common INTERFACE -fno-exceptions -fno-rtti)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -43,7 +43,7 @@ endif()

add_library(glz_test_exceptions INTERFACE)
target_compile_features(glz_test_exceptions INTERFACE cxx_std_20)
target_link_libraries(glz_test_exceptions INTERFACE Boost::ut glaze::glaze)
target_link_libraries(glz_test_exceptions INTERFACE ut::ut glaze::glaze)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(glz_test_exceptions INTERFACE)
target_compile_options(glz_test_exceptions INTERFACE -Wall -Wextra -pedantic)
Expand Down
4 changes: 2 additions & 2 deletions tests/api_test/api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <tuple>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/api/impl.hpp"
#include "glaze/api/std/deque.hpp"
#include "glaze/api/std/span.hpp"
Expand Down Expand Up @@ -97,7 +97,7 @@ glz::iface_fn glz_iface() noexcept { return glz::make_iface<my_api, my_api2>();

void tests()
{
using namespace boost::ut;
using namespace ut;

std::shared_ptr<glz::iface> iface{glz_iface()()};
auto io = (*iface)["my_api"]();
Expand Down
18 changes: 8 additions & 10 deletions tests/binary_test/binary_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Glaze Library
// For the license information refer to glaze.hpp

#ifndef BOOST_UT_DISABLE_MODULE
#define BOOST_UT_DISABLE_MODULE
#endif
#define UT_RUN_TIME_ONLY

#include <bit>
#include <chrono>
#include <complex>
Expand All @@ -15,7 +14,7 @@
#include <set>
#include <unordered_set>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/api/impl.hpp"
#include "glaze/binary/beve_to_json.hpp"
#include "glaze/binary/read.hpp"
Expand Down Expand Up @@ -202,7 +201,7 @@ struct glz::meta<Thing>

void write_tests()
{
using namespace boost::ut;
using namespace ut;

"round_trip"_test = [] {
{
Expand Down Expand Up @@ -413,7 +412,7 @@ void write_tests()

void bench()
{
using namespace boost::ut;
using namespace ut;
"bench"_test = [] {
glz::trace_begin("bench");
std::cout << "\nPerformance regresion test: \n";
Expand Down Expand Up @@ -452,7 +451,7 @@ void bench()
};
}

using namespace boost::ut;
using namespace ut;

suite binary_helpers = [] {
"binary_helpers"_test = [] {
Expand Down Expand Up @@ -592,7 +591,7 @@ void file_include_test()

void container_types()
{
using namespace boost::ut;
using namespace ut;
"vector int roundtrip"_test = [] {
std::vector<int> vec(100);
for (auto& item : vec) item = rand();
Expand Down Expand Up @@ -2134,11 +2133,10 @@ int main()
file_include_test();
container_types();

auto result = boost::ut::cfg<>.run({.report_errors = true});
glz::trace_end("binary_test");
const auto ec = glz::write_file_trace("binary_test.trace.json", std::string{});
if (ec) {
std::cerr << "trace output failed\n";
}
return result;
return 0;
}
11 changes: 4 additions & 7 deletions tests/compare_test/compare_test.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Glaze Library
// For the license information refer to glaze.hpp

#ifndef BOOST_UT_DISABLE_MODULE
#define BOOST_UT_DISABLE_MODULE
#endif
#define UT_RUN_TIME_ONLY

#include "glaze/compare/compare.hpp"

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/compare/approx.hpp"

using namespace boost::ut;
using namespace ut;

struct float_compare_t
{
Expand Down Expand Up @@ -61,6 +59,5 @@ suite equality = [] {

int main()
{
const auto result = boost::ut::cfg<>.run({.report_errors = true});
return result;
return 0;
}
8 changes: 5 additions & 3 deletions tests/csv_test/csv_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#define UT_RUN_TIME_ONLY

#include <deque>
#include <map>
#include <unordered_map>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/csv/read.hpp"
#include "glaze/csv/write.hpp"
#include "glaze/record/recorder.hpp"

// Specification: https://datatracker.ietf.org/doc/html/rfc4180

using namespace boost::ut;
using namespace ut;

struct my_struct
{
Expand Down Expand Up @@ -587,4 +589,4 @@ suite fish_record = [] {
};
};

int main() { return boost::ut::cfg<>.run({.report_errors = true}); }
int main() { return 0; }
6 changes: 4 additions & 2 deletions tests/eigen_test/eigen_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Glaze Library
// For the license information refer to glaze.hpp

#define UT_RUN_TIME_ONLY

#include "glaze/ext/eigen.hpp"

#include <Eigen/Core>
Expand All @@ -10,7 +12,7 @@
#include <iterator>
#include <random>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/binary/beve_to_json.hpp"
#include "glaze/json/json_ptr.hpp"
#include "glaze/json/ptr.hpp"
Expand All @@ -19,7 +21,7 @@

int main()
{
using namespace boost::ut;
using namespace ut;
"write_json"_test = [] {
Eigen::Matrix<double, 2, 2> m{};
m << 5, 1, 1, 7;
Expand Down
13 changes: 6 additions & 7 deletions tests/exceptions_test/exceptions_test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Glaze Library
// For the license information refer to glaze.hpp

#include "boost/ut.hpp"
#define UT_RUN_TIME_ONLY

#include "ut/ut.hpp"
#include "glaze/glaze_exceptions.hpp"
#include "glaze/thread/threadpool.hpp"

using namespace boost::ut;
using namespace ut;

struct my_struct
{
Expand Down Expand Up @@ -48,7 +50,7 @@ suite starter = [] {
};

suite basic_types = [] {
using namespace boost::ut;
using namespace ut;

"double write"_test = [] {
std::string buffer{};
Expand Down Expand Up @@ -160,8 +162,5 @@ suite read_file_test = [] {

int main()
{
// Explicitly run registered test suites and report errors
// This prevents potential issues with thread local variables
const auto result = boost::ut::cfg<>.run({.report_errors = true});
return result;
return 0;
}
28 changes: 14 additions & 14 deletions tests/json_conformance/json_conformance.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#define UT_RUN_TIME_ONLY

#include <deque>
#include <iostream>
#include <map>
#include <random>
#include <unordered_map>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/glaze.hpp"

using namespace boost::ut;
using namespace ut;

using sv = glz::sv;

Expand Down Expand Up @@ -110,7 +112,7 @@ inline void should_fail()

if constexpr (Opts.force_conformance) {
// TODO: Add force_conformance testing after parse
skip / "comma after close"_test = [] {
/*skip / "comma after close"_test = [] {
constexpr sv s = R"(["Comma after the close"],)";
{
std::vector<std::string> v;
Expand All @@ -132,7 +134,7 @@ inline void should_fail()
bool_object obj{};
expect(glz::read_json(obj, s));
}
};
};*/
}

"illegal expression"_test = [] {
Expand Down Expand Up @@ -160,7 +162,7 @@ inline void should_fail()
};

// TODO: Support this error in all cases
skip / "numbers cannot have leading zeroes"_test = [] {
/*skip / "numbers cannot have leading zeroes"_test = [] {
constexpr sv s = R"({"i": 013})";
{
int_object obj{};
Expand All @@ -170,7 +172,7 @@ inline void should_fail()
glz::json_t obj{};
expect(glz::read_json(obj, s));
}
};
};*/

"numbers cannot be hex"_test = [] {
constexpr sv s = R"({"i": 0x14})";
Expand Down Expand Up @@ -289,7 +291,7 @@ inline void should_fail()
};

// TODO: This should be an error
skip / "0e"_test = [] {
/*skip / "0e"_test = [] {
constexpr sv s = R"(0e)";
{
double v{};
Expand All @@ -303,9 +305,9 @@ inline void should_fail()
int v{};
expect(glz::read_json(v, s));
}
};
};*/

skip / "0e+"_test = [] {
/*skip / "0e+"_test = [] {
constexpr sv s = R"(0e+)";
{
double v{};
Expand All @@ -319,7 +321,7 @@ inline void should_fail()
int v{};
expect(glz::read_json(v, s));
}
};
};*/
}

template <glz::opts Opts>
Expand Down Expand Up @@ -362,8 +364,6 @@ suite json_conformance = [] {
};

int main()
{ // Explicitly run registered test suites and report errors
// This prevents potential issues with thread local variables
const auto result = boost::ut::cfg<>.run({.report_errors = true});
return result;
{
return 0;
}
12 changes: 6 additions & 6 deletions tests/json_performance/json_performance.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#define UT_RUN_TIME_ONLY

#include <deque>
#include <iostream>
#include <map>
#include <random>
#include <unordered_map>

#include "boost/ut.hpp"
#include "ut/ut.hpp"
#include "glaze/glaze.hpp"

using namespace boost::ut;
using namespace ut;

std::mt19937 gen{};

Expand Down Expand Up @@ -64,8 +66,6 @@ suite string_performance = [] {
};

int main()
{ // Explicitly run registered test suites and report errors
// This prevents potential issues with thread local variables
const auto result = boost::ut::cfg<>.run({.report_errors = true});
return result;
{
return 0;
}
Loading