@@ -162,6 +162,42 @@ function Install-CygWin
162162 choco install cygwin - y -- force -- params " /InstallDir:${InstallLocation} /NoStartMenu"
163163}
164164
165+ function Ensure-CygWinInstalled
166+ {
167+ [CmdletBinding ()]
168+ param (
169+ [string ] $InstallLocation = " $env: SystemDrive /cygwin" ,
170+ [Parameter (Mandatory = $true )]
171+ [string ] $FailureMessage
172+ )
173+
174+ if (Test-Path - Path " $InstallLocation /bin/sh.exe" )
175+ {
176+ return $true
177+ }
178+
179+ Write-Verbose - Verbose - Message " CygWin not found"
180+ Install-CygWin - InstallLocation $InstallLocation
181+
182+ $expectedCygWinPath = " $InstallLocation /bin/sh.exe"
183+ if (Test-Path - Path $expectedCygWinPath )
184+ {
185+ return $true
186+ }
187+
188+ Write-Verbose - Verbose - Message " CygWin did not install correctly, missing expected path: ${expectedCygWinPath} "
189+
190+ $cygWinDirs = Get-Item - Path " $env: SystemDrive /cygwin*" - ErrorAction SilentlyContinue
191+ if ($cygWinDirs.Count -gt 1 )
192+ {
193+ Write-Verbose - Verbose - Message " CygWin install failed with mangled folder locations: ${cygWinDirs} "
194+ Write-Verbose - Verbose - Message ' TODO: Add hack to fix up CygWin folder.'
195+ }
196+
197+ Write-BuildMessage - Message $FailureMessage - Category Error
198+ return $false
199+ }
200+
165201<#
166202 . Synopsis
167203 Runs the tests for this repo
@@ -229,34 +265,7 @@ function Invoke-OpenSSHTests
229265 Write-Verbose - Verbose - Message " Running E2E Tests..."
230266 Set-OpenSSHTestEnvironment - Confirm:$false
231267
232- # Ensure CygWin is installed, and install from Chocolatey if needed.
233- # used for bash tests and default shell pester tests
234- $cygwinInstalled = $true
235- $cygwinInstallLocation = " $env: SystemDrive /cygwin"
236- if (! (Test-Path - Path " $cygwinInstallLocation /bin/sh.exe" ))
237- {
238- Write-Verbose - Verbose - Message " CygWin not found"
239- Install-CygWin - InstallLocation $cygwinInstallLocation
240-
241- # Hack to fix up mangled CygWin directory, if needed.
242- $expectedCygWinPath = " $env: SystemDrive /cygwin/bin/sh.exe"
243- if (! (Test-Path - Path $expectedCygWinPath ))
244- {
245- Write-Verbose - Verbose - Message " CygWin did not install correctly, missing expected path: ${expectedCygWinPath} "
246-
247- $cygWinDirs = Get-Item - Path " $env: SystemDrive /cygwin*"
248- if ($cygWinDirs.Count -gt 1 )
249- {
250- Write-Verbose - Verbose - Message " CygWin install failed with mangled folder locations: ${cygWinDirs} "
251- Write-Verbose - Verbose - Message ' TODO: Add hack to fix up CygWin folder.'
252- }
253-
254- Write-BuildMessage - Message " All bash tests failed because CygWin install failed" - Category Error
255- $AllTestsPassed = $false
256- $cygwinInstalled = $false
257- }
258- }
259-
268+ $cygwinInstalled = Ensure- CygWinInstalled - FailureMessage " All E2E tests failed because CygWin install failed"
260269 if ($cygwinInstalled )
261270 {
262271 Invoke-OpenSSHE2ETest
@@ -279,33 +288,10 @@ function Invoke-OpenSSHTests
279288 Write-BuildMessage - Message " All E2E tests passed!" - Category Information
280289 }
281290 }
282-
283- # Bash tests.
284- Write-Verbose - Verbose - Message " Running Bash Tests..."
285-
286- # Run UNIX bash tests.
287- Write-Verbose - Verbose - Message " Starting Bash Tests..."
288- Invoke-OpenSSHBashTests
289- if (-not $Global :bash_tests_summary )
290- {
291- $errorMessage = " Failed to start OpenSSH bash tests"
292- Write-BuildMessage - Message $errorMessage - Category Error
293- $AllTestsPassed = $false
294- }
295- else
296- {
297- if ($Global :bash_tests_summary [" TotalBashTestsFailed" ] -ne 0 )
298- {
299- $total_bash_failed_tests = $Global :bash_tests_summary [" TotalBashTestsFailed" ]
300- $total_bash_tests = $Global :bash_tests_summary [" TotalBashTests" ]
301- $errorMessage = " At least one of the bash tests failed. [$total_bash_failed_tests of $total_bash_tests ]"
302- Write-BuildMessage - Message $errorMessage - Category Error
303- $AllTestsPassed = $false
304- }
305-
306- $OpenSSHTestInfo [" BashTestSummaryFile" ] = $Global :bash_tests_summary [" BashTestSummaryFile" ]
307- $OpenSSHTestInfo [" BashTestLogFile" ] = $Global :bash_tests_summary [" BashTestLogFile" ]
308- }
291+ }
292+ else
293+ {
294+ $AllTestsPassed = $false
309295 }
310296
311297 # OpenSSH Uninstall Tests
@@ -346,6 +332,70 @@ function Invoke-OpenSSHTests
346332 }
347333}
348334
335+ <#
336+ . Synopsis
337+ Runs OpenSSH bash tests only.
338+ #>
339+ function Invoke-OpenSSHBashTestsOnly
340+ {
341+ [CmdletBinding ()]
342+ param (
343+ [Parameter (Mandatory = $true )]
344+ [string ] $OpenSSHBinPath
345+ )
346+
347+ Set-BasicTestInfo - OpenSSHBinPath $OpenSSHBinPath - Confirm:$false
348+
349+ $AllTestsPassed = $true
350+
351+ Write-Verbose - Verbose - Message " Running Bash-only OpenSSH test flow..."
352+ Set-OpenSSHTestEnvironment - Confirm:$false
353+
354+ $cygwinInstalled = Ensure- CygWinInstalled - FailureMessage " All bash tests failed because CygWin install failed"
355+ if (-not $cygwinInstalled )
356+ {
357+ $AllTestsPassed = $false
358+ }
359+
360+ if ($AllTestsPassed )
361+ {
362+ Write-Verbose - Verbose - Message " Starting Bash Tests..."
363+ Invoke-OpenSSHBashTests
364+ if (-not $Global :bash_tests_summary )
365+ {
366+ $errorMessage = " Failed to start OpenSSH bash tests"
367+ Write-BuildMessage - Message $errorMessage - Category Error
368+ $AllTestsPassed = $false
369+ }
370+ else
371+ {
372+ if ($Global :bash_tests_summary [" TotalBashTestsFailed" ] -ne 0 )
373+ {
374+ $total_bash_failed_tests = $Global :bash_tests_summary [" TotalBashTestsFailed" ]
375+ $total_bash_tests = $Global :bash_tests_summary [" TotalBashTests" ]
376+ $errorMessage = " At least one of the bash tests failed. [$total_bash_failed_tests of $total_bash_tests ]"
377+ Write-BuildMessage - Message $errorMessage - Category Error
378+ $AllTestsPassed = $false
379+ }
380+
381+ $OpenSSHTestInfo [" BashTestSummaryFile" ] = $Global :bash_tests_summary [" BashTestSummaryFile" ]
382+ $OpenSSHTestInfo [" BashTestLogFile" ] = $Global :bash_tests_summary [" BashTestLogFile" ]
383+ }
384+ }
385+
386+ $OpenSSHTestInfo | Export-Clixml - Path " $repoRoot /OpenSSHTestInfo.xml" - Depth 10
387+
388+ if ($AllTestsPassed )
389+ {
390+ Write-BuildMessage - Message " All OpenSSH bash validation tests have passed!" - Category Information
391+ }
392+ else
393+ {
394+ Write-BuildMessage - Message " Some OpenSSH bash validation tests have failed." - Category Error
395+ throw " OpenSSH bash validation tests failed!"
396+ }
397+ }
398+
349399<#
350400 . Synopsis
351401 Collect OpenSSH pester test results into one directory
0 commit comments