Skip to content

Commit 4c60dcb

Browse files
committed
Include 'Merge pull request #204 from boostorg/test-iostream'
Source commit: 2f0ffbb
1 parent d6f8d88 commit 4c60dcb

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

test/test_iostream.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2015 Artyom Beilis (Tonkikh)
2-
// Copyright (c) 2020 - 2021 Alexander Grund
2+
// Copyright (c) 2020 - 2026 Alexander Grund
33
//
44
// Distributed under the Boost Software License, Version 1.0.
55
// https://www.boost.org/LICENSE_1_0.txt
@@ -17,6 +17,7 @@
1717
#include "test.hpp"
1818
#include "test_sets.hpp"
1919
#include <algorithm>
20+
#include <cstdlib>
2021
#include <fstream>
2122
#include <limits>
2223
#include <queue>
@@ -457,10 +458,10 @@ class RedirectStdio
457458
void setBufferData(const std::wstring& data)
458459
{
459460
std::vector<INPUT_RECORD> buffer;
460-
buffer.reserve(data.size() * 2 + 2);
461+
buffer.reserve(data.size() * 2);
461462
for(const auto c : data)
462463
{
463-
INPUT_RECORD ev;
464+
INPUT_RECORD ev{};
464465
ev.EventType = KEY_EVENT;
465466
ev.Event.KeyEvent.bKeyDown = TRUE;
466467
ev.Event.KeyEvent.dwControlKeyState = 0;
@@ -472,14 +473,15 @@ class RedirectStdio
472473
} else
473474
{
474475
ev.Event.KeyEvent.uChar.UnicodeChar = c;
475-
ev.Event.KeyEvent.wVirtualKeyCode = VkKeyScanW(c);
476+
ev.Event.KeyEvent.wVirtualKeyCode = 0;
476477
}
477-
ev.Event.KeyEvent.wVirtualScanCode =
478-
static_cast<WORD>(MapVirtualKeyW(ev.Event.KeyEvent.wVirtualKeyCode, MAPVK_VK_TO_VSC));
478+
ev.Event.KeyEvent.wVirtualScanCode = 0;
479479
buffer.push_back(ev);
480480
ev.Event.KeyEvent.bKeyDown = FALSE;
481481
buffer.push_back(ev);
482482
}
483+
// Clear any previous contents
484+
FlushConsoleInputBuffer(h);
483485
DWORD dwWritten;
484486
TEST(WriteConsoleInputW(h, buffer.data(), static_cast<DWORD>(buffer.size()), &dwWritten));
485487
TEST_EQ(dwWritten, static_cast<DWORD>(buffer.size()));
@@ -489,6 +491,11 @@ class RedirectStdio
489491
void test_console()
490492
{
491493
#ifndef NOWIDE_DISABLE_CIN_TEST
494+
#ifdef __MINGW32__
495+
bool isMinGW_CI = std::getenv("CI");
496+
#else
497+
bool isMinGW_CI = false;
498+
#endif
492499
std::cout << "Test cin console: " << std::flush;
493500
{
494501
RedirectStdio stdinHandle(STD_INPUT_HANDLE);
@@ -506,10 +513,20 @@ void test_console()
506513
std::string line;
507514
TEST(std::getline(cin, line));
508515
std::cout << "ASCII line read" << std::endl;
509-
TEST_EQ(line, testStringIn1);
510-
TEST(std::getline(cin, line));
511-
std::cout << "UTF-8 line read" << std::endl;
512-
TEST_EQ(line, testStringIn2);
516+
// MinGW on CI sometimes swallows the (mocked) first line or returns it multiple times
517+
if(isMinGW_CI && line == testStringIn2)
518+
std::cout << "WARNING: MinGW CI issue detected, skipping part of test"; // LCOV_EXCL_LINE
519+
else
520+
{
521+
TEST_EQ(line, testStringIn1);
522+
std::cout << "UTF-8 line read" << std::endl;
523+
line.clear();
524+
TEST(std::getline(cin, line));
525+
if(isMinGW_CI && line == testStringIn1)
526+
std::cout << "WARNING: MinGW CI issue detected, skipping 1st part of test"; // LCOV_EXCL_LINE
527+
else
528+
TEST_EQ(line, testStringIn2);
529+
}
513530
}
514531
#endif
515532
std::cout << "Test cout console" << std::endl;
@@ -523,7 +540,10 @@ void test_console()
523540
cout << testString << std::flush;
524541

525542
const auto data = stdoutHandle.getBufferData();
526-
TEST_EQ(data, nw::widen(testString));
543+
if(isMinGW_CI && data.empty())
544+
std::cout << "WARNING: MinGW CI issue detected, skipping part of test"; // LCOV_EXCL_LINE
545+
else
546+
TEST_EQ(data, nw::widen(testString));
527547
}
528548
std::cout << "Test cerr console" << std::endl;
529549
{

0 commit comments

Comments
 (0)