Skip to content

Commit 627d662

Browse files
committed
IN PROGRESS: Convert test projects to project.json
1 parent 8055c8c commit 627d662

File tree

14 files changed

+294
-27
lines changed

14 files changed

+294
-27
lines changed

.vscode/tasks.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@
1212
"args": [ "./build.ps1" ],
1313
"isBuildCommand": true,
1414
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"taskName": "test",
18+
"args": [ "./scripts/RunTests.ps1" ],
19+
"isTestCommand": true,
20+
"problemMatcher": "$msCompile"
1521
}
1622
]

appveyor.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,11 @@ branches:
2121
#init:
2222
#- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
2323

24-
# assembly_info:
25-
# patch: true
26-
# file: '**\AssemblyInfo.*'
27-
# assembly_version: '{version}'
28-
# assembly_file_version: '{version}'
29-
# assembly_informational_version: '$(core_version)$(prerelease_name)+{build}'
30-
31-
install:
32-
- git submodule -q update --init
33-
34-
# before_build:
35-
# - ps: if (Test-Path 'C:\Tools\NuGet3') { $nugetDir = 'C:\Tools\NuGet3' } else { $nugetDir = 'C:\Tools\NuGet' }; (New-Object Net.WebClient).DownloadFile('https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe', "$nugetDir\NuGet.exe")
36-
# - nuget restore PowerShellEditorServices.sln
37-
3824
build_script:
39-
- ps: ./build.ps1 -Configuration Release -BuildNumber $env:APPVEYOR_BUILD_NUMBER -PackageNuget -PackageModule
25+
- ps: ./build.ps1 -Configuration Release -BuildNumber $env:APPVEYOR_BUILD_NUMBER -PackageNuget -PackageModule
4026

4127
after_build:
4228
- ps: Get-ChildItem -Path "release/BuiltPackages/*" -Include "*.nupkg", "*.zip" | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
4329

44-
# test:
45-
# assemblies:
46-
# - Microsoft.PowerShell.EditorServices.Test.dll
47-
# - Microsoft.PowerShell.EditorServices.Test.Protocol.dll
48-
# - Microsoft.PowerShell.EditorServices.Test.Host.dll
49-
# - Microsoft.PowerShell.EditorServices.Test.Channel.WebSockets.dll
30+
test_script:
31+
- ps: ./scripts/RunTests.ps1 -Framework net451 -Configuration Release

build.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ $projectPaths = @(
3535
)
3636

3737
$testProjectPaths = @(
38-
#"test/PowerShellEditorServices.Test",
38+
"test/PowerShellEditorServices.Test.Runner",
39+
"test/PowerShellEditorServices.Test.Shared",
40+
"test/PowerShellEditorServices.Test"
3941
#"test/PowerShellEditorServices.Test.Protocol",
4042
#"test/PowerShellEditorServices.Test.Host"
4143
)

