Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for Get-VSPath for VSBuildV1 #15293

Merged
merged 10 commits into from
Sep 20, 2021
24 changes: 24 additions & 0 deletions Tasks/VSBuildV1/Tests/Get-VSPath-Use-RegKey.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[CmdletBinding()]
param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
. $PSScriptRoot\..\Get-VSPath.ps1

Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\12.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\11.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\10.0 -Name ShellFolder -ErrorAction Ignore


# Assert.

$path_14 = Get-VSPath '14.0'
$path_12 = Get-VSPath '12.0'
$path_11 = Get-VSPath '11.0'
$path_10 = Get-VSPath '10.0'

Assert-AreEqual 'use_reg_key' $path_14
Assert-AreEqual 'use_reg_key' $path_12
Assert-AreEqual 'use_reg_key' $path_11
Assert-AreEqual 'use_reg_key' $path_10
23 changes: 23 additions & 0 deletions Tasks/VSBuildV1/Tests/Get-VSPath-Use-VsWhere.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[CmdletBinding()]
param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
. $PSScriptRoot\..\Get-VSPath.ps1

$instance = New-Object Object
Add-Member -NotePropertyName installationPath -NotePropertyValue 'use_vswhere' -inputObject $instance

Register-Mock Get-VisualStudio { $instance } -- '17'
Register-Mock Get-VisualStudio { $instance } -- '16'
Register-Mock Get-VisualStudio { $instance } -- '15'

# Assert.

$path_17 = Get-VSPath '17.0'
$path_16 = Get-VSPath '16.0'
$path_15 = Get-VSPath '15.0'

Assert-AreEqual 'use_vswhere' $path_17
Assert-AreEqual 'use_vswhere' $path_16
Assert-AreEqual 'use_vswhere' $path_15
6 changes: 6 additions & 0 deletions Tasks/VSBuildV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('VSBuild Suite', function () {
});

if (psm.testSupported()) {
it('Get-VSPath use Reg Key', (done) => {
psr.run(path.join(__dirname, 'Get-VSPath-Use-RegKey.ps1'), done);
})
it('Get-VSPath use vswhere', (done) => {
psr.run(path.join(__dirname, 'Get-VSPath-Use-VsWhere.ps1'), done);
})
it('(Select-VSVersion) falls back from 14', (done) => {
psr.run(path.join(__dirname, 'Select-VSVersion.FallsBackFrom14.ps1'), done);
})
Expand Down