Skip to content

Commit dd7b6f9

Browse files
Fix running tests
1 parent 1aaddbb commit dd7b6f9

File tree

7 files changed

+76
-35
lines changed

7 files changed

+76
-35
lines changed

EditorServicesCommandSuite.build.ps1

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
[CmdletBinding()]
33
param(
44
[ValidateSet('Debug', 'Release')]
5-
[string] $Configuration = 'Debug'
5+
[string] $Configuration = 'Debug',
6+
7+
[version] $TestRuntimeVersion
68
)
79

810
$moduleName = 'EditorServicesCommandSuite'
@@ -27,16 +29,17 @@ $script:Folders = @{
2729
$script:Discovery = @{
2830
HasDocs = Test-Path ('{0}\{1}\*.md' -f $Folders.Docs, $PSCulture)
2931
HasTests = Test-Path ('{0}\*.Test.ps1' -f $Folders.Test)
32+
IsUnix = $PSEdition -eq 'Core' -and -not $IsWindows
3033
}
3134

3235
task Clean {
3336
$releaseFolder = $Folders.Release
3437
if (Test-Path $releaseFolder) {
3538
Remove-Item $releaseFolder -Recurse
3639
}
40+
3741
New-Item -ItemType Directory $releaseFolder | Out-Null
3842
New-Item -ItemType Directory $releaseFolder/RefactorCmdlets | Out-Null
39-
4043
}
4144

4245
task BuildDocs -If { $Discovery.HasDocs } {
@@ -83,7 +86,7 @@ task ResGenImpl {
8386
}
8487

8588
task BuildManaged {
86-
$script:dotnet = $dotnet = & $PSScriptRoot\tools\GetDotNet.ps1 -Unix:$Discover.IsUnix
89+
$script:dotnet = $dotnet = & $PSScriptRoot\tools\GetDotNet.ps1 -Unix:$Discovery.IsUnix
8790

8891
& $dotnet publish --framework netstandard2.0 --configuration $Configuration --verbosity q -nologo
8992
}
@@ -128,8 +131,32 @@ task Analyze -If { $Settings.ShouldAnalyze } {
128131
Invoke-ScriptAnalyzer -Path $Folders.Release -Settings $PSScriptRoot\ScriptAnalyzerSettings.psd1 -Recurse
129132
}
130133

131-
task Test -If { $Discovery.HasTests -and $Settings.ShouldTest } {
132-
Invoke-Pester -PesterOption @{ IncludeVSCodeMarker = $true }
134+
task DoTest {
135+
Push-Location $PSScriptRoot\test\EditorServicesCommandSuite.Tests
136+
try {
137+
if (-not $TestRuntimeVersion) {
138+
if ($Discovery.IsUnix) {
139+
throw 'Unable to automatically determine installed runtime version on Unix, please supply your installed runtime version and try again.'
140+
}
141+
142+
if ([string]::IsNullOrEmpty($dotnet.Source)) {
143+
throw 'Unable to automatically determine installed runtime version, please supply your installed runtime version and try again.'
144+
}
145+
146+
$dotnetFolder = Split-Path $dotnet.Source
147+
$runtimes = Resolve-Path ('{0}/shared/Microsoft.NETCore.App' -f $dotnetFolder) -ErrorAction Stop
148+
$TestRuntimeVersion = Get-ChildItem $runtimes.Path -Directory |
149+
Select-Object -First 1 -ExpandProperty Name
150+
}
151+
152+
& $dotnet xunit `
153+
-framework netcoreapp2.0 `
154+
-configuration Test `
155+
-fxversion $TestRuntimeVersion `
156+
-nologo
157+
} finally {
158+
Pop-Location
159+
}
133160
}
134161

135162
task DoInstall {
@@ -157,11 +184,11 @@ task ResGen -Jobs AssertPSResGen, ResGenImpl
157184

158185
task Build -Jobs Clean, AssertDependencies, ResGen, BuildManaged, BuildRefactorModule, CopyToRelease, BuildDocs
159186

160-
task PreRelease -Jobs Build, Analyze, Test
187+
task Test -Jobs Build, DoTest
161188

162-
task Install -Jobs PreRelease, DoInstall
189+
task Install -Jobs Test, DoInstall
163190

164-
task Publish -Jobs PreRelease, DoPublish
191+
task Publish -Jobs Test, DoPublish
165192

166193
task . Build
167194

EditorServicesCommandSuite.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorServicesCommandSuite.
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorServicesCommandSuite.PSReadLine", "src\EditorServicesCommandSuite.PSReadLine\EditorServicesCommandSuite.PSReadLine.csproj", "{BC09FB7E-60AD-4D14-82B3-32751A88C5AE}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorServicesCommandSuite.Tests", "src\EditorServicesCommandSuite.Tests\EditorServicesCommandSuite.Tests.csproj", "{79A27D11-3604-4123-81D8-100F96A206C7}"
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EditorServicesCommandSuite.Tests", "test\EditorServicesCommandSuite.Tests\EditorServicesCommandSuite.Tests.csproj", "{79A27D11-3604-4123-81D8-100F96A206C7}"
1515
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/EditorServicesCommandSuite.Common.props

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,19 @@
66
<Configurations>Debug;Release;Test</Configurations>
77
<RunCodeAnalysis>true</RunCodeAnalysis>
88
<LangVersion>7.2</LangVersion>
9+
<TargetFrameworks>netstandard2.0;netcoreapp2.0</TargetFrameworks>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<AdditionalFiles Include="..\EditorServicesCommandSuite\stylecop.json" />
1213
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="All" />
1314
</ItemGroup>
14-
<Choose>
15-
<When Condition=" '$(Configuration)' != 'Test' ">
16-
<PropertyGroup>
17-
<TargetFramework>netstandard2.0</TargetFramework>
18-
</PropertyGroup>
19-
<ItemGroup>
20-
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-04" PrivateAssets="All" />
21-
</ItemGroup>
22-
</When>
23-
<When Condition=" '$(Configuration)' == 'Test' ">
24-
<PropertyGroup>
25-
<DefineConstants>TEST</DefineConstants>
26-
<TargetFramework>netcoreapp2.0</TargetFramework>
27-
</PropertyGroup>
28-
<ItemGroup>
29-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" PrivateAssets="All" />
30-
</ItemGroup>
31-
</When>
32-
</Choose>
15+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
16+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-04" PrivateAssets="All" />
17+
</ItemGroup>
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
19+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" PrivateAssets="All" />
20+
</ItemGroup>
21+
<PropertyGroup Condition=" '$(Configuration)' == 'Test' ">
22+
<DefineConstants>TEST</DefineConstants>
23+
</PropertyGroup>
3324
</Project>

src/EditorServicesCommandSuite/Internal/CommandSuite.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ protected internal static CommandSuite Instance
7474
}
7575
}
7676

77+
internal static bool TryGetInstance(out CommandSuite instance)
78+
{
79+
instance = s_instance;
80+
return s_instance != null;
81+
}
82+
7783
/// <summary>
7884
/// Gets the diagnostics provider.
7985
/// </summary>

src/EditorServicesCommandSuite/Utility/Settings.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,22 @@ internal static string GetPathFromScope(SettingsScope scope)
103103
"EditorServicesCommandSuite",
104104
"ESCSSettings.psd1");
105105
case SettingsScope.Workspace:
106-
return string.IsNullOrWhiteSpace(CommandSuite.Instance?.DocumentContext?.Workspace)
107-
? string.Empty
108-
: Path.Combine(
109-
CommandSuite.Instance.DocumentContext.Workspace,
110-
"ESCSSettings.psd1");
106+
{
107+
CommandSuite commandSuite;
108+
if (!CommandSuite.TryGetInstance(out commandSuite))
109+
{
110+
return string.Empty;
111+
}
112+
113+
if (commandSuite.Workspace.IsUntitledWorkspace())
114+
{
115+
return string.Empty;
116+
}
117+
118+
return Path.Combine(
119+
commandSuite.Workspace.GetWorkspacePath(),
120+
"ESCSSettings.psd1");
121+
}
111122
}
112123

