fix tests

This commit is contained in:
Maxim Lobanov
2020-11-01 11:13:45 +03:00
parent b49a705f6b
commit 85b8007337
3 changed files with 92 additions and 69 deletions

View File

@@ -2,39 +2,39 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1"
Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1"
Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1"
$XCODE_VERSIONS = Get-ToolsetValue "xcode.versions"
$DEFAULT_XCODE = Get-ToolsetValue "xcode.default"
$LATEST_XCODE_VERSION = $XCODE_VERSIONS | Select-Object -First 1
$OS = Get-OSVersion
$xcodeVersions = Get-ToolsetValue "xcode.versions"
$defaultXcode = Get-ToolsetValue "xcode.default"
$latestXcodeVersion = $xcodeVersions | Select-Object -First 1
$os = Get-OSVersion
Describe "Xcode" {
It "Default Xcode is $DEFAULT_XCODE" {
$defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode }
It "Default Xcode is <DefaultXcode>" -TestCases $defaultXcodeTestCase {
"xcodebuild -version" | Should -ReturnZeroExitCode
(Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode $DEFAULT_XCODE*"
(Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*"
}
It "Xcode.app points to default Xcode" {
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
}
# Cut "_beta" postfix for test cases
$testCases = $XCODE_VERSIONS | ForEach-Object { @{XcodeVersion = $_.Split("_")[0] } }
$testCases = $xcodeVersions | ForEach-Object { @{ XcodeVersion = $_.link; LatestXcodeVersion = $xcodeVersions[0].link; Symlinks = $_.symlinks } }
It "<XcodeVersion>" -TestCases $testCases {
param ( [string] $XcodeVersion )
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
"$xcodebuildPath -version" | Should -ReturnZeroExitCode
}
It "Xcode <XcodeVersion> tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) {
param ( [string] $XcodeVersion )
$TOOLS_NOT_INSTALLED_EXIT_CODE = 69
$xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild"
$result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus"
if ($XcodeVersion -ne $LATEST_XCODE_VERSION) {
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)
@@ -42,13 +42,12 @@ Describe "Xcode" {
}
It "Xcode <XcodeVersion> has correct beta symlink" -TestCases $testCases {
param ( [string] $XcodeVersion )
$xcodesWithBetaSymlink = @("12", "9.3", "9.4")
$shouldBetaSymlinkExists = $XcodeVersion.StartsWith("10") -or $XcodeVersion.StartsWith("11") -or ($XcodeVersion -in $xcodesWithBetaSymlink)
$betaSymlinkPath = Get-XcodeRootPath -Version "${XcodeVersion}_beta"
Test-Path $betaSymlinkPath | Should -Be $shouldBetaSymlinkExists
$sourcePath = Get-XcodeRootPath -Version $XcodeVersion
$Symlinks | ForEach-Object {
$targetPath = Get-XcodeRootPath -Version $_
$targetPath | Should -Exist
(Get-Item $targetPath).Target | Should -Be $sourcePath
}
}
It "/Applications/Xcode* symlinks are valid" {
@@ -58,37 +57,32 @@ Describe "Xcode" {
$_ | Should -Exist
}
}
}
Context "XCODE_DEVELOPER_DIR" {
$stableXcodeVersions = $XCODE_VERSIONS | ForEach-Object { $_.Split("_")[0] } | Where-Object { Test-XcodeStableRelease -Version $_ }
$majorXcodeVersions = $stableXcodeVersions | ForEach-Object { $_.Split(".")[0] } | Select-Object -Unique
$testCases = $majorXcodeVersions | ForEach-Object {
$majorXcodeVersion = $_
$expectedVersion = $stableXcodeVersions | Where-Object { $_.StartsWith("$majorXcodeVersion") } | Select-Object -First 1
return @{
MajorXcodeVersion = $majorXcodeVersion
ExpectedVersion = $expectedVersion
}
Describe "XCODE_DEVELOPER_DIR variables" {
$exactVersionsList = $xcodeVersions.link | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
$xcodeRootPath = Get-XcodeRootPath -Version $_
$xcodeVersionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath
return @{
RootPath = $xcodeRootPath
Version = [SemVer]::Parse($xcodeVersionInfo.Version)
}
} | Sort-Object -Property Version -Descending
$majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique
$testCases = $majorVersions | ForEach-Object { @{ MajorVersion = $_; VersionsList = $exactVersionsList } }
It "XCODE_<MajorXcodeVersion>_DEVELOPER_DIR" -TestCases $testCases {
param (
[string] $MajorXcodeVersion,
[string] $ExpectedVersion
)
$variableName = "XCODE_${MajorXcodeVersion}_DEVELOPER_DIR"
$actualPath = Get-EnvironmentVariable $variableName
$expectedPath = Join-Path (Get-XcodeRootPath -Version $ExpectedVersion) "Contents/Developer"
$actualPath | Should -Exist
$actualPath | Should -Be $expectedPath
}
It "XCODE_<MajorVersion>_DEVELOPER_DIR" -TestCases $testCases {
$variableName = "XCODE_${MajorVersion}_DEVELOPER_DIR"
$actualPath = Get-EnvironmentVariable $variableName
$expectedVersion = $VersionsList | Where-Object { $_.Version.Major -eq $MajorVersion } | Select-Object -First 1
$expectedPath = "$($expectedVersion.RootPath)/Contents/Developer"
$actualPath | Should -Exist
$actualPath | Should -Be $expectedPath
}
}
Describe "Xcode simulators" {
$XCODE_VERSIONS | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
$xcodeVersions | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object {
Switch-Xcode -Version $_
Context "$_" {
@@ -105,7 +99,7 @@ Describe "Xcode simulators" {
}
AfterAll {
$DEFAULT_XCODE = Get-ToolsetValue "xcode.default"
Switch-Xcode -Version $DEFAULT_XCODE
$defaultXcode = Get-ToolsetValue "xcode.default"
Switch-Xcode -Version $defaultXcode
}
}