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

Improved reliability of some tests #4686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

springcomp
Copy link
Contributor

@springcomp springcomp commented Apr 2, 2025

PR Summary

TL;DR;

This pull request suggests an improvement to the TestSetup() method to initialize some data members that are used in some tests that would otherwise fail.

Summary

Some tests around history, prediction and suggestion – are failing on the local machine due to the PSConsoleReadLine._history member not being initialized.

This member is initialized the first time the PSConsoleReadLine.ReadLine() method is called, which happens in the Test method overloads.

However, some tests perform actions between the TestSetup() and the Test() methods. For instance, the following test fails because the _history member is not initialized:

List_RenderSuggestion_UpdatesWhileTyping:

        [SkippableFact]
        public void List_RenderSuggestion_ListUpdatesWhileTyping()
        {
            TestSetup(KeyMode.Cmd);
            int listWidth = CheckWindowSize();
            // The font effect sequences of the dimmed color used in list view metadata line
            // are ignored in the mock console, so only the white color will be left.
            var dimmedColors = Tuple.Create(ConsoleColor.White, _console.BackgroundColor);
            var emphasisColors = Tuple.Create(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor);
            using var disp = SetPrediction(PredictionSource.History, PredictionViewStyle.ListView);

            // Different matches as more input coming
            SetHistory("echo -bar", "eca -zoo"); // ** THIS CALL FAILS BECAUSE _history IS NOT INITIALIZED
            Test("ech", Keys(

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests (Not Applicable)
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed at PowerShell-Docs
      • Doc Issue filed:
Microsoft Reviewers: Open in CodeFlow

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.

1 participant