Skip to content

Commit 67987fc

Browse files
Move tests to PS7 and PS7.1 and fix IsNetCore check (#1318)
* move tests to PS7 and PS7.1 * fix up build script * remove 6.2 * change global.json back * remove using dotnet already installed * install ahead of time * remove global.json * continueOnError * use different url * test new rcedit * different splat mechanic * move back to aka * no platform check * use channel only
1 parent ccec61c commit 67987fc

File tree

9 files changed

+97
-74
lines changed

9 files changed

+97
-74
lines changed

.vsts-ci/templates/ci-general.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ steps:
1414
# Using `prependpath` to update the PATH just for this build.
1515
Write-Host "##vso[task.prependpath]$powerShellPath"
1616
displayName: Install PowerShell Daily
17+
continueOnError: true
1718
1819
- pwsh: '$PSVersionTable'
1920
displayName: Display PowerShell version information

PowerShellEditorServices.build.ps1

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ param(
1919
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
2020

2121
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
22-
$script:RequiredSdkVersion = (Get-Content (Join-Path $PSScriptRoot 'global.json') | ConvertFrom-Json).sdk.version
2322
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs")
2423
$script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props")
2524
$script:IsPreview = [bool]($script:PsesCommonProps.Project.PropertyGroup.VersionSuffix)
2625

2726
$script:NetRuntime = @{
28-
Core = 'netcoreapp2.1'
27+
PS62 = 'netcoreapp2.1'
28+
PS7 = 'netcoreapp3.1'
29+
PS71 = 'net5.0'
2930
Desktop = 'net461'
3031
Standard = 'netstandard2.0'
3132
}
3233

33-
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Core)/publish"
34+
$script:HostCoreOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.PS62)/publish"
3435
$script:HostDeskOutput = "$PSScriptRoot/src/PowerShellEditorServices.Hosting/bin/$Configuration/$($script:NetRuntime.Desktop)/publish"
3536
$script:PsesOutput = "$PSScriptRoot/src/PowerShellEditorServices/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
3637
$script:VSCodeOutput = "$PSScriptRoot/src/PowerShellEditorServices.VSCode/bin/$Configuration/$($script:NetRuntime.Standard)/publish"
@@ -52,64 +53,45 @@ function Invoke-WithCreateDefaultHook {
5253
}
5354
}
5455

