A few StateMachine unit tests don't fully test what they purport to #1824

Open
opened 2026-01-30 22:37:34 +00:00 by claunia · 1 comment
Owner

Originally created by @j4james on GitHub (Jun 21, 2019).

I'm not sure if this is right place to report this, because it's not a bug in the app itself, but it's an issue I noticed in the unit tests, which I think may be considered a bug.

As a specific example, consider the TestCursorKeysMode test in OutputEngineTest.cpp:

TEST_METHOD(TestCursorKeysMode)
{
    StatefulDispatch* pDispatch = new StatefulDispatch;
    VERIFY_IS_NOT_NULL(pDispatch);
    StateMachine mach(new OutputStateMachineEngine(pDispatch));

    mach.ProcessString(L"\x1b[?1h", 5);
    VERIFY_IS_TRUE(pDispatch->_fCursorKeysMode);

    pDispatch->ClearState();

    mach.ProcessString(L"\x1b[?1l", 5);
    VERIFY_IS_FALSE(pDispatch->_fCursorKeysMode);

    pDispatch->ClearState();
}

The second half of this test is assumedly meant to prove that the given escape sequence will reset the cursor keys mode. However, the _fCursorKeysMode flag is false by default, so you could replace that escape sequence with almost anything, including removing it altogether, and the test would still pass.

There are similar problems with TestCursorBlinking, TestCursorVisibility, and possibly also TestAltBufferSwapping.

When I added a similar test, I got around the problem by explicitly setting the flag I was testing to the opposite of what was expected, but I'm not sure if that is the best approach. Another possibility might be using std::optional<bool> instead of just a bool, so the default value could then be a nullopt, and it wouldn't be possible to pass the test based on the default value alone. The downside of that approach is the VERIFY steps become a little more complicated.

Originally created by @j4james on GitHub (Jun 21, 2019). I'm not sure if this is right place to report this, because it's not a bug in the app itself, but it's an issue I noticed in the unit tests, which I think may be considered a bug. As a specific example, consider the [`TestCursorKeysMode`](https://github.com/microsoft/terminal/blob/9b92986b49bed8cc41fde4d6ef080921c41e6d9e/src/terminal/parser/ut_parser/OutputEngineTest.cpp#L1162-L1177) test in OutputEngineTest.cpp: ```c++ TEST_METHOD(TestCursorKeysMode) { StatefulDispatch* pDispatch = new StatefulDispatch; VERIFY_IS_NOT_NULL(pDispatch); StateMachine mach(new OutputStateMachineEngine(pDispatch)); mach.ProcessString(L"\x1b[?1h", 5); VERIFY_IS_TRUE(pDispatch->_fCursorKeysMode); pDispatch->ClearState(); mach.ProcessString(L"\x1b[?1l", 5); VERIFY_IS_FALSE(pDispatch->_fCursorKeysMode); pDispatch->ClearState(); } ``` The second half of this test is assumedly meant to prove that the given escape sequence will reset the cursor keys mode. However, the `_fCursorKeysMode` flag is false by default, so you could replace that escape sequence with almost anything, including removing it altogether, and the test would still pass. There are similar problems with `TestCursorBlinking`, `TestCursorVisibility`, and possibly also `TestAltBufferSwapping`. When I added a similar test, I got around the problem by explicitly setting the flag I was testing to the opposite of what was expected, but I'm not sure if that is the best approach. Another possibility might be using `std::optional<bool>` instead of just a `bool`, so the default value could then be a `nullopt`, and it wouldn't be possible to pass the test based on the default value alone. The downside of that approach is the `VERIFY` steps become a little more complicated.
claunia added the Help WantedProduct-ConhostIssue-TaskArea-CodeHealth labels 2026-01-30 22:37:34 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jul 1, 2019):

To add: this is the right place to report this. There certainly are lots of test gaps, and places where our infrastructure could be improved. Any contributions to help us catch those and fix them is greatly appreciated :)

@zadjii-msft commented on GitHub (Jul 1, 2019): To add: this _is_ the right place to report this. There certainly are lots of test gaps, and places where our infrastructure could be improved. Any contributions to help us catch those and fix them is greatly appreciated :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1824