From 8c96dbb9bb660e512a8573514518b06976a4ba18 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 3 Nov 2020 09:13:58 +0300 Subject: [PATCH] fix tests --- .../software-report/SoftwareReport.Xcode.psm1 | 4 +- images/macos/templates/macOS-10.15.json | 6 +- images/macos/tests/Xcode.Tests.ps1 | 89 ++++++++++--------- 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/images/macos/software-report/SoftwareReport.Xcode.psm1 b/images/macos/software-report/SoftwareReport.Xcode.psm1 index 8fb84193..448e6f38 100644 --- a/images/macos/software-report/SoftwareReport.Xcode.psm1 +++ b/images/macos/software-report/SoftwareReport.Xcode.psm1 @@ -99,7 +99,7 @@ function Build-XcodeTable { } } -function Get-XcodeDevicesList { +function Build-XcodeDevicesList { param ( [Parameter(Mandatory)][object] $XcodeInfo, [Parameter(Mandatory)][object] $Runtime @@ -188,7 +188,7 @@ function Build-XcodeSimulatorsTable { $xcodeInfo.Values | ForEach-Object { $runtimeFound = $_.SimulatorsInfo.runtimes | Where-Object { $_.identifier -eq $runtime.identifier } | Select-Object -First 1 if ($runtimeFound) { - $devicesToAdd = Get-XcodeDevicesList -XcodeInfo $_ -Runtime $runtimeFound + $devicesToAdd = Build-XcodeDevicesList -XcodeInfo $_ -Runtime $runtimeFound $runtimeDevices += $devicesToAdd | Select-Object -ExpandProperty name $xcodeList += $_.VersionInfo.Version } diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index 75e0726e..c7412da1 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -136,11 +136,15 @@ "scripts": [ "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", + "./provision/core/dotnet.sh", + "./provision/core/python.sh", "./provision/core/azcopy.sh", "./provision/core/openssl.sh", "./provision/core/ruby.sh", "./provision/core/rubygem.sh", - "./provision/core/powershell.sh" + "./provision/core/powershell.sh", + "./provision/core/git.sh", + "./provision/core/node.sh" ] }, { diff --git a/images/macos/tests/Xcode.Tests.ps1 b/images/macos/tests/Xcode.Tests.ps1 index af7ac81f..78c0ca07 100644 --- a/images/macos/tests/Xcode.Tests.ps1 +++ b/images/macos/tests/Xcode.Tests.ps1 @@ -8,45 +8,53 @@ $latestXcodeVersion = $xcodeVersions | Select-Object -First 1 $os = Get-OSVersion Describe "Xcode" { - $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } - It "Default Xcode is " -TestCases $defaultXcodeTestCase { - "xcodebuild -version" | Should -ReturnZeroExitCode - (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" - } - - It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { - $xcodeApp = "/Applications/Xcode.app" - $expectedTarget = Get-XcodeRootPath -Version $DefaultXcode - $xcodeApp | Should -Exist - $expectedTarget | Should -Exist - (Get-Item $xcodeApp).Target | Should -Be $expectedTarget - } - $testCases = $xcodeVersions | ForEach-Object { @{ XcodeVersion = $_.link; LatestXcodeVersion = $xcodeVersions[0].link; Symlinks = $_.symlinks } } - It "" -TestCases $testCases { - $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" - "$xcodebuildPath -version" | Should -ReturnZeroExitCode - } - - It "Xcode tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) { - $TOOLS_NOT_INSTALLED_EXIT_CODE = 69 - $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" - $result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus" - - if ($XcodeVersion -ne $LatestXcodeVersion) { - $result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE - } else { - $result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE) + Context "Versions" { + It "" -TestCases $testCases { + $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" + "$xcodebuildPath -version" | Should -ReturnZeroExitCode } } - It "Xcode has correct beta symlink" -TestCases $testCases { - $sourcePath = Get-XcodeRootPath -Version $XcodeVersion - $Symlinks | ForEach-Object { - $targetPath = Get-XcodeRootPath -Version $_ - $targetPath | Should -Exist - (Get-Item $targetPath).Target | Should -Be $sourcePath + Context "Default" { + $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } + It "Default Xcode is " -TestCases $defaultXcodeTestCase { + "xcodebuild -version" | Should -ReturnZeroExitCode + (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" + } + + It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { + $xcodeApp = "/Applications/Xcode.app" + $expectedTarget = Get-XcodeRootPath -Version $DefaultXcode + $xcodeApp | Should -Exist + $expectedTarget | Should -Exist + (Get-Item $xcodeApp).Target | Should -Be $expectedTarget + } + } + + Context "Additional tools" { + It "Xcode tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) { + $TOOLS_NOT_INSTALLED_EXIT_CODE = 69 + $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" + $result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus" + + if ($XcodeVersion -ne $LatestXcodeVersion) { + $result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE + } else { + $result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE) + } + } + } + + Context "Symlinks" { + It "Xcode has correct symlinks" -TestCases $testCases { + $sourcePath = Get-XcodeRootPath -Version $XcodeVersion + $Symlinks | Where-Object { $_ } | ForEach-Object { + $targetPath = Get-XcodeRootPath -Version $_ + $targetPath | Should -Exist + (Get-Item $targetPath).Target | Should -Be $sourcePath + } } } @@ -82,23 +90,24 @@ Describe "XCODE_DEVELOPER_DIR variables" { } Describe "Xcode simulators" { - $xcodeVersions | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { - Switch-Xcode -Version $_ - + $xcodeVersions.link | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { Context "$_" { - It "No duplicates in devices" { + $testCase = @{ XcodeVersion = $_ } + It "No duplicates in devices" -TestCases $testCase { + Switch-Xcode -Version $XcodeVersion [array]$devicesList = @(Get-XcodeDevicesList | Where-Object { $_ }) Validate-ArrayWithoutDuplicates $devicesList -Because "Found duplicate device simulators" } - It "No duplicates in pairs" { + It "No duplicates in pairs" -TestCases $testCase { + Switch-Xcode -Version $XcodeVersion [array]$pairsList = @(Get-XcodePairsList | Where-Object { $_ }) Validate-ArrayWithoutDuplicates $pairsList -Because "Found duplicate pairs simulators" } } } - AfterAll { + AfterEach { $defaultXcode = Get-ToolsetValue "xcode.default" Switch-Xcode -Version $defaultXcode }