55-
task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestE2E {
56+
function Install-Dotnet {
57+
param (
58+
$Channel
59+
)
5660

57-
$dotnetPath = "$PSScriptRoot/.dotnet"
58-
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
59-
$originalDotNetExePath = $dotnetExePath
61+
Write-Host "`n### Installing .NET CLI $Version...`n" -ForegroundColor Green
6062

61-
if (!(Test-Path $dotnetExePath)) {
62-
$installedDotnet = Get-Command dotnet -ErrorAction Ignore
63-
if ($installedDotnet) {
64-
$dotnetExePath = $installedDotnet.Source
65-
}
66-
else {
67-
$dotnetExePath = $null
68-
}
69-
}
63+
# The install script is platform-specific
64+
$installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" }
7065

71-
# Make sure the dotnet we found is the right version
72-
if ($dotnetExePath) {
73-
# dotnet --version can write to stderr, which causes builds to abort, therefore use --list-sdks instead.
74-
if ((& $dotnetExePath --list-sdks | ForEach-Object { $_.Split()[0] } ) -contains $script:RequiredSdkVersion) {
75-
$script:dotnetExe = $dotnetExePath
76-
}
77-
else {
78-
# Clear the path so that we invoke installation
79-
$script:dotnetExe = $null
80-
}
81-
}
82-
else {
83-
# Clear the path so that we invoke installation
84-
$script:dotnetExe = $null
85-
}
66+
# Download the official installation script and run it
67+
$installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt"
68+
Invoke-WebRequest "https://dot.net/v1/dotnet-install.$installScriptExt" -OutFile $installScriptPath
69+
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
8670

87-
if ($script:dotnetExe -eq $null) {
71+
if ($script:IsUnix) {
72+
chmod +x $installScriptPath
73+
}
8874

89-
Write-Host "`n### Installing .NET CLI $script:RequiredSdkVersion...`n" -ForegroundColor Green
75+
$paramArr = @('-Channel', $Channel, '-InstallDir', "'$env:DOTNET_INSTALL_DIR'", '-NoPath')
76+
Invoke-Expression "$installScriptPath $paramArr"
77+
$env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH
9078

91-
# The install script is platform-specific
92-
$installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" }
79+
Write-Host "`n### Installation complete." -ForegroundColor Green
80+
}
9381

94-
# Download the official installation script and run it
95-
$installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt"
96-
Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/sdk/master/scripts/obtain/dotnet-install.$installScriptExt" -OutFile $installScriptPath
97-
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
82+
task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E {
9883

99-
if (!$script:IsUnix) {
100-
& $installScriptPath -Version $script:RequiredSdkVersion -InstallDir "$env:DOTNET_INSTALL_DIR"
101-
}
102-
else {
103-
& /bin/bash $installScriptPath -Version $script:RequiredSdkVersion -InstallDir "$env:DOTNET_INSTALL_DIR"
104-
$env:PATH = $dotnetExeDir + [System.IO.Path]::PathSeparator + $env:PATH
105-
}
84+
$dotnetPath = "$PSScriptRoot/.dotnet"
85+
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
10686

107-
Write-Host "`n### Installation complete." -ForegroundColor Green
108-
$script:dotnetExe = $originalDotnetExePath
87+
if (!(Test-Path $dotnetExePath)) {
88+
Install-Dotnet -Channel '2.1'
89+
Install-Dotnet -Channel '3.1'
90+
Install-Dotnet -Channel 'release/5.0.1xx-preview6'
10991
}
11092

11193
# This variable is used internally by 'dotnet' to know where it's installed
112-
$script:dotnetExe = Resolve-Path $script:dotnetExe
94+
$script:dotnetExe = Resolve-Path $dotnetExePath
11395
if (!$env:DOTNET_INSTALL_DIR)
11496
{
11597
$dotnetExeDir = [System.IO.Path]::GetDirectoryName($script:dotnetExe)
@@ -228,7 +210,7 @@ task SetupHelpForTests -Before Test {
228210

229211
task Build BinClean,{
230212
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -f $script:NetRuntime.Standard }
231-
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Core }
213+
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.PS62 }
232214
if (-not $script:IsUnix)
233215
{
234216
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
@@ -245,15 +227,24 @@ function DotNetTestFilter {
245227

246228
task Test TestServer,TestE2E
247229

248-
task TestServer {
230+
task TestServer TestServerWinPS,TestServerPS7,TestServerPS71
231+
232+
task TestServerWinPS -If (-not $script:IsUnix) {
249233
Set-Location .\test\PowerShellEditorServices.Test\
234+
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Desktop (DotNetTestFilter) }
235+
}
250236

251-
if (-not $script:IsUnix) {
252-
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Desktop (DotNetTestFilter) }
237+
task TestServerPS7 {
238+
Set-Location .\test\PowerShellEditorServices.Test\
239+
Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath {
240+
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS7 (DotNetTestFilter) }
253241
}
242+
}
254243

244+
task TestServerPS71 {
245+
Set-Location .\test\PowerShellEditorServices.Test\
255246
Invoke-WithCreateDefaultHook -NewModulePath $script:PSCoreModulePath {
256-
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) }
247+
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS71 (DotNetTestFilter) }
257248
}
258249
}
259250

@@ -265,21 +256,21 @@ task TestHost {
265256
exec { & $script:dotnetExe test -f $script:NetRuntime.Desktop (DotNetTestFilter) }
266257
}
267258

268-
exec { & $script:dotnetExe build -c $Configuration -f $script:NetRuntime.Core }
269-
exec { & $script:dotnetExe test -f $script:NetRuntime.Core (DotNetTestFilter) }
259+
exec { & $script:dotnetExe build -c $Configuration -f $script:NetRuntime.PS62 }
260+
exec { & $script:dotnetExe test -f $script:NetRuntime.PS62 (DotNetTestFilter) }
270261
}
271262

272263
task TestE2E {
273264
Set-Location .\test\PowerShellEditorServices.Test.E2E\
274265

275266
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
276-
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) }
267+
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS62 (DotNetTestFilter) }
277268