113124
return string.Empty;

test/EditorServicesCommandSuite.Tests/ImplementAbstractMethodsTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private async Task<string> GetRefactoredTextAsync(
6363
return await MockContext.GetRefactoredTextAsync(
6464
testString,
6565
context => Task.FromResult(
66-
ImplementAbstractMethodsRefactorProvider.GetEdits(
66+
ImplementAbstractMethodsRefactor.GetEdits(
6767
context.Ast.FindParent<TypeDefinitionAst>(),
6868
context.Ast.FindParent<TypeConstraintAst>(),
6969
context.Token,
@@ -102,6 +102,12 @@ internal static MemberOfType Property()
102102
return new MemberOfType() { _memberType = MemberTypes.Property };
103103
}
104104

105+
internal MemberOfType Static()
106+
{
107+
_isStatic = true;
108+
return this;
109+
}
110+
105111
internal MemberOfType Named(string name)
106112
{
107113
_name = name;

test/EditorServicesCommandSuite.Tests/MockContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static async Task<string> GetRefactoredTextAsync(
1818
string testString,
1919
Func<DocumentContextBase, Task<IEnumerable<DocumentEdit>>> editFactory)
2020
{
21-
Settings.SetSetting("NewLineCharacter", "\n");
21+
Settings.SetSetting("NewLine", "\n");
2222
Settings.SetSetting("TabString", "\t");
2323
var context = GetContext(testString);
2424
var sb = new StringBuilder(context.RootAst.Extent.Text);

0 commit comments

Comments
 (0)