Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/universal-intel-chipset-updater.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ function Check-ForUpdaterUpdates {
Start-Process -FilePath $outputPath

# Exit immediately without any user interaction
# Use exit code 100 to indicate successful launch of new version
[Environment]::Exit(100)
# Use exit code 0 to indicate successful launch of new version
exit 0
} else {
Write-Host "`n Update cancelled by user." -ForegroundColor Yellow
Cleanup
Expand Down
43 changes: 43 additions & 0 deletions tests/exit-code.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Describe 'universal-intel-chipset-updater.ps1' {
It 'should exit with code 0 after launching a new version' {
# Define dummy functions for Pester to find and mock.
function Show-Screen1 { }
function Verify-ScriptHash { }
function Invoke-WebRequest { }
function Read-Host { }
function Get-DownloadsFolder { }
function Start-Process { }
function Cleanup { }
function Show-FinalCredits { }

# Mock the behavior of the functions for this test case.
Mock -CommandName Show-Screen1 { }
Mock -CommandName Verify-ScriptHash { return $true }
Mock -CommandName Get-DownloadsFolder { return '/tmp' }
Mock -CommandName Start-Process { }
Mock -CommandName Cleanup { }
Mock -CommandName Show-FinalCredits { }

# Mock the network call to simulate finding a newer version.
Mock -CommandName Invoke-WebRequest {
return @{ Content = "99.9-9999.99.99" } # A fake, newer version
}

# Mock user input to follow the "download and exit" code path.
$userInput = @('N', 'Y', 'Y') # Prompts: Continue? -> N, Download? -> Y, Exit? -> Y
$inputCounter = 0
Mock -CommandName Read-Host {
$response = $userInput[$inputCounter]
$script:inputCounter++
return $response
}

# Wrap the script execution in a function
function Invoke-ScriptForTest {
. ./src/universal-intel-chipset-updater.ps1
}

# Assert that the script attempts to exit with a code of '0'.
Should -ScriptBlock ${function:Invoke-ScriptForTest} -Throw -ExceptionType ([System.Management.Automation.ExitException]) -WithMessage '0'
}
}