This PR ensures that the Get-ChocolateyVersion function only attempts to cast the Chocolatey CLI version number as a version object.
To achieve this the stdout from executing choco --version is matches against the recommended regular expression for checking SemVer strings.
Motivation and Context
When a Chocolatey for Business or Pro license is installed on a system but the licensed extension package is not yet installed, additional information is presented to the user.
This pollutes the stdout stream meaning that it is not possible to directly cast the information on this stream and a version object.
Instead, the stream is matched against a regular expression representing a valid SemVer string, and then the match (if found) is processed.
If for any reason the regular expression does not match, the function will now assert that the task has failed. This should make diagnosing failures easier.
Testing
I have tested this against a Windows Server 2016 VM where I have installed and uninstalled packages with and without a license installed (and the licensed extension missing).
I have repeated these tests on both Chocolatey CLI 1.4.0 and 2.1.0.
Operating Systems Testing
Windows Server 2016
Change Types Made
[X] Bug fix (non-breaking change).
[ ] Feature / Enhancement (non-breaking change).
[ ] Breaking change (fix or feature that could cause existing functionality to change).
Description Of Changes
This PR ensures that the
Get-ChocolateyVersion
function only attempts to cast the Chocolatey CLI version number as aversion
object.To achieve this the
stdout
from executingchoco --version
is matches against the recommended regular expression for checking SemVer strings.Motivation and Context
When a Chocolatey for Business or Pro license is installed on a system but the licensed extension package is not yet installed, additional information is presented to the user.
This pollutes the
stdout
stream meaning that it is not possible to directly cast the information on this stream and aversion
object.Instead, the stream is matched against a regular expression representing a valid SemVer string, and then the match (if found) is processed.
If for any reason the regular expression does not match, the function will now assert that the task has failed. This should make diagnosing failures easier.
Testing
I have tested this against a Windows Server 2016 VM where I have installed and uninstalled packages with and without a license installed (and the licensed extension missing).
I have repeated these tests on both Chocolatey CLI 1.4.0 and 2.1.0.
Operating Systems Testing
Change Types Made
Change Checklist
Related Issue
Fixes #132