278269
# Run E2E tests in ConstrainedLanguage mode.
279270
if (!$script:IsUnix) {
280271
try {
281272
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine);
282-
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.Core (DotNetTestFilter) }
273+
exec { & $script:dotnetExe test --logger trx -f $script:NetRuntime.PS62 (DotNetTestFilter) }
283274
} finally {
284275
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
285276
}
@@ -303,10 +294,6 @@ task LayoutModule -After Build {
303294
# Copy Third Party Notices.txt to module folder
304295
Copy-Item -Force -Path "$PSScriptRoot\Third Party Notices.txt" -Destination $psesOutputPath
305296

306-
# Copy UnixConsoleEcho native libraries
307-
Copy-Item -Path "$script:PsesOutput/runtimes/osx-64/native/*" -Destination $psesDepsPath -Force
308-
Copy-Item -Path "$script:PsesOutput/runtimes/linux-64/native/*" -Destination $psesDepsPath -Force
309-
310297
# Assemble PSES module
311298

312299
$includedDlls = [System.Collections.Generic.HashSet[string]]::new()

global.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/PowerShellEditorServices/Utility/VersionUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class VersionUtils
1717
/// <summary>
1818
/// True if we are running on .NET Core, false otherwise.
1919
/// </summary>
20-
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
20+
public static bool IsNetCore { get; } = !RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.Ordinal);
2121

2222
/// <summary>
2323
/// Gets the Version of PowerShell being used.

test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ internal class CompleteCommandFromModule
3030
CompletionDetails.Create(
3131
"Get-Random",
3232
CompletionType.Command,
33-
string.Join(Environment.NewLine + Environment.NewLine, s_getRandomParamSets)
33+
string.Join(Environment.NewLine + Environment.NewLine, s_getRandomParamSets),
34+
listItemText: "Get-Random"
3435
);
3536
}
3637
}

test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,18 @@ await this.GetCompletionResults(
7878
CompleteCommandFromModule.SourceDetails);
7979

8080
Assert.NotEmpty(completionResults.Completions);
81+
8182
Assert.Equal(
82-
CompleteCommandFromModule.ExpectedCompletion,
83-
completionResults.Completions[0]);
83+
CompleteCommandFromModule.ExpectedCompletion.CompletionText,
84+
completionResults.Completions[0].CompletionText
85+
);
86+
87+
Assert.Equal(
88+
CompleteCommandFromModule.ExpectedCompletion.CompletionType,
89+
completionResults.Completions[0].CompletionType
90+
);
91+
92+
Assert.NotNull(completionResults.Completions[0].ToolTipText);
8493
}
8594

8695
[Trait("Category", "Completions")]

test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
4+
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
55
<AssemblyName>Microsoft.PowerShell.EditorServices.Test</AssemblyName>
66
</PropertyGroup>
77
<PropertyGroup>
@@ -12,6 +12,12 @@
1212
<ProjectReference Include="..\..\src\PowerShellEditorServices\PowerShellEditorServices.csproj" />
1313
<ProjectReference Include="..\PowerShellEditorServices.Test.Shared\PowerShellEditorServices.Test.Shared.csproj" />
1414
</ItemGroup>
15+
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
16+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.0-preview.3" />
17+
</ItemGroup>
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
19+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.2" />
20+
</ItemGroup>
1521
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
1622
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.4" />
1723
</ItemGroup>
@@ -33,7 +39,7 @@
3339
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3440
</None>
3541
</ItemGroup>
36-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
42+
<PropertyGroup Condition=" '$(TargetFramework)' != 'net461' ">
3743
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
3844
</PropertyGroup>
3945
</Project>

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void CanRecurseDirectoryTree()
9797
ignoreReparsePoints: s_defaultIgnoreReparsePoints
9898
);
9999

100-
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"))
100+
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
101101
{
102102
// .Net Core doesn't appear to use the same three letter pattern matching rule although the docs
103103
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Utility;
7+
using Xunit;
8+
9+
namespace Microsoft.PowerShell.EditorServices.Test.Utility
10+
{
11+
public class VersionUtilsTests
12+
{
13+
[Trait("Category", "VersionUtils")]
14+
[Fact]
15+
public void IsNetCoreTest()
16+
{
17+
#if CoreCLR
18+
Assert.True(VersionUtils.IsNetCore);
19+
#else
20+
Assert.False(VersionUtils.IsNetCore);
21+
#endif
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)