@@ -35,7 +35,8 @@
#ifdef _WIN32
# include <stdio.h> // _fileno
-# include <io.h> // _get_osfhandle
+# include <io.h> // _get_osfhandle, _open_osfhandle, _write
+# include <fcntl.h> // _O_APPEND
# include <windows.h> // GetLastError, WriteConsoleW
#elifdef _GLIBCXX_HAVE_UNISTD_H
# include <stdio.h> // fileno
@@ -324,6 +325,16 @@ namespace
if (!to_valid_utf16(str, wstr))
ec = std::make_error_code(errc::illegal_byte_sequence);
+ // This allows us to test this function with a normal file,
+ // see testsuite/27_io/print/2.cc
+ if (!check_for_console(term))
+ {
+ int fd = _open_osfhandle((intptr_t)term, _O_APPEND);
+ if (_write(fd, wstr.data(), wstr.size() * 2) == -1)
+ ec = {errno, generic_category()};
+ return ec;
+ }
+
unsigned long nchars = 0;
WriteConsoleW(term, wstr.data(), wstr.size(), &nchars, nullptr);
if (nchars != wstr.size())
@@ -39,7 +39,11 @@ as_printed_to_terminal(std::string& s)
#else
const auto ec = std::__write_to_terminal(strm, s);
#endif
- VERIFY( !ec || ec == std::make_error_code(std::errc::illegal_byte_sequence) );
+ if (ec && ec != std::make_error_code(std::errc::illegal_byte_sequence))
+ {
+ std::println("Failed to : {}", ec.message());
+ VERIFY(!ec);
+ }
std::fclose(strm);
std::ifstream in(f.path);
s.assign(std::istreambuf_iterator<char>(in), {});
@@ -114,6 +118,7 @@ test_utf16_transcoding()
VERIFY( as_printed_to_terminal(s) );
VERIFY( utf16_from_bytes(s) == s2 );
+ s = (const char*)u8"£🇬🇧 €🇪🇺";
s += " \xa3 10.99 \xee\xdd";
VERIFY( ! as_printed_to_terminal(s) );
std::u16string repl = u"\uFFFD";