-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
More module tests #2309
More module tests #2309
Conversation
1a2b2d1
to
d5203d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Having a module test seems like a good idea but I am concerned about duplication. I think we don't need to replicate so many test cases here, it's enough to exercise every user-facing public function like format
or format_to
once. In particular, we shouldn't be testing multiple built-in argument types because they all go through the same path.
Also there are some json files that I don't think should be here.
Right, these two additional files sneaked in by accident. Thanks for pointing this out. Regarding duplication: it's not just the name like e.g. If you happen to have sections to point me to which concern you I will look into them and remove superfluous duplicates. I'd love to have a tool to aide me but I'm not aware of one. |
test/module-test.cc
Outdated
EXPECT_EQ("42", fmt::format("{}", 42)); | ||
EXPECT_EQ("42", fmt::format("{:}", 42u)); | ||
EXPECT_EQ("+42", fmt::format("{:+d}", short{42})); | ||
EXPECT_EQ("42", fmt::format("{:d}", unsigned short{42u})); | ||
EXPECT_EQ("-42", fmt::format("{0}", -42L)); | ||
EXPECT_EQ("2a", fmt::format("{0:x}", 42uL)); | ||
EXPECT_EQ("***42", fmt::format("{:*>5}", 42LL)); | ||
EXPECT_EQ("0X2A", fmt::format("{:#X}", 42uLL)); | ||
EXPECT_EQ("===42.000000===", fmt::format("{:=^15f}", 42.0)); | ||
EXPECT_EQ("00000042.1", fmt::format("{:<010.5G}", 42.1f)); | ||
EXPECT_EQ(" +4.21235e+11", fmt::format("{:+{}.{}e}", 42.1234567e10L, 13, 5)); | ||
EXPECT_EQ("-0x1.5000000000000p+5", fmt::format("{: a}", -42.0)); | ||
constexpr auto nan = std::numeric_limits<double>::quiet_NaN(); | ||
EXPECT_EQ("-nan-", fmt::format("{:-^5}", nan)); | ||
constexpr auto inf = std::numeric_limits<double>::infinity(); | ||
EXPECT_EQ("-INF-", fmt::format("{:-^5F}", inf)); | ||
EXPECT_EQ("-INF ", fmt::format("{: 5G}", -inf)); | ||
EXPECT_EQ("42", fmt::format("{:s}", "42")); | ||
EXPECT_EQ("a", fmt::format("{:c}", 'a')); | ||
EXPECT_EQ("a", fmt::format("{:c}", unsigned char{'a'})); | ||
EXPECT_EQ("a", fmt::format("{:c}", signed char{'a'})); | ||
EXPECT_EQ("false", fmt::format("{}", false)); | ||
EXPECT_EQ("0B1", fmt::format("{:#B}", true)); | ||
EXPECT_EQ("0x2a", fmt::format("{:p}", (void *)42)); | ||
EXPECT_EQ("1234", fmt::format("{:L}", 1234)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example here we don't need to test all argument types. Since they all go through the same code path, it is very unlikely that one of them works and another doesn't. I suggest picking one type (e.g. int) and testing public methods with it. In the unlikely case that we find some problem in the future, we can add a regression test.
d5203d3
to
700551f
Compare
Your suggestions are in. This is also updated to msvc 16.11-pre1 |
700551f
to
d8e200d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestions are in. This is also updated to msvc 16.11-pre1
Thank you. A few more comments, otherwise looks great.
test/module-test.cc
Outdated
EXPECT_FALSE(no_args.get(1)); | ||
|
||
using ctx = fmt::format_context; | ||
fmt::basic_format_args<ctx> args = fmt::make_format_args<ctx>(42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx
can be dropped here because it is the default. Same in multiple places below.
test/module-test.cc
Outdated
} | ||
|
||
TEST(module_test, ptr) { | ||
auto p = (int*)42; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use more narrow bit_cast or reinterpret_cast instead of a C-style cast.
test/module-test.cc
Outdated
} | ||
|
||
TEST(module_test, weekday) { | ||
const auto de = std::locale("de_DE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may throw if the locale is not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ...
Luckily we don't care here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we care? Since this is a non-functional test I suggest using the std::locale::classic()
which is always available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't care for the same reason why you suggest using the classic locale: it just has to look up the correct overloads. If you prefer std::locale::classic()
then I'll change it accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it just has to look up the correct overloads.
It would enough if we didn't actually run this code, only compile. But my understanding is that we eventually want to run this code.
If you prefer std::locale::classic() then I'll change it accordingly.
Please do.
test/module-test.cc
Outdated
static_assert(fmt::is_formattable<disabled_formatter_convertible>::value, ""); | ||
} | ||
|
||
struct convertible_to_int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything starting from here to the end of the file falls into the category of "functional testing", please remove. It is very unlikely that this functionality behaves differently between modular and non-modular build because it goes through the same argument handling paths as everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've condensed it as much as possible to name-lookup.
d8e200d
to
865994b
Compare
core.h, format.h, args.h, chrono.h, color.h, printf.h, os.h
865994b
to
576f0b7
Compare
Thank you! |
Most of the API of core.h, format.h, and args.h
Just narrow strings. Tests for wide strings will come later.