99// All Rights Reserved
1010// {fmt} module.
1111
12- #ifdef _MSC_FULL_VER
13- // hide some implementation bugs in msvc
14- // that are not essential to users of the module.
15- # define FMT_HIDE_MODULE_BUGS
16- #endif
17-
1812#include < bit>
1913#include < chrono>
2014#include < exception>
4337
4438import fmt;
4539
46- // check for macros leaking from BMI
47- static bool macro_leaked =
48- #if defined(FMT_CORE_H_) || defined(FMT_FORMAT_H_)
49- true ;
50- #else
51- false ;
52- #endif
53-
5440#define FMT_OS_H_ // don't pull in os.h, neither directly nor indirectly
55- // this define plus the #include <gmock/gmock.h> above
56- // prevents header inclusion after the import fmt statement
5741#include " gtest-extra.h"
5842
5943// an implicitly exported namespace must be visible [module.interface]/2.2
@@ -63,16 +47,11 @@ TEST(module_test, namespace) {
6347 ASSERT_TRUE (true );
6448}
6549
66- // macros must not be imported from a * named* module [cpp.import]/5.1
50+ // Macros must not be imported from a named module [cpp.import]/5.1.
6751TEST (module_test, macros) {
68- #if defined(FMT_HIDE_MODULE_BUGS) && defined(_MSC_FULL_VER) && \
69- _MSC_FULL_VER <= 192930130
70- // bug in msvc up to 16.11-pre2:
71- // include-guard macros leak from BMI
72- // and even worse: they cannot be #undef-ined
73- macro_leaked = false ;
52+ #if defined(FMT_BASE_H_) || defined(FMT_FORMAT_H_)
53+ FAIL () << " Macros are leaking from a named module" ;
7454#endif
75- EXPECT_FALSE (macro_leaked);
7655}
7756
7857// The following is less about functional testing (that's done elsewhere)
@@ -148,37 +127,15 @@ TEST(module_test, format_args) {
148127 EXPECT_FALSE (no_args.get (1 ));
149128
150129 int n = 42 ;
151- fmt::basic_format_args<fmt::format_context> args = fmt::make_format_args (n);
130+ auto args = fmt::make_format_args (n);
152131 EXPECT_TRUE (args.max_size () > 0 );
153- auto arg0 = args.get (0 );
154- EXPECT_TRUE (arg0);
155- decltype (arg0) arg_none;
156- EXPECT_FALSE (arg_none);
157- EXPECT_TRUE (arg0.type () != arg_none.type ());
158- }
159-
160- TEST (module_test, wformat_args) {
161- auto no_args = fmt::wformat_args ();
162- EXPECT_FALSE (no_args.get (1 ));
163- int n = 42 ;
164- fmt::basic_format_args<fmt::wformat_context> args = fmt::make_wformat_args (n);
165132 EXPECT_TRUE (args.get (0 ));
166- }
167-
168- TEST (module_test, dynamic_format_args) {
169- fmt::dynamic_format_arg_store<fmt::format_context> dyn_store;
170- dyn_store.push_back (fmt::arg (" a42" , 42 ));
171-
172- fmt::basic_format_args<fmt::format_context> args = dyn_store;
173- EXPECT_FALSE (args.get (3 ));
174- EXPECT_TRUE (args.get (fmt::string_view (" a42" )));
133+ EXPECT_FALSE (args.get (1 ));
175134}
176135
177136TEST (module_test, vformat) {
178137 int n = 42 ;
179138 EXPECT_EQ (" 42" , fmt::vformat (" {}" , fmt::make_format_args (n)));
180- EXPECT_EQ (L" 42" ,
181- fmt::vformat (fmt::wstring_view (L" {}" ), fmt::make_wformat_args (n)));
182139}
183140
184141TEST (module_test, vformat_to) {
@@ -187,15 +144,6 @@ TEST(module_test, vformat_to) {
187144 std::string s;
188145 fmt::vformat_to (std::back_inserter (s), " {}" , store);
189146 EXPECT_EQ (" 42" , s);
190-
191- auto wstore = fmt::make_wformat_args (n);
192- std::wstring w;
193- fmt::vformat_to (std::back_inserter (w), L" {}" , wstore);
194- EXPECT_EQ (L" 42" , w);
195-
196- wchar_t wbuffer[4 ] = {0 };
197- fmt::vformat_to (wbuffer, L" {:}" , wstore);
198- EXPECT_EQ (L" 42" , std::wstring_view (wbuffer));
199147}
200148
201149TEST (module_test, vformat_to_n) {
@@ -205,11 +153,6 @@ TEST(module_test, vformat_to_n) {
205153 fmt::vformat_to_n (std::back_inserter (s), 1 , " {}" , store);
206154 char buffer[4 ] = {0 };
207155 fmt::vformat_to_n (buffer, 3 , " {:}" , store);
208-
209- auto wstore = fmt::make_wformat_args (n);
210- std::wstring w;
211- wchar_t wbuffer[4 ] = {0 };
212- fmt::vformat_to_n (wbuffer, 3 , fmt::wstring_view (L" {:}" ), wstore);
213156}
214157
215158std::string as_string (std::wstring_view text) {
@@ -251,11 +194,6 @@ TEST(module_test, locale) {
251194 fmt::vformat_to (std::back_inserter (s), classic, " {:L}" , store);
252195 EXPECT_EQ (" 4.2" , s);
253196 EXPECT_EQ (" 4.2" , fmt::format (" {:L}" , 4.2 ));
254-
255- auto wstore = fmt::make_wformat_args (m);
256- EXPECT_EQ (L" 4.2" , fmt::format (classic, L" {:L}" , 4.2 ));
257- EXPECT_EQ (L" 4.2" , fmt::vformat (classic, L" {:L}" , wstore));
258- EXPECT_EQ (L" 4.2" , fmt::format (L" {:L}" , 4.2 ));
259197}
260198
261199TEST (module_test, string_view) {
@@ -385,23 +323,6 @@ TEST(module_test, sprintf) {
385323 EXPECT_EQ (" 42" , fmt::sprintf (" %d" , 42 ));
386324}
387325
388- TEST (module_test, vfprintf) {
389- int n = 42 ;
390- auto store = fmt::make_format_args<fmt::printf_context>(n);
391- auto args = fmt::basic_format_args<fmt::printf_context>(store);
392- EXPECT_WRITE (stdout, fmt::vfprintf (stdout, fmt::string_view (" %d" ), args),
393- " 42" );
394- }
395-
396- TEST (module_test, vsprintf) {
397- int n = 42 ;
398- auto store = fmt::make_format_args<fmt::printf_context>(n);
399- auto args = fmt::basic_format_args<fmt::printf_context>(store);
400- EXPECT_EQ (fmt::vsprintf (fmt::string_view (" %d" ), args), " 42" );
401- EXPECT_WRITE (stdout, fmt::vfprintf (stdout, fmt::string_view (" %d" ), args),
402- " 42" );
403- }
404-
405326TEST (module_test, color) {
406327 EXPECT_EQ (" \x1B [30m42\x1B [0m" ,
407328 fmt::format (fg (fmt::terminal_color::black), " {}" , 42 ));
0 commit comments