scripts/RunTests.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
param(
2+
[string[]]$TestProjects = @(
3+
"PowerShellEditorServices.Test",
4+
"PowerShellEditorServices.Test.Protocol",
5+
"PowerShellEditorServices.Test.Host"
6+
),
7+
8+
[ValidateSet("net451", "netstandard1.6")]
9+
[string]$Framework = "netstandard1.6",
10+
11+
[ValidateSet("Debug", "Release")]
12+
[string]$Configuration = "Debug",
13+
14+
[switch]$AppVeyorMode
15+
)
16+
17+
$xunitVersion = "2.2.0-*"
18+
19+
#$nugetPackagesPath = "$HOME/.nuget/packages"
20+
#$testRunnerPath = Join-Path $PSScriptRoot, ".." "test/PowerShellEditorServices.Test.Runner"
21+
#$testRunnerBinPath = Join-Path "$testRunnerPath bin/$Configuration/$Framework"
22+
#$testRunnerDllPath = Join-Path $testRunnerBinPath "Microsoft.PowerShell.EditorServices.Test.Runner.dll"
23+
24+
function Copy-TestDependencies($runnerPath) {
25+
26+
# Needed depdenendcies:
27+
# xunit.runner.utility
28+
# xunit.abstrations
29+
# xunit.assert
30+
31+
# TODO: Don't hardcode these paths, resolve them from package.lock.json
32+
if ($Framework -eq "net451") {
33+
cp $HOME/.nuget/packages/xunit.runner.utility/2.2.0-beta2-build3300/lib/net45/xunit.runner.utility.desktop.dll $runnerPath
34+
cp /home/daviwil/.nuget/packages/xunit.abstractions/2.0.1-rc2/lib/net35/xunit.abstractions.dll $runnerPath
35+
}
36+
elseif ($Framework -eq "netstandard1.6") {
37+
cp $HOME/.nuget/packages/xunit.assert/2.2.0-beta2-build3300/lib/netstandard1.0/xunit.assert.dll $runnerPath
38+
cp $HOME/.nuget/packages/xunit.runner.utility/2.2.0-beta2-build3300/lib/netstandard1.1/xunit.runner.utility.dotnet.dll $runnerPath
39+
cp $HOME/.nuget/packages/xunit.abstractions/2.0.1-rc2/lib/netstandard1.0/xunit.abstractions.dll $runnerPath
40+
}
41+
42+
# $xunitPlatform = "dotnet"
43+
44+
# $xunitPaths = Get-ChildItem $nugetPackagesPath -Recurse "2.2.0-*" | % { $_.FullName }
45+
# $xunitDlls = @(
46+
# "xunit.assert.dll",
47+
# "xunit.runner.utility.$xunitPlatform"
48+
# )
49+
# $xunitDllPaths = Get-ChildItem -Path $xunitPaths -Recurse -Include $xunitDlls
50+
51+
# Copy-Item -Path
52+
# #$projectJson = (Get-Content "$testRunnerPath/project.lock.json") -Join "`n" | ConvertFrom-Json
53+
54+
}
55+
56+
# Ideals:
57+
# - Provide paths to test assemblies
58+
# - Optionally specify test classes/names to run
59+
# - Maybe use xunit's resolvers if I can, make my own if not
60+
# - Execute tests sequentially at first, maybe in background later
61+
# - Custom output and error handling to get ideal output
62+
# - Make it possible to use AppVeyor's output system, but if not, use their API:
63+
# https://www.appveyor.com/docs/build-worker-api/#add-tests
64+
65+
# TODO: Might need to load PSES assemblies too...
66+
67+
$runnerBinPath = Join-Path $PSScriptRoot "../test/PowerShellEditorServices.Test.Runner/bin/$Configuration/$Framework/"
68+
Add-Type -Path "$runnerBinPath/Microsoft.PowerShell.EditorServices.Test.Runner.dll"
69+
70+
Copy-TestDependencies $runnerBinPath
71+
72+
$assemblyPath = Join-Path $PSScriptRoot "../test/PowerShellEditorServices.Test/bin/$Configuration/$Framework/Microsoft.PowerShell.EditorServices.Test.dll"
73+
Get-ChildItem $assemblyPath
74+
Write-Host "Running tests for assembly: $assemblyPath" -ForegroundColor Yellow
75+
76+
$runner = [Microsoft.PowerShell.EditorServices.Test.Runner.TestRunner]::new()
77+
$runner.RunTests(@($assemblyPath))

