From ca81ce0df217a7e70da54b72b1af7dc76a6a4bfe Mon Sep 17 00:00:00 2001 From: nzbr Date: Tue, 17 Jan 2023 19:46:54 +0100 Subject: fix powershell test --- tests/lib/lib.ps1 | 12 ++++++++++++ tests/shells.Tests.ps1 | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/lib.ps1 b/tests/lib/lib.ps1 index beef272..bc2dd94 100644 --- a/tests/lib/lib.ps1 +++ b/tests/lib/lib.ps1 @@ -2,6 +2,16 @@ if ($PSVersionTable.PSEdition -ne 'Core') { throw "The tests are not compatible with Windows PowerShell, please use PowerShell Core instead" } +function Remove-Escapes { + param( + [parameter(ValueFromPipeline = $true)] + [string[]]$InputObject + ) + process { + $InputObject | ForEach-Object { $_ -replace '\x1b(\[(\?..|.)|.)', '' } + } +} + # Implementation-independent base class class Distro { [string]$id @@ -155,9 +165,11 @@ class WslDistro : Distro { # Auto-select the implementation to use function Install-Distro() { if ($IsWindows) { + Write-Host "Detected Windows host, using WSL" return [WslDistro]::new() } else { + Write-Host "Detected Linux host, using Docker" return [DockerDistro]::new() } } diff --git a/tests/shells.Tests.ps1 b/tests/shells.Tests.ps1 index fda3295..4dae61b 100644 --- a/tests/shells.Tests.ps1 +++ b/tests/shells.Tests.ps1 @@ -18,7 +18,7 @@ users.users.`${config.wsl.defaultUser}.shell = pkgs.$package; "@ > $temp $distro.InstallConfig($temp) Remove-Item $temp - $distro.Launch("echo `$SHELL") | Select-Object -Last 1 | Should -BeExactly "/run/current-system/sw/bin/$executable" + $distro.Launch("echo `$SHELL") | Remove-Escapes | Select-Object -Last 1 | Should -BeExactly "/run/current-system/sw/bin/$executable" $LASTEXITCODE | Should -Be 0 } } -- cgit v1.2.3