-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine Windows 10 SDK install command and add tests (#153)
- Loading branch information
Showing
6 changed files
with
275 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
param ( | ||
[int]$ExpectedExitCode = 0, | ||
[string]$ExpectedErrorKeyphrase = "" | ||
) | ||
|
||
# Ensure the output is UTF-8 encoded so we can use emojis... | ||
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | ||
$emojiGreenCheck = "$([char]0x2705)" | ||
$emojiRedCross = "$([char]0x274C)" | ||
|
||
Write-Output "Running test-install-windows-10-sdk.ps1 with ExpectedExitCode=$ExpectedExitCode and ExpectedErrorKeyphrase=$ExpectedErrorKeyphrase" | ||
|
||
if (($ExpectedExitCode -eq 0) -and ($ExpectedErrorKeyphrase -ne "")) { | ||
Write-Output "$emojiRedCross Expected call to succeed (expected error code = 0), but given an error keyphrase to check." | ||
exit 1 | ||
} | ||
|
||
$output = & "$PSScriptRoot\..\bin\install_windows_10_sdk.ps1" -DryRun | ||
$exitCode = $LASTEXITCODE | ||
|
||
if ($exitCode -ne $ExpectedExitCode) { | ||
Write-Output "$emojiRedCross Expected exit code $ExpectedExitCode, got $exitCode" | ||
Write-Output "Output was:" | ||
Write-Output "$output" | ||
exit 1 | ||
} else { | ||
Write-Output "$emojiGreenCheck Exit code matches expected value ($ExpectedExitCode)" | ||
} | ||
|
||
# Only check error keyphrase if exit code is not 0 | ||
if ($exitCode -eq 0) { | ||
exit 0 | ||
} | ||
|
||
# If keyphrase is empty, assume the caller is satisfied with only testing the exit code | ||
if ($ExpectedErrorKeyphrase -eq "") { | ||
Write-Output "Exit code match expectation and no error keyphrase was provided. Test completed." | ||
exit 0 | ||
} | ||
|
||
if ($output -match [regex]::Escape($ExpectedErrorKeyphrase)) { | ||
Write-Output "$emojiGreenCheck Error keyphrase matches expected value ($ExpectedErrorKeyphrase)" | ||
Write-Output "Test completed." | ||
} else { | ||
Write-Output "$emojiRedCross Expected error to contain '$ExpectedErrorKeyphrase', but got:" | ||
Write-Output "$output" | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Tests the prepare_windows_host_for_app_distribution.ps1 script with the -SkipWindows10SDKInstallation parameter. | ||
# | ||
# We only test the skip behavior because the installation takes a "long" time to run. | ||
|
||
param ( | ||
[int]$ExpectedExitCode = 0 | ||
) | ||
|
||
# Ensure the output is UTF-8 encoded so we can use emojis... | ||
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | ||
$emojiGreenCheck = "$([char]0x2705)" | ||
$emojiRedCross = "$([char]0x274C)" | ||
|
||
Write-Output "Testing prepare_windows_host_for_app_distribution.ps1 with -SkipWindows10SDKInstallation" | ||
|
||
# Create a valid SDK version file to ensure it's not being used | ||
$sdkVersion = "20348" | ||
"$sdkVersion" | Out-File .windows-10-sdk-version | ||
|
||
# Run the script with skip parameter | ||
$output = & "$PSScriptRoot\..\bin\prepare_windows_host_for_app_distribution.ps1" -SkipWindows10SDKInstallation | ||
$exitCode = $LASTEXITCODE | ||
|
||
# Check exit code | ||
if ($exitCode -ne $ExpectedExitCode) { | ||
Write-Output "$emojiRedCross Expected exit code $ExpectedExitCode, got $exitCode" | ||
Write-Output "Output was:" | ||
Write-Output "$output" | ||
exit 1 | ||
} else { | ||
Write-Output "$emojiGreenCheck Exit code matches expected value ($ExpectedExitCode)" | ||
} | ||
|
||
$expectedSkipMessage = "Run with SkipWindows10SDKInstallation = true. Skipping Windows 10 SDK installation check." | ||
if ($output -match [regex]::Escape($expectedSkipMessage)) { | ||
Write-Output "$emojiGreenCheck Found expected skip message in output" | ||
} else { | ||
Write-Output "$emojiRedCross Expected to find message about skipping due to parameter, but got:" | ||
Write-Output "$output" | ||
exit 1 | ||
} | ||
|
||
# Verify SDK was not installed by checking the file system | ||
$windowsSDKsRoot = "C:\Program Files (x86)\Windows Kits\10\bin" | ||
$sdkPath = "$windowsSDKsRoot\10.0.$sdkVersion\x64" | ||
If (Test-Path $sdkPath) { | ||
Write-Output "$emojiRedCross Found SDK installation at $sdkPath when it should have been skipped" | ||
exit 1 | ||
} else { | ||
Write-Output "$emojiGreenCheck Confirmed SDK was not installed at $sdkPath" | ||
} | ||
|
||
Write-Output "Test completed successfully." |