test/PowerShellEditorServices.Test.Host/DebugAdapterTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public async Task InitializeAsync()
2323
{
2424
string testLogPath =
2525
Path.Combine(
26+
#if CoreCLR
27+
AppContext.BaseDirectory,
28+
#else
2629
AppDomain.CurrentDomain.BaseDirectory,
30+
#endif
2731
"logs",
2832
this.GetType().Name,
2933
Guid.NewGuid().ToString().Substring(0, 8) + ".log");

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public async Task InitializeAsync()
2727
{
2828
string testLogPath =
2929
Path.Combine(
30+
#if CoreCLR
31+
AppContext.BaseDirectory,
32+
#else
3033
AppDomain.CurrentDomain.BaseDirectory,
34+
#endif
3135
"logs",
3236
this.GetType().Name,
3337
Guid.NewGuid().ToString().Substring(0, 8) + ".log");
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 System;
7+
using System.Threading;
8+
using Xunit;
9+
using Xunit.Runners;
10+
11+
namespace Microsoft.PowerShell.EditorServices.Test.Runner
12+
{
13+
public class TestRunner
14+
{
15+
private int exitCode = 0;
16+
17+
private object consoleLock = new object();
18+
19+
private ManualResetEvent finished;
20+
21+
public int RunTests(string[] assemblyFileNames)
22+
{
23+
XunitProject project = new XunitProject();
24+
foreach (string assemblyFileName in assemblyFileNames)
25+
{
26+
this.finished = new ManualResetEvent(false);
27+
28+
var path = System.IO.Path.GetFullPath(assemblyFileName);
29+
30+
using (var runner = AssemblyRunner.WithoutAppDomain(path))
31+
{
32+
runner.OnDiagnosticMessage = OnDiagnosticMessage;
33+
runner.OnErrorMessage = OnErrorMessage;
34+
runner.OnTestStarting = OnTestStarting;
35+
runner.OnDiscoveryComplete = OnDiscoveryComplete;
36+
runner.OnExecutionComplete = OnExecutionComplete;
37+
runner.OnTestFailed = OnTestFailed;
38+
runner.OnTestSkipped = OnTestSkipped;
39+
40+
Console.WriteLine($"Discovering tests for path {path}...");
41+
42+
runner.Start(
43+
//typeName: "LanguageServiceTests",
44+
//parallel: false,
45+
methodDisplay: TestMethodDisplay.ClassAndMethod);
46+
47+
this.finished.WaitOne();
48+
this.finished.Dispose();
49+
}
50+
};
51+
52+
return this.exitCode;
53+
}
54+
55+
private void OnDiagnosticMessage(DiagnosticMessageInfo obj)
56+
{
57+
lock (this.consoleLock)
58+
{
59+
Console.WriteLine($"DIAGNOSTIC: {obj.Message}");
60+
}
61+
}
62+
63+
private void OnTestStarting(TestStartingInfo obj)
64+
{
65+
lock (this.consoleLock)
66+
{
67+
Console.WriteLine($"Starting test {obj.TestDisplayName}...");
68+
}
69+
}
70+
71+
private void OnErrorMessage(ErrorMessageInfo obj)
72+
{
73+
lock (this.consoleLock)
74+
{
75+
Console.WriteLine($"Error while running tests:\r\n\r\n{obj.ExceptionMessage}");
76+
}
77+
}
78+
79+
private void OnDiscoveryComplete(DiscoveryCompleteInfo info)
80+
{
81+
lock (this.consoleLock)
82+
{
83+
Console.WriteLine($"Running {info.TestCasesToRun} of {info.TestCasesDiscovered} tests...");
84+
}
85+
}
86+
87+
private void OnExecutionComplete(ExecutionCompleteInfo info)
88+
{
89+
lock (this.consoleLock)
90+
{
91+
Console.WriteLine($"Finished: {info.TotalTests} tests in {Math.Round(info.ExecutionTime, 3)}s ({info.TestsFailed} failed, {info.TestsSkipped} skipped)");
92+
}
93+
94+
this.finished.Set();
95+
}
96+
97+
private void OnTestFailed(TestFailedInfo info)
98+
{
99+
lock (this.consoleLock)
100+
{
101+
Console.ForegroundColor = ConsoleColor.Red;
102+
103+
Console.WriteLine("[FAIL] {0}: {1}", info.TestDisplayName, info.ExceptionMessage);
104+
if (info.ExceptionStackTrace != null)
105+
Console.WriteLine(info.ExceptionStackTrace);
106+
107+
Console.ResetColor();
108+
}
109+
110+
exitCode = 1;
111+
}
112+
113+
private void OnTestSkipped(TestSkippedInfo info)
114+
{
115+
lock (this.consoleLock)
116+
{
117+
Console.ForegroundColor = ConsoleColor.Yellow;
118+
Console.WriteLine("[SKIP] {0}: {1}", info.TestDisplayName, info.SkipReason);
119+
Console.ResetColor();
120+
}
121+
}
122+
}
123+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "Microsoft.PowerShell.EditorServices.Test.Runner",
3+
"version": "0.7.1-beta-*",
4+
"dependencies": {
5+
"xunit": "2.2.0-beta2-*",
6+
"xunit.runner.utility": "2.2.0-beta2-*",
7+
"Microsoft.PowerShell.SDK": "1.0.0-alpha9"
8+
},
9+
"frameworks": {
10+
"net451": {
11+
},
12+
"netstandard1.6": {
13+
"imports": ["dnxcore50", "portable-net45+win8"],
14+
"buildOptions": {
15+
"define": [ "CoreCLR" ]
16+
}
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "Microsoft.PowerShell.EditorServices.Test.Shared",
3+
"version": "0.7.1-beta-*",
4+
"dependencies": {
5+
"xunit": "2.2.0-beta2-*",
6+
"Microsoft.PowerShell.SDK": "1.0.0-alpha9",
7+
"PowerShellEditorServices": "0.7.1-beta-*"
8+
},
9+
"frameworks": {
10+
"net451": {
11+
},
12+
"netstandard1.6": {
13+
"imports": ["dnxcore50", "portable-net45+win8"],
14+
"buildOptions": {
15+
"define": [ "CoreCLR" ]
16+
}
17+
}
18+
}
19+
}

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ await this.debugService.SetLineBreakpoints(
111111
string arguments = string.Join(" ", args);
112112

113113
// Execute the script and wait for the breakpoint to be hit
114-
this.powerShellContext.ExecuteScriptAtPath(
115-
debugWithParamsFile.FilePath, arguments);
114+
var executeTask =
115+
this.powerShellContext.ExecuteScriptAtPath(
116+
debugWithParamsFile.FilePath, arguments);
116117

117118
await this.AssertDebuggerStopped(debugWithParamsFile.FilePath);
118119

test/PowerShellEditorServices.Test/Language/PowerShellVersionTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
#if !CoreCLR
7+
68
using Microsoft.Win32;
79
using System;
810
using System.Diagnostics;
@@ -92,3 +94,5 @@ private void Compile(string project, string version, string versionSuffix)
9294
}
9395
}
9496

97+
98+
#endif

test/PowerShellEditorServices.Test/Session/PowerShellContextTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public async Task CanExecutePSCommand()
7373
public async Task CanQueueParallelRunspaceRequests()
7474
{
7575
// Concurrently initiate 4 requests in the session
76-
this.powerShellContext.ExecuteScriptString("$x = 100");
76+
var taskOne = this.powerShellContext.ExecuteScriptString("$x = 100");
7777
Task<RunspaceHandle> handleTask = this.powerShellContext.GetRunspaceHandle();
78-
this.powerShellContext.ExecuteScriptString("$x += 200");
79-
this.powerShellContext.ExecuteScriptString("$x = $x / 100");
78+
var taskTwo = this.powerShellContext.ExecuteScriptString("$x += 200");
79+
var taskThree = this.powerShellContext.ExecuteScriptString("$x = $x / 100");
8080

8181
PSCommand psCommand = new PSCommand();
8282
psCommand.AddScript("$x");

test/PowerShellEditorServices.Test/Utility/LoggerTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public class LoggerTests
1717
private const string testMessage = "This is a test log message.";
1818
private readonly string logFilePath =
1919
Path.Combine(
20+
#if CoreCLR
21+
AppContext.BaseDirectory,
22+
#else
2023
AppDomain.CurrentDomain.BaseDirectory,
24+
#endif
2125
"Test.log");
2226

2327
[Fact]

0 commit comments

Comments
 (0)