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

More module tests #2309

Merged
merged 1 commit into from
May 28, 2021
Merged

More module tests #2309

merged 1 commit into from
May 28, 2021

Conversation

DanielaE
Copy link
Contributor

Most of the API of core.h, format.h, and args.h

Just narrow strings. Tests for wide strings will come later.

@DanielaE DanielaE force-pushed the feature/add-module-test branch 2 times, most recently from 1a2b2d1 to d5203d3 Compare May 25, 2021 09:36
Copy link
Contributor

@vitaut vitaut left a 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.

@DanielaE
Copy link
Contributor Author

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. format but all of the overloads, and as these are templates which may cause different specializations within the library, as many of them should be instantiated to check not only visibility but also reachability. This aspect is a non-issue in traditional libraries, because everything visible is also reachable, and there are possibly more declarations and semantic properties reachable than visible. In the modules world things are much different: visibility and name-lookup in instantiations must be put to a test. I've already found a few places by these tests where lookup is an issue that need to be audited and addressed.

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.

Comment on lines 105 to 129
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));
Copy link
Contributor

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.

test/module-test.cc Outdated Show resolved Hide resolved
@DanielaE
Copy link
Contributor Author

Your suggestions are in. This is also updated to msvc 16.11-pre1

Copy link
Contributor

@vitaut vitaut left a 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.

EXPECT_FALSE(no_args.get(1));

using ctx = fmt::format_context;
fmt::basic_format_args<ctx> args = fmt::make_format_args<ctx>(42);
Copy link
Contributor

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, ptr) {
auto p = (int*)42;
Copy link
Contributor

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, weekday) {
const auto de = std::locale("de_DE");
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 Show resolved Hide resolved
static_assert(fmt::is_formattable<disabled_formatter_convertible>::value, "");
}

struct convertible_to_int {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

core.h, format.h, args.h, chrono.h, color.h, printf.h, os.h
@vitaut vitaut merged commit 272b0f3 into fmtlib:master May 28, 2021
@vitaut
Copy link
Contributor

vitaut commented May 28, 2021

Thank you!

@DanielaE DanielaE deleted the feature/add-module-test branch May 29, 2021 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants