From a94cd677bd876fffcad5323477bb24a2b8ee31c3 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 13 Apr 2021 16:05:08 +1000 Subject: [PATCH] tap: use fmtlib specifiers --- tap.hpp | 11 +++++++---- test/affine.cpp | 6 +++--- test/algo/sort.cpp | 2 +- test/alloc/aligned/direct.cpp | 2 +- test/alloc/aligned/foreign.cpp | 2 +- test/ascii.cpp | 2 +- test/cmdopt.cpp | 8 ++++---- test/coord.cpp | 2 +- test/encode/base.cpp | 4 ++-- test/encode/number.cpp | 6 ++++-- test/exe.cpp | 2 +- test/fixed.cpp | 20 ++++++++++---------- test/format.cpp | 4 ++-- test/geom/aabb.cpp | 2 +- test/geom/ellipse.cpp | 6 +++--- test/geom/frustum.cpp | 2 +- test/geom/line.cpp | 2 +- test/geom/plane.cpp | 2 +- test/geom/sample/edge.cpp | 4 ++-- test/geom/sample/subregion.cpp | 2 +- test/geom/segment.cpp | 6 +++--- test/geom/sphere.cpp | 2 +- test/hash/checksum.cpp | 4 ++-- test/hash/crc.cpp | 2 +- test/hash/fasthash.cpp | 4 ++-- test/hash/fnv1a.cpp | 4 ++-- test/hash/murmur.cpp | 12 ++++++------ test/hash/siphash.cpp | 2 +- test/hash/table.cpp | 4 ++-- test/hash/xxhash.cpp | 4 ++-- test/introspection.cpp | 1 + test/iterator.cpp | 2 +- test/job/queue.cpp | 2 +- test/maths.cpp | 4 ++-- test/maths/fast.cpp | 6 +++--- test/matrix.cpp | 2 +- test/parallel/queue.cpp | 5 +++-- test/parallel/stack.cpp | 2 +- test/parse/si.cpp | 2 +- test/parse/time.cpp | 2 +- test/polynomial.cpp | 2 +- test/quaternion.cpp | 6 +++--- test/rand/buckets.cpp | 2 +- test/region.cpp | 12 ++++++------ test/roots/bisection.cpp | 2 +- test/string.cpp | 14 +++++++------- test/thread/spinlock.cpp | 2 +- test/time/8601.cpp | 4 ++-- test/uri.cpp | 22 +++++++++++----------- test/utf8.cpp | 14 +++++++------- test/vector.cpp | 14 +++++++------- test/version.cpp | 8 ++++---- test/view.cpp | 2 +- 53 files changed, 137 insertions(+), 130 deletions(-) diff --git a/tap.hpp b/tap.hpp index 2e49fa68..f2b8591c 100644 --- a/tap.hpp +++ b/tap.hpp @@ -9,8 +9,10 @@ #pragma once #include "except.hpp" -#include "format.hpp" #include "maths.hpp" +#include "debug/validate.hpp" + +#include #include #include @@ -50,10 +52,11 @@ namespace cruft::TAP { bool expect (const bool test, const char (&fmt)[N], Args&&... args) { + CHECK (!strstr (fmt, "%")); m_output << (test ? "ok " : "not ok ") << ++m_size - << " - " - << format::printf (fmt) (std::forward (args)...) - << std::endl; + << " - "; + fmt::print (m_output, fmt, std::forward (args)...); + m_output << std::endl; if (!test) m_status = EXIT_FAILURE; diff --git a/test/affine.cpp b/test/affine.cpp index c1241fd1..6f514c61 100644 --- a/test/affine.cpp +++ b/test/affine.cpp @@ -138,7 +138,7 @@ test_perspective (cruft::TAP::logger &tap) tap.expect ( cruft::relatively_equal (m, p, 1e-7f), - "perspective %!:%!@%!", + "perspective {}:{}@{}", t.w, t.h, t.fov ); } @@ -163,7 +163,7 @@ test_mq_axis (cruft::TAP::logger &tap) auto q = cruft::quaternionf::angle_axis (1, t.euler); auto diff = sum (abs (m - q.as_matrix ())); - tap.expect_le (diff, 1e-6f, "matrix/quaternion rotation identities, %s", t.msg); + tap.expect_le (diff, 1e-6f, "matrix/quaternion rotation identities, {:s}", t.msg); } } @@ -197,7 +197,7 @@ test_mq_euler (cruft::TAP::logger &tap) ).as_matrix (); auto diff = cruft::sum (abs (m - q)); - tap.expect_le (diff, 1e-6f, "matrix-quaternion xyz euler rotations, %s", t.msg); + tap.expect_le (diff, 1e-6f, "matrix-quaternion xyz euler rotations, {:s}", t.msg); } } diff --git a/test/algo/sort.cpp b/test/algo/sort.cpp index f98efaf7..4d1fcac1 100644 --- a/test/algo/sort.cpp +++ b/test/algo/sort.cpp @@ -89,7 +89,7 @@ main (int, char**) [] (int a, int b) { return a < b; } ); - tap.expect (std::is_sorted (std::cbegin (t.values), std::cend (t.values)), "%s", t.msg); + tap.expect (std::is_sorted (std::cbegin (t.values), std::cend (t.values)), "{:s}", t.msg); } // Check that SOA sort works with multiple value arrays diff --git a/test/alloc/aligned/direct.cpp b/test/alloc/aligned/direct.cpp index 64cd3b84..50fa85fb 100644 --- a/test/alloc/aligned/direct.cpp +++ b/test/alloc/aligned/direct.cpp @@ -41,7 +41,7 @@ main (int, char**) !(result[2] % alignment) && !(result[3] % alignment), - "allocations make alignment of %zu", alignment + "allocations make alignment of {}", alignment ); return tap.status (); diff --git a/test/alloc/aligned/foreign.cpp b/test/alloc/aligned/foreign.cpp index fa108853..14a517c8 100644 --- a/test/alloc/aligned/foreign.cpp +++ b/test/alloc/aligned/foreign.cpp @@ -47,7 +47,7 @@ main () for (const auto &t: TESTS) { auto ptr = reinterpret_cast (alloc.allocate (t.size).data ()); auto offset = ptr - reinterpret_cast (base); - tap.expect_mod (offset, alignment, "%s", t.message); + tap.expect_mod (offset, alignment, "{:s}", t.message); } return tap.status (); diff --git a/test/ascii.cpp b/test/ascii.cpp index 75067f6b..c837246e 100644 --- a/test/ascii.cpp +++ b/test/ascii.cpp @@ -62,7 +62,7 @@ main (int, char**) tap.expect ( is_digit && is_hex && is_upper && is_lower && is_space && integer && hexadecimal, - "%s", t.msg + "{:s}", t.msg ); } diff --git a/test/cmdopt.cpp b/test/cmdopt.cpp index ce8bb883..5789bd1b 100644 --- a/test/cmdopt.cpp +++ b/test/cmdopt.cpp @@ -85,13 +85,13 @@ test_bool (cruft::TAP::logger &tap) for (auto i: positive) { argv[2] = i; p.scan (argv.size (), argv.data ()); - tap.expect_eq (value, true, "read bool, %s", i); + tap.expect_eq (value, true, "read bool, {:s}", i); } for (auto i: negative) { argv[2] = i; p.scan (argv.size (), argv.data ()); - tap.expect_eq (value, false, "read bool, %s", i); + tap.expect_eq (value, false, "read bool, {:s}", i); } // Check that invalid forms of boolean all throw exceptions @@ -101,7 +101,7 @@ test_bool (cruft::TAP::logger &tap) argv[2] = i; tap.expect_throw ([&] () { p.scan (argv.size (), argv.data ()); - }, "invalid bool, %s", i); + }, "invalid bool, {:s}", i); } } @@ -187,7 +187,7 @@ test_bytes (cruft::TAP::logger &tap) argv[2] = i.str; p.scan (std::size (argv), argv); - tap.expect_eq (i.val, size, "bytes, %s", i.str); + tap.expect_eq (i.val, size, "bytes, {:s}", i.str); }; } diff --git a/test/coord.cpp b/test/coord.cpp index ba238d84..79cd03c5 100644 --- a/test/coord.cpp +++ b/test/coord.cpp @@ -143,7 +143,7 @@ main (void) }; for (auto const &t: TESTS) - tap.expect (cruft::coord::element_ordering (t.a, t.b) == t.expected, "ordering; %!", t.message); + tap.expect (cruft::coord::element_ordering (t.a, t.b) == t.expected, "ordering; {}", t.message); } return tap.status (); diff --git a/test/encode/base.cpp b/test/encode/base.cpp index af5e5c4e..038c97e5 100644 --- a/test/encode/base.cpp +++ b/test/encode/base.cpp @@ -84,7 +84,7 @@ test_size (cruft::TAP::logger &tap) tap.expect_eq ( encoded, output_v[i], - "%! character base%! encode; '%!' is '%!'", i, Size, encoded, output_v[i] + "{} character base{} encode; '{}' is '{}'", i, Size, encoded, output_v[i] ); @@ -94,7 +94,7 @@ test_size (cruft::TAP::logger &tap) cruft::make_view (encoded) ); - tap.expect_eq (decoded, fragment, "%! character base%! decode, '%!'", i, Size, decoded); + tap.expect_eq (decoded, fragment, "{} character base{} decode, '{}'", i, Size, decoded); } } diff --git a/test/encode/number.cpp b/test/encode/number.cpp index 6984615f..9248dda3 100644 --- a/test/encode/number.cpp +++ b/test/encode/number.cpp @@ -1,6 +1,8 @@ #include "encode/number.hpp" #include "tap.hpp" +#include + int main () { @@ -22,7 +24,7 @@ int main () for (auto const &t: TESTS) { // decode the truth string and test against the truth number cruft::view src (t.str); - tap.expect_eq (cruft::encode::decode36 (src), t.value, "base36 decode '%!'", t.str); + tap.expect_eq (cruft::encode::decode36 (src), t.value, "base36 decode '{}'", t.str); // encode the truth number std::ostringstream dst; @@ -35,7 +37,7 @@ int main () std::transform (encoded_truth.begin (), encoded_truth.end (), encoded_truth.begin (), ::tolower); // compare lower case encoded strings - tap.expect_eq (encoded_computed, encoded_truth, "base36 encode '%!'", t.value); + tap.expect_eq (encoded_computed, encoded_truth, "base36 encode '{}'", t.value); } return tap.status (); diff --git a/test/exe.cpp b/test/exe.cpp index 84cee43c..70db28a6 100644 --- a/test/exe.cpp +++ b/test/exe.cpp @@ -22,7 +22,7 @@ main (int, char **argv) tap.expect_eq ( query.stem (), truth.stem (), - "identify executable path # %!", query + "identify executable path # {}", query ); return tap.status (); diff --git a/test/fixed.cpp b/test/fixed.cpp index f65319da..bb3b4abb 100644 --- a/test/fixed.cpp +++ b/test/fixed.cpp @@ -20,19 +20,19 @@ test_simple (cruft::TAP::logger &tap) std::ostringstream os; os << "fixed<" << type_to_string () << ',' << I << ',' << E << '>'; - tap.expect_eq (lo, lo, "%s self equality", os.str ()); - tap.expect_eq (hi, hi, "%s self equality", os.str ()); + tap.expect_eq (lo, lo, "{:s} self equality", os.str ()); + tap.expect_eq (hi, hi, "{:s} self equality", os.str ()); - tap.expect_neq (hi, lo, "%s inequality", os.str ()); - tap.expect_neq (lo, hi, "%s inequality", os.str ()); + tap.expect_neq (hi, lo, "{:s} inequality", os.str ()); + tap.expect_neq (lo, hi, "{:s} inequality", os.str ()); - tap.expect_lt (lo, hi, "%s less than", os.str ()); - tap.expect_le (lo, hi, "%s less than equal", os.str ()); - tap.expect_le (lo, lo, "%s less than equal", os.str ()); + tap.expect_lt (lo, hi, "{:s} less than", os.str ()); + tap.expect_le (lo, hi, "{:s} less than equal", os.str ()); + tap.expect_le (lo, lo, "{:s} less than equal", os.str ()); - tap.expect_gt (hi, lo, "%s greater than", os.str ()); - tap.expect_ge (lo, lo, "%s greater than equal", os.str ()); - tap.expect_ge (hi, lo, "%s greater than equal", os.str ()); + tap.expect_gt (hi, lo, "{:s} greater than", os.str ()); + tap.expect_ge (lo, lo, "{:s} greater than equal", os.str ()); + tap.expect_ge (hi, lo, "{:s} greater than equal", os.str ()); } diff --git a/test/format.cpp b/test/format.cpp index 582cde6c..e7126b19 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -21,7 +21,7 @@ main (void) #define CHECK_RENDER(fmt,res,...) do { \ auto val = to_string (cruft::format::printf (fmt)(__VA_ARGS__)); \ - tap.expect_eq (val, res, "render '%!', # %! == %!", fmt, val, res); \ + tap.expect_eq (val, res, "render '{}', # {} == {}", fmt, val, res); \ } while (0) CHECK_RENDER ("foo", "foo"); @@ -182,7 +182,7 @@ main (void) #define CHECK_THROW(fmt,except,...) do { \ tap.expect_throw ([&] { \ to_string (cruft::format::printf (fmt)(__VA_ARGS__)); \ - }, "exception '%s' for format '%s'", #except, fmt); \ + }, "exception '{:s}' for format '{:s}'", #except, fmt); \ } while (0) CHECK_THROW("%", syntax_error); diff --git a/test/geom/aabb.cpp b/test/geom/aabb.cpp index be509dba..364281f9 100644 --- a/test/geom/aabb.cpp +++ b/test/geom/aabb.cpp @@ -48,7 +48,7 @@ main (int, char**) for (auto const &t: TESTS) { cruft::geom::aabb2f const shape (t.lo, t.hi); cruft::geom::ray2f const r {t.base, t.direction}; - tap.expect_eq (distance (r, shape), t.distance, "%!", t.message); + tap.expect_eq (distance (r, shape), t.distance, "{}", t.message); } }; diff --git a/test/geom/ellipse.cpp b/test/geom/ellipse.cpp index 0bfa51ca..7d6b5e54 100644 --- a/test/geom/ellipse.cpp +++ b/test/geom/ellipse.cpp @@ -39,7 +39,7 @@ test_intersection (cruft::TAP::logger &tap) }; for (auto const& t: TESTS) { - tap.expect_eq (t.distance, distance (t.caster, t.shape), "%s", t.message); + tap.expect_eq (t.distance, distance (t.caster, t.shape), "{:s}", t.message); } } @@ -57,7 +57,7 @@ test_area (cruft::TAP::logger &tap) for (auto const& t: TESTS) { auto found = area (t.shape); - tap.expect (cruft::relatively_equal (found, t.value, 1.08e-2f), "%!", t.message); + tap.expect (cruft::relatively_equal (found, t.value, 1.08e-2f), "{}", t.message); } } @@ -105,7 +105,7 @@ test_cover (cruft::TAP::logger &tap) return intersects (shape, p); }); - tap.expect (success, "%!", t.message); + tap.expect (success, "{}", t.message); } } diff --git a/test/geom/frustum.cpp b/test/geom/frustum.cpp index 0f498ff8..2fe481d4 100644 --- a/test/geom/frustum.cpp +++ b/test/geom/frustum.cpp @@ -29,7 +29,7 @@ main () }; for (const auto &t: TESTS) { - tap.expect_eq (intersects (origin90, t.box), t.intersects, "origin frustrum, %s", t.message); + tap.expect_eq (intersects (origin90, t.box), t.intersects, "origin frustrum, {:s}", t.message); } return tap.status (); diff --git a/test/geom/line.cpp b/test/geom/line.cpp index 9fdd7e95..76077097 100644 --- a/test/geom/line.cpp +++ b/test/geom/line.cpp @@ -21,7 +21,7 @@ main (int, char**) for (auto const& t: TESTS) { cruft::geom::line3f l { t.origin, t.direction }; auto d = distance2 (l, t.q); - tap.expect_eq (d, t.distance, "%!", t.message); + tap.expect_eq (d, t.distance, "{}", t.message); } return tap.status (); diff --git a/test/geom/plane.cpp b/test/geom/plane.cpp index 851bcb73..9e966661 100644 --- a/test/geom/plane.cpp +++ b/test/geom/plane.cpp @@ -20,7 +20,7 @@ test_distances (cruft::TAP::logger &tap) for (auto const &t: TESTS) { auto const p = cruft::geom::make_plane (t.a, t.b, t.c); const auto d = distance (p, t.query); - tap.expect_eq (d, t.distance, "%!", t.message); + tap.expect_eq (d, t.distance, "{}", t.message); } }; diff --git a/test/geom/sample/edge.cpp b/test/geom/sample/edge.cpp index 49057459..9762d121 100644 --- a/test/geom/sample/edge.cpp +++ b/test/geom/sample/edge.cpp @@ -26,7 +26,7 @@ int main () bool const y_perim = pos.y == 0 || pos.y == AREA.h; if (!x_perim && !y_perim) { - tap.fail ("position %! falls outside perimeter: %!", i, pos); + tap.fail ("position {} falls outside perimeter: {}", i, pos); return tap.status (); } @@ -54,7 +54,7 @@ int main () tap.expect_lt ( std::abs (rel_diff), 0.05f, - "occurence counts are evenly spaced: %!:%! vs %!:%!", + "occurence counts are evenly spaced: {}:{} vs {}:{}", hi->first, hi->second, lo->first, lo->second ); diff --git a/test/geom/sample/subregion.cpp b/test/geom/sample/subregion.cpp index aee65bd1..c59d73f7 100644 --- a/test/geom/sample/subregion.cpp +++ b/test/geom/sample/subregion.cpp @@ -40,7 +40,7 @@ main () } } - tap.expect (success, "subregion coverage validity, %!", msg); + tap.expect (success, "subregion coverage validity, {}", msg); } return tap.status (); diff --git a/test/geom/segment.cpp b/test/geom/segment.cpp index b37e0a00..bc441b91 100644 --- a/test/geom/segment.cpp +++ b/test/geom/segment.cpp @@ -22,7 +22,7 @@ void test_point_distance (cruft::TAP::logger &tap) for (auto const& t: TESTS) { cruft::geom::segment3f s {t.a, t.b}; auto d = distance (s, t.q); - tap.expect_eq (d, t.distance, "%!", t.message); + tap.expect_eq (d, t.distance, "{}", t.message); } } @@ -65,7 +65,7 @@ void test_region_intersection (cruft::TAP::logger &tap) }; for (auto const &t: TESTS) - tap.expect_eq (intersects (t.a, t.b), t.expected, "region intersection: %!", t.message); + tap.expect_eq (intersects (t.a, t.b), t.expected, "region intersection: {}", t.message); } @@ -108,7 +108,7 @@ void test_bresenham (cruft::TAP::logger &tap) std::vector computed; for (auto const p: cruft::geom::bresenham ({ t.a, t.b })) computed.push_back (p); - tap.expect_eq (computed, t.expected, "bresenham: %!", t.message); + tap.expect_eq (computed, t.expected, "bresenham: {}", t.message); } } diff --git a/test/geom/sphere.cpp b/test/geom/sphere.cpp index 88a1c68a..eccd2770 100644 --- a/test/geom/sphere.cpp +++ b/test/geom/sphere.cpp @@ -45,7 +45,7 @@ test_intersect (cruft::TAP::logger &tap) }; for (const auto &[d,s,r,msg]: TESTS) { - tap.expect_eq (d, distance (r, s), "%!", msg); + tap.expect_eq (d, distance (r, s), "{}", msg); } } diff --git a/test/hash/checksum.cpp b/test/hash/checksum.cpp index a338bb50..7a4aa97d 100644 --- a/test/hash/checksum.cpp +++ b/test/hash/checksum.cpp @@ -40,13 +40,13 @@ main (int, char**) { tap.expect_eq ( t.adler, a (cruft::view {t.data}.template cast ()), - "adler checksum: %s", t.msg + "adler checksum: {:s}", t.msg ); tap.expect_eq ( t.bsd, b (cruft::view {t.data}.template cast ()), - "bsdsum checksum: %s", t.msg); + "bsdsum checksum: {:s}", t.msg); } return tap.status (); diff --git a/test/hash/crc.cpp b/test/hash/crc.cpp index d1ab4c7f..a1027eab 100644 --- a/test/hash/crc.cpp +++ b/test/hash/crc.cpp @@ -34,7 +34,7 @@ main (int, char**) for (const auto &t: TESTS) { #define TEST(KLASS) do { \ auto computed = cruft::hash::KLASS{}(cruft::view {t.dat}.template cast ()); \ - tap.expect_eq (t.result.KLASS, computed, "%s: %s", #KLASS, t.msg); \ + tap.expect_eq (t.result.KLASS, computed, "{:s}: {:s}", #KLASS, t.msg); \ } while (0) TEST(crc32); diff --git a/test/hash/fasthash.cpp b/test/hash/fasthash.cpp index 817509e2..bb4719ed 100644 --- a/test/hash/fasthash.cpp +++ b/test/hash/fasthash.cpp @@ -47,8 +47,8 @@ main (void) for (const auto &t: TESTS) { cruft::view data { t.data }; - tap.expect_eq (t.hash32, h32 (t.seed32, data.cast ()), "h32(%0" PRIx32 ")", t.seed32); - tap.expect_eq (t.hash64, h64 (t.seed64, data.cast ()), "h64(%0" PRIx64 ")", t.seed64); + tap.expect_eq (t.hash32, h32 (t.seed32, data.cast ()), "h32({:#04x})", t.seed32); + tap.expect_eq (t.hash64, h64 (t.seed64, data.cast ()), "h64({:#08x})", t.seed64); } tap.expect (success32, "fasthash32"); diff --git a/test/hash/fnv1a.cpp b/test/hash/fnv1a.cpp index 706642fa..9178aa50 100644 --- a/test/hash/fnv1a.cpp +++ b/test/hash/fnv1a.cpp @@ -24,8 +24,8 @@ main (void) const cruft::hash::fnv1a h64; for (const auto &t: TESTS) { - tap.expect_eq (h32 (cruft::view{t.data}.cast ()), t.h32, "fnv1a32: '%s'", t.data); - tap.expect_eq (h64 (cruft::view{t.data}.cast ()), t.h64, "fnv1a64: '%s'", t.data); + tap.expect_eq (h32 (cruft::view{t.data}.cast ()), t.h32, "fnv1a32: '{:s}'", t.data); + tap.expect_eq (h64 (cruft::view{t.data}.cast ()), t.h64, "fnv1a64: '{:s}'", t.data); } return tap.status (); diff --git a/test/hash/murmur.cpp b/test/hash/murmur.cpp index 800a1a01..d9ed50db 100644 --- a/test/hash/murmur.cpp +++ b/test/hash/murmur.cpp @@ -124,13 +124,13 @@ test (cruft::TAP::logger &tap) const cruft::hash::murmur3_128_x86 h3_x86 (t.m3_128_x86.seed); const cruft::hash::murmur3_128_x64 h3_x64 (t.m3_128_x64.seed); - tap.expect_eq (h1 (t.data), t.m1_32.hash, "murmur1_32, '%s'", t.msg); - tap.expect_eq (h2_32 (t.data), t.m2_32.hash, "murmur2_32, '%s'", t.msg); - tap.expect_eq (h2_64 (t.data), t.m2_64.hash, "murmur2_64, '%s'", t.msg); + tap.expect_eq (h1 (t.data), t.m1_32.hash, "murmur1_32, '{:s}'", t.msg); + tap.expect_eq (h2_32 (t.data), t.m2_32.hash, "murmur2_32, '{:s}'", t.msg); + tap.expect_eq (h2_64 (t.data), t.m2_64.hash, "murmur2_64, '{:s}'", t.msg); - tap.expect_eq (h3 (t.data), t.m3_32.hash, "murmur3_32, '%s'", t.msg); - tap.expect_eq (h3_x86 (t.data), t.m3_128_x86.hash, "murmur3_128_x86, '%s'", t.msg); - tap.expect_eq (h3_x64 (t.data), t.m3_128_x64.hash, "murmur3_128_x64, '%s'", t.msg); + tap.expect_eq (h3 (t.data), t.m3_32.hash, "murmur3_32, '{:s}'", t.msg); + tap.expect_eq (h3_x86 (t.data), t.m3_128_x86.hash, "murmur3_128_x86, '{:s}'", t.msg); + tap.expect_eq (h3_x64 (t.data), t.m3_128_x64.hash, "murmur3_128_x64, '{:s}'", t.msg); } } diff --git a/test/hash/siphash.cpp b/test/hash/siphash.cpp index 8ef10a5c..b5cd800a 100644 --- a/test/hash/siphash.cpp +++ b/test/hash/siphash.cpp @@ -30,7 +30,7 @@ main () for (const auto &t: TESTS) { cruft::hash::siphash<2,4> h (t.key); - tap.expect_eq (h (t.data), t.digest, "%s", t.message); + tap.expect_eq (h (t.data), t.digest, "{:s}", t.message); } return tap.status (); diff --git a/test/hash/table.cpp b/test/hash/table.cpp index a0ceaf81..2c4576ea 100644 --- a/test/hash/table.cpp +++ b/test/hash/table.cpp @@ -35,7 +35,7 @@ void test_type (cruft::TAP::logger &tap) auto const pos = std::adjacent_find (std::begin (results), std::end (results)); tap.expect ( pos == std::end (results), - "no equal elements, %!", + "no equal elements, {}", cruft::introspection::name::bare () ); } @@ -62,7 +62,7 @@ void test_type (cruft::TAP::logger &tap) tap.expect ( success, - "equal counts at bit positions, %!", + "equal counts at bit positions, {}", cruft::introspection::name::bare () ); } diff --git a/test/hash/xxhash.cpp b/test/hash/xxhash.cpp index ad31f033..4f2c30d6 100644 --- a/test/hash/xxhash.cpp +++ b/test/hash/xxhash.cpp @@ -52,8 +52,8 @@ main (int, char **) cruft::hash::xxhash32 h32 (t.seed); cruft::hash::xxhash64 h64 (t.seed); - tap.expect_eq (h32 (t.data), t.hash32, "xxhash32 %s", t.msg); - tap.expect_eq (h64 (t.data), t.hash64, "xxhash64 %s, seed %!", t.msg, t.seed); + tap.expect_eq (h32 (t.data), t.hash32, "xxhash32 {:s}", t.msg); + tap.expect_eq (h64 (t.data), t.hash64, "xxhash64 {:s}, seed {}", t.msg, t.seed); } return tap.status (); diff --git a/test/introspection.cpp b/test/introspection.cpp index f56cd0c7..759553f5 100644 --- a/test/introspection.cpp +++ b/test/introspection.cpp @@ -2,6 +2,7 @@ #include "introspection/name.hpp" #include "introspection/type.hpp" #include "std.hpp" +#include "view.hpp" #include "tap.hpp" #include diff --git a/test/iterator.cpp b/test/iterator.cpp index 068da08d..f019edd3 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -45,7 +45,7 @@ test_iota (cruft::TAP::logger &tap) { cruft::iterator::iota seq (5); auto const sum = std::accumulate (std::begin (seq), std::end (seq), 0u); - tap.expect_eq (sum, 4u+3u+2u+1u+0u, "iota summation %!", sum); + tap.expect_eq (sum, 4u+3u+2u+1u+0u, "iota summation {}", sum); } diff --git a/test/job/queue.cpp b/test/job/queue.cpp index dcfd278b..9c83a865 100644 --- a/test/job/queue.cpp +++ b/test/job/queue.cpp @@ -45,6 +45,6 @@ main (void) success = count == INNER && success; } - tap.expect (success, "%! trivial increment jobs of size %!", OUTTER, INNER); + tap.expect (success, "{} trivial increment jobs of size {}", OUTTER, INNER); return tap.status (); } \ No newline at end of file diff --git a/test/maths.cpp b/test/maths.cpp index c3ece3ea..287212fe 100644 --- a/test/maths.cpp +++ b/test/maths.cpp @@ -135,8 +135,8 @@ test_normalisations (cruft::TAP::logger &tap) }; for (const auto &t: TESTS) { - tap.expect_eq (cruft::renormalise (t.sint), t.uint, "%s s32-to-u32", t.msg); - tap.expect_eq (cruft::renormalise (t.uint), t.sint, "%s u32-to-s32", t.msg); + tap.expect_eq (cruft::renormalise (t.sint), t.uint, "{:s} s32-to-u32", t.msg); + tap.expect_eq (cruft::renormalise (t.uint), t.sint, "{:s} u32-to-s32", t.msg); } } } diff --git a/test/maths/fast.cpp b/test/maths/fast.cpp index 4a01b28b..c8e224f8 100644 --- a/test/maths/fast.cpp +++ b/test/maths/fast.cpp @@ -87,11 +87,11 @@ main () // // const float relerr = 1 - observed / expected; // std::cout << observed << '\t' << expected << '\t' << relerr << '\n'; - // tap.expect_lt (relerr, 1e-4f, "relative exp(%!) error", i); + // tap.expect_lt (relerr, 1e-4f, "relative exp({}) error", i); //} - tap.expect_eq (successes.sin, std::size (sins), "sin evaluation, %!/%!", successes.sin, std::size (sins)); - tap.expect_eq (successes.exp, std::size (exps), "exp evaluation, %!/%!", successes.exp, std::size (exps)); + tap.expect_eq (successes.sin, std::size (sins), "sin evaluation, {}/{}", successes.sin, std::size (sins)); + tap.expect_eq (successes.exp, std::size (exps), "exp evaluation, {}/{}", successes.exp, std::size (exps)); return tap.status (); } diff --git a/test/matrix.cpp b/test/matrix.cpp index e6ef6dbc..03a237ef 100644 --- a/test/matrix.cpp +++ b/test/matrix.cpp @@ -214,7 +214,7 @@ main (void) truth, euler, [] (auto a, auto b) { return cruft::almost_equal (a, b); } )), - "matrix-to-euler, %s", + "matrix-to-euler, {:s}", t.msg ); } diff --git a/test/parallel/queue.cpp b/test/parallel/queue.cpp index 8b9cae0e..20224953 100644 --- a/test/parallel/queue.cpp +++ b/test/parallel/queue.cpp @@ -1,8 +1,9 @@ +#include "tap.hpp" + #include "parallel/queue.hpp" #include "thread/flag.hpp" #include "thread/semaphore.hpp" - -#include "tap.hpp" +#include "view.hpp" #include diff --git a/test/parallel/stack.cpp b/test/parallel/stack.cpp index e2b2ed44..ec0d2e57 100644 --- a/test/parallel/stack.cpp +++ b/test/parallel/stack.cpp @@ -66,7 +66,7 @@ int main () for (auto &t: contestants) t.join (); - tap.expect (true, "n-way fight, %! contestants", contestants.size ()); + tap.expect (true, "n-way fight, {} contestants", contestants.size ()); } return tap.status (); diff --git a/test/parse/si.cpp b/test/parse/si.cpp index 73ad0a70..337adcde 100644 --- a/test/parse/si.cpp +++ b/test/parse/si.cpp @@ -25,7 +25,7 @@ int main () if (!res) { tap.fail ("SI parsing %!", t.str); } else { - tap.expect_eq (t.val, *res, "SI parsing '%!'", t.str); + tap.expect_eq (t.val, *res, "SI parsing '{}'", t.str); } } diff --git a/test/parse/time.cpp b/test/parse/time.cpp index 666f3458..bb40431c 100644 --- a/test/parse/time.cpp +++ b/test/parse/time.cpp @@ -37,7 +37,7 @@ int main () for (auto const &[str,val,msg]: TESTS) { auto res = cruft::parse::duration::from (str); - tap.expect (res && val == *res, "%! %! == %!", msg, val.count (), res->count()); + tap.expect (res && val == *res, "{} {} == {}", msg, val.count (), res->count()); } return tap.status (); diff --git a/test/polynomial.cpp b/test/polynomial.cpp index 0428e630..ccf740f0 100644 --- a/test/polynomial.cpp +++ b/test/polynomial.cpp @@ -51,7 +51,7 @@ main (int, char**) ok = false; } - tap.expect (ok, "%s", i.name); + tap.expect (ok, "{:s}", i.name); } return tap.status (); diff --git a/test/quaternion.cpp b/test/quaternion.cpp index dfcf448d..f4ba1e89 100644 --- a/test/quaternion.cpp +++ b/test/quaternion.cpp @@ -89,7 +89,7 @@ main (void) auto m = cruft::rotation (r.mag, r.axis); auto diff = cruft::abs (q - m); - tap.expect_lt (cruft::sum (diff), 1e-6f, "single basis rotation %zu", i); + tap.expect_lt (cruft::sum (diff), 1e-6f, "single basis rotation {:d}", i); } auto q = quaternionf::identity (); @@ -127,7 +127,7 @@ main (void) auto v = rotate (src, q); auto diff = std::abs (cruft::sum (dst - v)); - tap.expect_lt (diff, 1e-06f, "quaternion from-to, %s", t.msg); + tap.expect_lt (diff, 1e-06f, "quaternion from-to, {:s}", t.msg); } } @@ -144,7 +144,7 @@ main (void) tap.expect_eq ( cruft::quaternionf::from_euler ({ t.x, t.y, t.z }), t.expected, - "from_euler: %!", + "from_euler: {}", t.msg ); } diff --git a/test/rand/buckets.cpp b/test/rand/buckets.cpp index 5526148a..3a4e244f 100644 --- a/test/rand/buckets.cpp +++ b/test/rand/buckets.cpp @@ -40,7 +40,7 @@ test_buckets (cruft::TAP::logger &tap, Args&& ...args) std::find_if (std::cbegin (buckets), std::cend (buckets), [] (auto v) { return v < EXPECTED * 7 / 8; }) == std::cend (buckets), - "bucket counts for %s", cruft::introspection::name::full () + "bucket counts for {:s}", cruft::introspection::name::full () ); } diff --git a/test/region.cpp b/test/region.cpp index 2db3a617..3e12a176 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -49,8 +49,8 @@ main (int, char **) }; for (auto const &[a, b, res, msg]: TESTS) { - tap.expect_eq (a.intersects (b), res, "intersection a-on-b: %!", msg); - tap.expect_eq (b.intersects (a), res, "intersection b-on-a: %!", msg); + tap.expect_eq (a.intersects (b), res, "intersection a-on-b: {}", msg); + tap.expect_eq (b.intersects (a), res, "intersection b-on-a: {}", msg); } } @@ -131,7 +131,7 @@ main (int, char **) }; for (auto const &[a, b, expected, msg]: TESTS) - tap.expect_eq (a.covers (b), expected, "covers: %!", msg); + tap.expect_eq (a.covers (b), expected, "covers: {}", msg); } // ensure make_region covers the expected values @@ -185,7 +185,7 @@ main (int, char **) for (auto const &t: TESTS) { auto const d2 = distance2 (t.r, t.p); - tap.expect_eq (d2, t.distance2, "region-point distance2: %!", t.message); + tap.expect_eq (d2, t.distance2, "region-point distance2: {}", t.message); } }; @@ -233,7 +233,7 @@ main (int, char **) }; for (auto const &[a, b, res, message]: TESTS) - tap.expect_eq (intersection (a, b), res, "region-region interesection: %!", message); + tap.expect_eq (intersection (a, b), res, "region-region interesection: {}", message); } // Test rotate behaves as expected. @@ -282,7 +282,7 @@ main (int, char **) for (auto const &obj: TESTS) { auto const computed = rotate90 (orig, obj.rotation); - tap.expect_eq (computed, obj.res, "%! rotation", obj.rotation); + tap.expect_eq (computed, obj.res, "{} rotation", obj.rotation); } } diff --git a/test/roots/bisection.cpp b/test/roots/bisection.cpp index 44ca9650..a81e1665 100644 --- a/test/roots/bisection.cpp +++ b/test/roots/bisection.cpp @@ -33,7 +33,7 @@ main (void) for (const auto &t: TESTS) { constexpr float TOLERANCE = 0.00001f; auto root = cruft::roots::bisection (t.lo, t.hi, t.func, TOLERANCE); - tap.expect_eq (root, t.root, "%s", t.msg); + tap.expect_eq (root, t.root, "{:s}", t.msg); } return tap.status (); diff --git a/test/string.cpp b/test/string.cpp index f3b46959..96fefd68 100644 --- a/test/string.cpp +++ b/test/string.cpp @@ -26,8 +26,8 @@ test_transforms (cruft::TAP::logger &tap) }; for (auto const &[src, upper, lower, msg]: TESTS) { - tap.expect_eq (cruft::to_upper (src), upper, "to_upper, %!", msg); - tap.expect_eq (cruft::to_lower (src), lower, "to_lower, %!", msg); + tap.expect_eq (cruft::to_upper (src), upper, "to_upper, {:s}", msg); + tap.expect_eq (cruft::to_lower (src), lower, "to_lower, {:s}", msg); } } @@ -57,7 +57,7 @@ test_position (cruft::TAP::logger &tap) tap.expect ( pos.line == t.line && pos.column == t.column, - "character_position %!:%!", + "character_position {}:{}", t.line, t.column ); @@ -90,7 +90,7 @@ test_tokeniser (cruft::TAP::logger &tap) cruft::view src { csv.c_str (), csv.size () }; for (auto [tok, expected]: cruft::iterator::zip (cruft::tokeniser (src, ','), TESTS)) { - tap.expect (equal (tok, expected.value), "%s", expected.message); + tap.expect (equal (tok, expected.value), "{:s}", expected.message); } } @@ -164,7 +164,7 @@ test_contains (cruft::TAP::logger &tap) for (auto const &t: TESTS) { cruft::tokeniser tok (t.haystack, t.separator); auto const found = tok.contains (t.needle); - tap.expect_eq (found, t.expected, "%!", t.message); + tap.expect_eq (found, t.expected, "{}", t.message); } } @@ -186,7 +186,7 @@ void test_comparator_less (cruft::TAP::logger &tap) }; for (auto const &t: TESTS) - tap.expect_eq (cmp (t.a, t.b), t.less, "string_less, %!", t.message); + tap.expect_eq (cmp (t.a, t.b), t.less, "string_less, {}", t.message); } @@ -209,7 +209,7 @@ void test_comparator_lower (cruft::TAP::logger &tap) cruft::string::compare::lower cmp; for (auto const &t: TESTS) { - tap.expect_eq (cmp (t.a, t.b), t.equal, "compare::lower, pointers, %!", t.message); + tap.expect_eq (cmp (t.a, t.b), t.equal, "compare::lower, pointers, {}", t.message); } } diff --git a/test/thread/spinlock.cpp b/test/thread/spinlock.cpp index 354812fd..8f54d6f5 100644 --- a/test/thread/spinlock.cpp +++ b/test/thread/spinlock.cpp @@ -53,7 +53,7 @@ main () for (auto &t: contestants) t.join (); - tap.expect (true, "n-way fight, %! contestants", std::thread::hardware_concurrency ()); + tap.expect (true, "n-way fight, {} contestants", std::thread::hardware_concurrency ()); } return tap.status (); diff --git a/test/time/8601.cpp b/test/time/8601.cpp index ff150ecd..aa707c56 100644 --- a/test/time/8601.cpp +++ b/test/time/8601.cpp @@ -16,7 +16,7 @@ main (int, char**) for (const auto &t: BAD) { tap.expect_throw ( [t] () { cruft::time::iso8601::parse (t); }, - "invalid timestamp '%s'", t + "invalid timestamp '{:s}'", t ); } @@ -39,7 +39,7 @@ main (int, char**) for (const auto &t: DECODE) { auto val = cruft::time::iso8601::parse (t.string); - tap.expect_eq (val, t.value, "%s", t.message); + tap.expect_eq (val, t.value, "{:s}", t.message); } tap.expect_eq ( diff --git a/test/uri.cpp b/test/uri.cpp index 14e54b64..eaaaac6f 100644 --- a/test/uri.cpp +++ b/test/uri.cpp @@ -140,18 +140,18 @@ main (void) }; for (auto t: GOOD) { - tap.expect_nothrow ([t] (void) { cruft::uri foo (t.src); }, "nothrow parsing '%s'", t.src); + tap.expect_nothrow ([t] (void) { cruft::uri foo (t.src); }, "nothrow parsing '{:s}'", t.src); cruft::uri u (t.src); - tap.expect_eq (u.scheme (), t.scheme, "scheme for '%s'", t.src); - tap.expect_eq (u.heirarchical (), t.hierarchical, "hierarchical for '%s'", t.src); - tap.expect_eq (u.authority (), t.authority, "authority for '%s'", t.src); - tap.expect_eq (u.host (), t.host, "host for '%s'", t.src); - tap.expect_eq (u.user (), t.user, "user for '%s'", t.src); - tap.expect_eq (u.port (), t.port, "port for '%s'", t.src); - tap.expect_eq (u.path (), t.path, "path for '%s'", t.src); - tap.expect_eq (u.query (), t.query, "query for '%s'", t.src); - tap.expect_eq (u.fragment (), t.fragment, "fragment for '%s'", t.src); + tap.expect_eq (u.scheme (), t.scheme, "scheme for '{:s}'", t.src); + tap.expect_eq (u.heirarchical (), t.hierarchical, "hierarchical for '{:s}'", t.src); + tap.expect_eq (u.authority (), t.authority, "authority for '{:s}'", t.src); + tap.expect_eq (u.host (), t.host, "host for '{:s}'", t.src); + tap.expect_eq (u.user (), t.user, "user for '{:s}'", t.src); + tap.expect_eq (u.port (), t.port, "port for '{:s}'", t.src); + tap.expect_eq (u.path (), t.path, "path for '{:s}'", t.src); + tap.expect_eq (u.query (), t.query, "query for '{:s}'", t.src); + tap.expect_eq (u.fragment (), t.fragment, "fragment for '{:s}'", t.src); } static const char* BAD[] = { @@ -160,7 +160,7 @@ main (void) for (auto i: BAD) tap.expect_throw ( - [i] (void) { cruft::uri foo (i); }, "throw parsing '%s'", i + [i] (void) { cruft::uri foo (i); }, "throw parsing '{:s}'", i ); diff --git a/test/utf8.cpp b/test/utf8.cpp index 1b6c2268..6d51cc1f 100644 --- a/test/utf8.cpp +++ b/test/utf8.cpp @@ -26,7 +26,7 @@ simple_valid (cruft::TAP::logger &tap) #endif }; - static constexpr char fmt[] = "valid length, %s"; + static constexpr char fmt[] = "valid length, {:s}"; for (const auto &t: VALID) { try { @@ -71,7 +71,7 @@ single_boundaries (cruft::TAP::logger &tap) { { 0xF4, 0x90, 0x80, 0x80 }, 0x00110000, "other" }, }; - static constexpr char fmt[] = "single character (%s), %!-byte sequence"; + static constexpr char fmt[] = "single character ({:s}), {}-byte sequence"; for (const auto &t: TESTS) { auto data = cruft::make_view ( @@ -111,7 +111,7 @@ malformed (cruft::TAP::logger &tap) { { 0x80, 0xBF, 0x80, 0xBF }, "continuation sequence" }, }; - static constexpr char fmt[] = "malformed %! byte sequence, %s"; + static constexpr char fmt[] = "malformed {} byte sequence, {:s}"; for (const auto &t: TESTS) { auto data = cruft::make_view ( @@ -179,7 +179,7 @@ malformed (cruft::TAP::logger &tap) { success = false; } } - tap.expect (success, "lonely start characters, %! bytes", t.length); + tap.expect (success, "lonely start characters, {} bytes", t.length); } @@ -197,7 +197,7 @@ malformed (cruft::TAP::logger &tap) tap.expect_throw ( [&data] () { cruft::utf8::decode (data); }, - "%! byte sequence missing the lastbyte", + "{} byte sequence missing the lastbyte", t.size () ); } @@ -217,7 +217,7 @@ malformed (cruft::TAP::logger &tap) tap.expect_throw ( [&data] () { cruft::utf8::decode (data); }, - "impossible %! byte sequence", + "impossible {} byte sequence", t.size () ); } @@ -255,7 +255,7 @@ overlong (cruft::TAP::logger &tap) [&] () { cruft::utf8::decode (data); }, - "overlong %! byte sequence, %s", + "overlong {} byte sequence, {:s}", t.data.size (), t.message ); diff --git a/test/vector.cpp b/test/vector.cpp index f0ebfe63..53e0c4ca 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -51,7 +51,7 @@ test_polar (cruft::TAP::logger &tap) auto in_cart = t.cartesian; auto to_cart = cruft::polar_to_cartesian (t.polar); - tap.expect_lt (norm (in_cart - to_cart), 0.00001f, "%s", t.desc); + tap.expect_lt (norm (in_cart - to_cart), 0.00001f, "{:s}", t.desc); // Compare polar representations. Make sure to normalise them first. auto in_polar = t.polar; @@ -60,7 +60,7 @@ test_polar (cruft::TAP::logger &tap) in_polar[1] = std::fmod (in_polar[1], 2 * cruft::pi); to_polar[1] = std::fmod (to_polar[1], 2 * cruft::pi); - tap.expect_eq (in_polar, to_polar, "%s", t.desc); + tap.expect_eq (in_polar, to_polar, "{:s}", t.desc); } } @@ -89,7 +89,7 @@ test_euler (cruft::TAP::logger &tap) for (auto i: TESTS) { tap.expect_eq (cruft::to_euler (i.dir), i.euler * cruft::pi, - "to euler, %s", i.name); + "to euler, {:s}", i.name); } // check error in round trip through euler angles @@ -100,7 +100,7 @@ test_euler (cruft::TAP::logger &tap) // trig functions reduce precision above almost_equal levels, so we // hard code a fairly low bound here instead. - tap.expect_lt (mag, 1e-7, "euler round-trip error, %s", i.name); + tap.expect_lt (mag, 1e-7, "euler round-trip error, {:s}", i.name); } } @@ -135,7 +135,7 @@ test_spherical (cruft::TAP::logger &tap) for (const auto t: S2C) { tap.expect ( all (abs (cruft::spherical_to_cartesian (t.spherical) - t.cartesian) < 1e-7f), - "%s, spherical-cartesian", + "{:s}, spherical-cartesian", t.message ); } @@ -188,7 +188,7 @@ test_spherical (cruft::TAP::logger &tap) const auto s1 = cruft::canonical_spherical (t.spherical); tap.expect ( all (abs (s0 - s1) < 1e-4f), - "%s, cartesian-spherical", + "{:s}, cartesian-spherical", t.message ); } @@ -197,7 +197,7 @@ test_spherical (cruft::TAP::logger &tap) //tap.expect_eq ( // cruft::cartesian_to_spherical (t.cartesian), // t.spherical, - // "%s, cartesian-spherical", + // "{:s}, cartesian-spherical", // t.message //); diff --git a/test/version.cpp b/test/version.cpp index 86b4565f..ec0809a5 100644 --- a/test/version.cpp +++ b/test/version.cpp @@ -55,7 +55,7 @@ main () { bool parts = std::equal (v.begin (), v.end (), t.parts); bool release = v.release == t.release; - tap.expect (parts && release, "%s", t.msg); + tap.expect (parts && release, "{:s}", t.msg); } @@ -64,9 +64,9 @@ main () { const bool lt = t.a < t.b; const bool gt = t.a > t.b; - tap.expect (t.eq == eq, "%s: equality", t.msg); - tap.expect (t.lt == lt, "%s: less-than", t.msg); - tap.expect (t.gt == gt, "%s: greater-than", t.msg); + tap.expect (t.eq == eq, "{:s}: equality", t.msg); + tap.expect (t.lt == lt, "{:s}: less-than", t.msg); + tap.expect (t.gt == gt, "{:s}: greater-than", t.msg); } return tap.status (); diff --git a/test/view.cpp b/test/view.cpp index a66d9a71..e1f3b86d 100644 --- a/test/view.cpp +++ b/test/view.cpp @@ -73,7 +73,7 @@ main (int, char**) }; for (const auto &t: TESTS) { - tap.expect_eq (cruft::view { t.init }.slice (t.a, t.b), t.result, "slice; %s", t.message); + tap.expect_eq (cruft::view { t.init }.slice (t.a, t.b), t.result, "slice; {:s}", t.message); } }