|
| 1 | +# Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT license. See LICENSE.txt in the project root for license information. |
| 3 | + |
| 4 | +# Instances and results are sorted for consistency. |
| 5 | +Describe 'vswhere -sort -find' { |
| 6 | + BeforeAll { |
| 7 | + # Always write to 32-bit registry key. |
| 8 | + $key = New-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Setup\Reboot -Force |
| 9 | + $null = $key | New-ItemProperty -Name 3 -Value 1 -Force |
| 10 | + |
| 11 | + $files = @( |
| 12 | + 'MSBuild\15.0\Bin\MSBuild.exe' |
| 13 | + 'MSBuild\15.0\Bin\MSBuild.exe.config' |
| 14 | + 'MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 15 | + 'MSBuild\15.0\Bin\amd64\MSBuild.exe.config' |
| 16 | + ) |
| 17 | + # Populate each instance with files to find. |
| 18 | + $instances = C:\bin\vswhere.exe -all -prerelease -products * -format json | ConvertFrom-Json |
| 19 | + foreach ($file in $files) { |
| 20 | + $filePath = Join-Path -Path $instances.installationPath -ChildPath $file |
| 21 | + $null = New-Item -Path $filePath -ItemType 'File' -Value '1' -Force |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + Context 'msbuild\15.0\bin\msbuild.exe' { |
| 26 | + It 'returns 2 matches' { |
| 27 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\15.0\bin\msbuild.exe' |
| 28 | + |
| 29 | + $files.Count | Should Be 2 |
| 30 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 31 | + $files[1] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 32 | + } |
| 33 | + |
| 34 | + It '-format json returns 2 matches' { |
| 35 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\15.0\bin\msbuild.exe' -format json | ConvertFrom-Json |
| 36 | + |
| 37 | + $files.Count | Should Be 2 |
| 38 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 39 | + $files[1] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 40 | + } |
| 41 | + |
| 42 | + It '-format xml returns 2 matches' { |
| 43 | + $doc = [xml](C:\bin\vswhere.exe -sort -find 'msbuild\15.0\bin\msbuild.exe' -format xml) |
| 44 | + |
| 45 | + $doc.files.file.Count | Should Be 2 |
| 46 | + $doc.files.file[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 47 | + $doc.files.file[1] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + Context 'msbuild\**\msbuild.exe' { |
| 52 | + It 'returns 4 matches' { |
| 53 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.exe' |
| 54 | + |
| 55 | + $files.Count | Should Be 4 |
| 56 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 57 | + $files[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 58 | + $files[2] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 59 | + $files[3] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 60 | + } |
| 61 | + |
| 62 | + It '-format json returns 4 matches' { |
| 63 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.exe' -format json | ConvertFrom-Json |
| 64 | + |
| 65 | + $files.Count | Should Be 4 |
| 66 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 67 | + $files[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 68 | + $files[2] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 69 | + $files[3] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 70 | + } |
| 71 | + |
| 72 | + It '-format xml returns 4 matches' { |
| 73 | + $doc = [xml](C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.exe' -format xml) |
| 74 | + |
| 75 | + $doc.files.file.Count | Should Be 4 |
| 76 | + $doc.files.file[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 77 | + $doc.files.file[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 78 | + $doc.files.file[2] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 79 | + $doc.files.file[3] | Should Be 'C:\VS\Community\MSBuild\15.0\Bin\MSBuild.exe' |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + Context 'msbuild\**\msbuild.* -latest' { |
| 84 | + It 'returns 4 matches' { |
| 85 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.*' -latest |
| 86 | + |
| 87 | + $files.Count | Should Be 4 |
| 88 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 89 | + $files[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe.config' |
| 90 | + $files[2] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 91 | + $files[3] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe.config' |
| 92 | + } |
| 93 | + |
| 94 | + It '-format json returns 4 matches' { |
| 95 | + $files = C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.*' -latest -format json | ConvertFrom-Json |
| 96 | + |
| 97 | + $files.Count | Should Be 4 |
| 98 | + $files[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 99 | + $files[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe.config' |
| 100 | + $files[2] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 101 | + $files[3] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe.config' |
| 102 | + } |
| 103 | + |
| 104 | + It '-format xml returns 4 matches' { |
| 105 | + $doc = [xml](C:\bin\vswhere.exe -sort -find 'msbuild\**\msbuild.*' -latest -format xml) |
| 106 | + |
| 107 | + $doc.files.file.Count | Should Be 4 |
| 108 | + $doc.files.file[0] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe' |
| 109 | + $doc.files.file[1] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe.config' |
| 110 | + $doc.files.file[2] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe' |
| 111 | + $doc.files.file[3] | Should Be 'C:\VS\Enterprise\MSBuild\15.0\Bin\MSBuild.exe.config' |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments