Skip to content

Move tests to PS7 and PS7.1 and fix IsNetCore check #1318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
35 changes: 23 additions & 12 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ $script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditor
$script:IsPreview = [bool]($script:PsesCommonProps.Project.PropertyGroup.VersionSuffix)

$script:NetRuntime = @{
Core = 'netcoreapp2.1'
PS6 = '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.PS6)/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"
Expand All @@ -52,7 +54,7 @@ function Invoke-WithCreateDefaultHook {
}
}

task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestE2E {
task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E {

$dotnetPath = "$PSScriptRoot/.dotnet"
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
Expand Down Expand Up @@ -228,7 +230,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.PS6 }
if (-not $script:IsUnix)
{
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Hosting\PowerShellEditorServices.Hosting.csproj -f $script:NetRuntime.Desktop }
Expand All @@ -245,15 +247,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice -- should help us ensure forward compat

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) }
}
}

Expand All @@ -265,21 +276,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.PS6 }
exec { & $script:dotnetExe test -f $script:NetRuntime.PS6 (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.PS6 (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.PS6 (DotNetTestFilter) }
} finally {
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
}
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.1.804"
"version": "5.0.100-preview.6.20318.15"
}
}
2 changes: 1 addition & 1 deletion src/PowerShellEditorServices/Utility/VersionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class VersionUtils
/// <summary>
/// True if we are running on .NET Core, false otherwise.
/// </summary>
public static bool IsNetCore { get; } = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
public static bool IsNetCore { get; } = !RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.Ordinal);

/// <summary>
/// Gets the Version of PowerShell being used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the signature of Get-Random changed so I'm asserting on less things but I think it's fine.

}

[Trait("Category", "Completions")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
<AssemblyName>Microsoft.PowerShell.EditorServices.Test</AssemblyName>
</PropertyGroup>
<PropertyGroup>
Expand All @@ -12,8 +12,11 @@
<ProjectReference Include="..\..\src\PowerShellEditorServices\PowerShellEditorServices.csproj" />
<ProjectReference Include="..\PowerShellEditorServices.Test.Shared\PowerShellEditorServices.Test.Shared.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.2.4" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.0-preview.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.2" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<PackageReference Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
Expand All @@ -33,7 +36,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0' ">
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 24 additions & 0 deletions test/PowerShellEditorServices.Test/Utility/VersionUtilsTests.cs
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

{
[Trait("Category", "VersionUtils")]
[Fact]
public void IsNetCoreTest()
{
#if CoreCLR
Assert.True(VersionUtils.IsNetCore);
#else
Assert.False(VersionUtils.IsNetCore);
#endif
}
}
}