Skip to content

Commit

Permalink
Fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Aug 12, 2023
1 parent 3dc19c9 commit ec15ff1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 43 deletions.
49 changes: 7 additions & 42 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ internal class WindowsDriver : ConsoleDriver {

public WindowsConsole WinConsole { get; private set; }

public override bool SupportsTrueColor => _isWindowsTerminal && Environment.OSVersion.Version.Build >= 14931;
public override bool SupportsTrueColor => _runningUnitTests || (_isWindowsTerminal && Environment.OSVersion.Version.Build >= 14931);

public override bool Force16Colors {
get => base.Force16Colors;
Expand Down Expand Up @@ -1452,7 +1452,11 @@ public override bool IsRuneSupported (Rune rune)
public override void Init (Action terminalResized)
{
TerminalResized = terminalResized;


if (Environment.OSVersion.Platform == PlatformID.Unix) {
_runningUnitTests = true;
return;
}
try {
if (WinConsole != null) {
var winSize = WinConsole.GetConsoleOutputWindow (out Point pos);
Expand Down Expand Up @@ -1708,7 +1712,7 @@ public override void End ()
WinConsole?.Cleanup ();
WinConsole = null;

if (_isWindowsTerminal) {
if (!_runningUnitTests && _isWindowsTerminal) {
// Disable alternative screen buffer.
Console.Out.Write (EscSeqUtils.CSI_RestoreAltBufferWithBackscroll);
}
Expand All @@ -1720,45 +1724,6 @@ public override void Suspend ()
throw new NotImplementedException ();
}
#endregion

static string GetParentProcessName ()
{
#pragma warning disable CA1416 // Validate platform compatibility
var myId = Process.GetCurrentProcess ().Id;
var query = string.Format ($"SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {myId}");
var search = new ManagementObjectSearcher ("root\\CIMV2", query);
var queryObj = search.Get ().OfType<ManagementBaseObject> ().FirstOrDefault ();
if (queryObj == null) {
return null;
}
var parentId = (uint)queryObj ["ParentProcessId"];
var parent = Process.GetProcessById ((int)parentId);
var prevParent = parent;

// Check if the parent is from other parent
while (queryObj != null) {
query = string.Format ($"SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {parentId}");
search = new ManagementObjectSearcher ("root\\CIMV2", query);
queryObj = search.Get ().OfType<ManagementBaseObject> ().FirstOrDefault ();
if (queryObj == null) {
return parent.ProcessName;
}
parentId = (uint)queryObj ["ParentProcessId"];
try {
parent = Process.GetProcessById ((int)parentId);
if (string.Equals (parent.ProcessName, "explorer", StringComparison.InvariantCultureIgnoreCase)) {
return prevParent.ProcessName;
}
prevParent = parent;
} catch (ArgumentException) {

return prevParent.ProcessName;
}
}

return parent.ProcessName;
#pragma warning restore CA1416 // Validate platform compatibility
}
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion testenvironments.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
"wslDistribution": "Debian"
}
]
}
}

0 comments on commit ec15ff1

Please sign in to comment.