diff --git a/.vsts-ci/templates/ci-general.yml b/.vsts-ci/templates/ci-general.yml index f7e20037c..34b81b7c1 100644 --- a/.vsts-ci/templates/ci-general.yml +++ b/.vsts-ci/templates/ci-general.yml @@ -14,6 +14,7 @@ steps: # Using `prependpath` to update the PATH just for this build. Write-Host "##vso[task.prependpath]$powerShellPath" displayName: Install PowerShell Daily + continueOnError: true - pwsh: '$PSVersionTable' displayName: Display PowerShell version information diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 89c44260f..34583f1be 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -19,18 +19,19 @@ param( #Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"} $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows -$script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version $script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs") $script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props") $script:IsPreview = [bool]($script:PsesCommonProps.Project.PropertyGroup.VersionSuffix) $script:NetRuntime = @{ - Core = 'netcoreapp2.1' + PS62 = 'netcoreapp2.1' + PS7 = 'netcoreapp3.1' + PS71 = 'net5.0' Desktop = 'net461' Standard = 'netstandard2.0' } -$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Core)/publish" +$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.PS62)/publish" $script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Desktop)/publish" $script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetRuntime.Standard)/publish" $script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetRuntime.Standard)/publish" @@ -52,64 +53,45 @@ function Invoke-WithCreateDefaultHook { } } -task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestE2E { +function Install-Dotnet { + param ( + $Channel + ) - $dotnetPath = "$PSScriptRoot/.dotnet" - $dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" } - $originalDotNetExePath = $dotnetExePath + Write-Host "`n### Installing .NET CLI $Version...`n" -ForegroundColor Green - if (!(Test-Path $dotnetExePath)) { - $installedDotnet = Get-Command dotnet -ErrorAction Ignore - if ($installedDotnet) { - $dotnetExePath = $installedDotnet.Source - } - else { - $dotnetExePath = $null - } - } + # The install script is platform-specific + $installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" } - # Make sure the dotnet we found is the right version - if ($dotnetExePath) { - # dotnet --version can write to stderr, which causes builds to abort, therefore use --list-sdks instead. - if ((& $dotnetExePath --list-sdks | ForEach-Object { $_.Split()[0] } ) -contains $script:RequiredSdkVersion) { - $script:dotnetExe = $dotnetExePath - } - else { - # Clear the path so that we invoke installation - $script:dotnetExe = $null - } - } - else { - # Clear the path so that we invoke installation - $script:dotnetExe = $null - } + # Download the official installation script and run it + $installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt" + Invoke-WebRequest "https://dot.net/v1/dotnet-install.$installScriptExt" -OutFile $installScriptPath + $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" - if ($script:dotnetExe -eq $null) { + if ($script:IsUnix) { + chmod +x $installScriptPath + } - Write-Host "`n### Installing .NET CLI $script:RequiredSdkVersion...`n" -ForegroundColor Green + $paramArr = @('-Channel', $Channel, '-InstallDir', "'$env:DOTNET_INSTALL_DIR'", '-NoPath') + Invoke-Expression "$installScriptPath $paramArr" + $env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH - # The install script is platform-specific - $installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" } + Write-Host "`n### Installation complete." -ForegroundColor Green +} - # Download the official installation script and run it - $installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt" - Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/sdk/master/scripts/obtain/dotnet-install.$installScriptExt" -OutFile $installScriptPath - $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" +task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E { - if (!$script:IsUnix) { - & $installScriptPath -Version $script:RequiredSdkVersion -InstallDir "$env:DOTNET_INSTALL_DIR" - } - else { - & /bin/bash $installScriptPath -Version $script:RequiredSdkVersion -InstallDir "$env:DOTNET_INSTALL_DIR" - $env:PATH = $dotnetExeDir + [System.IO.Path]::PathSeparator + $env:PATH - } + $dotnetPath = "$PSScriptRoot/.dotnet" + $dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" } - Write-Host "`n### Installation complete." -ForegroundColor Green - $script:dotnetExe = $originalDotnetExePath + if (!(Test-Path $dotnetExePath)) { + Install-Dotnet -Channel '2.1' + Install-Dotnet -Channel '3.1' + Install-Dotnet -Channel 'release/5.0.1xx-preview6' } # This variable is used internally by 'dotnet' to know where it's installed - $script:dotnetExe = Resolve-Path $script:dotnetExe + $script:dotnetExe = Resolve-Path $dotnetExePath if (!$env:DOTNET_INSTALL_DIR) { $dotnetExeDir = [System.IO.Path]::GetDirectoryName($script:dotnetExe) @@ -228,7 +210,7 @@ task SetupHelpForTests -Before Test { task Build BinClean,{ exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard } - exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Core } + exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS62 } if (-not $script:IsUnix) { exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop } @@ -245,15 +227,24 @@ function DotNetTestFilter { task Test TestServer,TestE2E -task TestServer { +task TestServer TestServerWinPS,TestServerPS7,TestServerPS71 + +task TestServerWinPS -If (-not $script:IsUnix) { Set-Location .\test\PowerShellEditorServices.Test\ + exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Desktop (DotNetTestFilter) } +} - if (-not $script:IsUnix) { - exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Desktop (DotNetTestFilter) } +task TestServerPS7 { + Set-Location .\test\PowerShellEditorServices.Test\ + Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath { + exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS7 (DotNetTestFilter) } } +} +task TestServerPS71 { + Set-Location .\test\PowerShellEditorServices.Test\ Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath { - exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) } + exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS71 (DotNetTestFilter) } } } @@ -265,21 +256,21 @@ task TestHost { exec { & $script:dotnetExe test -f $script:NetRuntime.Desktop (DotNetTestFilter) } } - exec { & $script:dotnetExe build -c $Configuration -f $script:NetRuntime.Core } - exec { & $script:dotnetExe test -f $script:NetRuntime.Core (DotNetTestFilter) } + exec { & $script:dotnetExe build -c $Configuration -f $script:NetRuntime.PS62 } + exec { & $script:dotnetExe test -f $script:NetRuntime.PS62 (DotNetTestFilter) } } task TestE2E { Set-Location .\test\PowerShellEditorServices.Test.E2E\ $env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" } - exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) } + exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS62 (DotNetTestFilter) } # Run E2E tests in ConstrainedLanguage mode. if (!$script:IsUnix) { try { [System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine); - exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) } + exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS62 (DotNetTestFilter) } } finally { [System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine); } @@ -303,10 +294,6 @@ task LayoutModule -After Build { # Copy Third Party Notices.txt to module folder Copy-Item -Force -Path "$PSScriptRoot\Third Party Notices.txt" -Destination $psesOutputPath - # Copy UnixConsoleEcho native libraries - Copy-Item -Path "$script:PsesOutput/runtimes/osx-64/native/*" -Destination $psesDepsPath -Force - Copy-Item -Path "$script:PsesOutput/runtimes/linux-64/native/*" -Destination $psesDepsPath -Force - # Assemble PSES module $includedDlls = [System.Collections.Generic.HashSet[string]]::new() diff --git a/global.json b/global.json deleted file mode 100644 index 0fe63c97e..000000000 --- a/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sdk": { - "version": "2.1.804" - } -} diff --git a/src/PowerShellEditorServices/Utility/VersionUtils.cs b/src/PowerShellEditorServices/Utility/VersionUtils.cs index 3dddd7914..e2c19ab03 100644 --- a/src/PowerShellEditorServices/Utility/VersionUtils.cs +++ b/src/PowerShellEditorServices/Utility/VersionUtils.cs @@ -17,7 +17,7 @@ internal static class VersionUtils /// /// True if we are running on .NET Core, false otherwise. /// - public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal); + public static bool IsNetCore { get; } = !RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.Ordinal); /// /// Gets the Version of PowerShell being used. diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs index e850a3590..8259d636d 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs @@ -30,7 +30,8 @@ internal class CompleteCommandFromModule CompletionDetails.Create( "Get-Random", CompletionType.Command, - string.Join(Environment.NewLine + Environment.NewLine, s_getRandomParamSets) + string.Join(Environment.NewLine + Environment.NewLine, s_getRandomParamSets), + listItemText: "Get-Random" ); } } diff --git a/test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs b/test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs index 487a4672f..346fdd841 100644 --- a/test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs @@ -78,9 +78,18 @@ await this.GetCompletionResults( CompleteCommandFromModule.SourceDetails); Assert.NotEmpty(completionResults.Completions); + Assert.Equal( - CompleteCommandFromModule.ExpectedCompletion, - completionResults.Completions[0]); + CompleteCommandFromModule.ExpectedCompletion.CompletionText, + completionResults.Completions[0].CompletionText + ); + + Assert.Equal( + CompleteCommandFromModule.ExpectedCompletion.CompletionType, + completionResults.Completions[0].CompletionType + ); + + Assert.NotNull(completionResults.Completions[0].ToolTipText); } [Trait("Category", "Completions")] diff --git a/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj b/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj index 8f84b1504..59fa2a989 100644 --- a/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj +++ b/test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;net461 + net5.0;netcoreapp3.1;net461 Microsoft.PowerShell.EditorServices.Test @@ -12,6 +12,12 @@ + + + + + + @@ -33,7 +39,7 @@ PreserveNewest - + $(DefineConstants);CoreCLR diff --git a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs index 5b15539a8..73105a75c 100644 --- a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs +++ b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs @@ -97,7 +97,7 @@ public void CanRecurseDirectoryTree() ignoreReparsePoints: s_defaultIgnoreReparsePoints ); - if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core")) + if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")) { // .Net Core doesn't appear to use the same three letter pattern matching rule although the docs // suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1' diff --git a/test/PowerShellEditorServices.Test/Utility/VersionUtilsTests.cs b/test/PowerShellEditorServices.Test/Utility/VersionUtilsTests.cs new file mode 100644 index 000000000..403afc2a8 --- /dev/null +++ b/test/PowerShellEditorServices.Test/Utility/VersionUtilsTests.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.PowerShell.EditorServices.Utility; +using Xunit; + +namespace Microsoft.PowerShell.EditorServices.Test.Utility +{ + public class VersionUtilsTests + { + [Trait("Category", "VersionUtils")] + [Fact] + public void IsNetCoreTest() + { +#if CoreCLR + Assert.True(VersionUtils.IsNetCore); +#else + Assert.False(VersionUtils.IsNetCore); +#endif + } + } +}