-
Notifications
You must be signed in to change notification settings - Fork 234
Migrate to netstandard2.0 and PSStandard #741
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
Conversation
test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1
Show resolved
Hide resolved
. .\ReferenceFileA.ps1 | ||
. .\ReferenceFileB.ps1 | ||
. .\ReferenceFileC.ps1 | ||
. ./ReferenceFileA.ps1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change shouldn't be needed and I think represents a bug where .NET Core tries to allow \
in a filename, where PowerShell would try to normalise the path... So we should deal with this properly
For testing, this was the best thing I came up with https://github.com/SeeminglyScience/PowerShellStandard-xunit-demo And it's pretty awful imo. |
Aha! I thought you might have been down this road @SeeminglyScience! |
Also, I don't actually know how Travis works, but we should change it so that:
|
@SeeminglyScience I saw the |
Now just the Host tests remain... 😎 |
The host tests are evil and I have disabled them |
So I've tried various ways to coerce the SDK into find the modules it needs to work, mainly by using a powershell.config.json. I've saved my scripts as a gist here: https://gist.github.com/rjmholt/3b9916346af42d260eeeb34512ff5be7. Unfortunately I just couldn't get them to work. In the interests in moving forward with this PR, I've just made a test hook to use Hopefully we can come up with a better fix in another PR. In any case, the underlying problem in the SDK will be fixed eventually and we won't need to do any extra work. |
@tylerl0706 @SeeminglyScience so I've added a workaround for the tests. Sadly not what I wanted, but the differences shouldn't be huge. And we still test with Anyway, please let me know re approval/changes requested. |
@@ -8,18 +8,16 @@ | |||
|
|||
namespace Microsoft.PowerShell.EditorServices | |||
{ | |||
#if PowerShellv5 | |||
|
|||
// TODO: Restore this when we figure out how to support multiple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll be able to bring this back in after this PR is merged :)
test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Shame xunit testing is so obtuse with PowerShell Standard :/
Ok this is actually really ready (@tylerl0706) |
To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
Fix session details gathering in nested prompts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Just a few more questions 😄
|
||
if ($DestinationPath -eq $null) { | ||
$DestinationPath = Join-Path $tmpDir $DllName | ||
} elseif (Test-Path $DestinationPath -PathType Container) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Test-Path
requires that the path exists. I would guess that we wouldn't expect the $DestinationPath
to exist at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not parsing your comment -- possible to rephrase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not thinking straight. Ignore that comment 😄
However, I wonder if it's worth having an else (which I assume would mean we were given a full file path) that will check if the file's directory location exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to invoke YAGNI for now. TBH I think I already over-engineered this function
PowerShellEditorServices.build.ps1
Outdated
|
||
$packageDirPath = Join-Path $tmpDir "$PackageName.$PackageVersion" | ||
if (-not (Test-Path $packageDirPath)) { | ||
$tmpNupkgPath = Join-Path $tmpDir 'tmp.zip' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe instead of using tmp.zip, use like a random GUID so we don't accidentally remove something else. It's sitting in the temp dir... so I don't feel too strongly about this if you don't want to do it.
return $DestinationPath | ||
} | ||
|
||
function Invoke-WithCreateDefaultHook { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me sad 😢 but I understand it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for a little while, then when the SDK switches back we'll be good
#if !CoreCLR | ||
string tempDir = Environment.GetEnvironmentVariable("TEMP"); | ||
#else | ||
string tempDir = Path.GetTempPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this worked in .NET Framework? It looked like it worked in Windows PowerShell
@@ -135,7 +135,8 @@ function Get-NugetAsmForRuntime { | |||
|
|||
$packageDirPath = Join-Path $tmpDir "$PackageName.$PackageVersion" | |||
if (-not (Test-Path $packageDirPath)) { | |||
$tmpNupkgPath = Join-Path $tmpDir 'tmp.zip' | |||
$guid = New-Guid | |||
$tmpNupkgPath = Join-Path $tmpDir "$guid.zip" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably do the proper clean up here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like after you expand-archive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
exec { & $script:dotnetExe xunit -f $script:TestRuntime.Core --fx-version $script:NetCoreTestingFrameworkVersion } | ||
} | ||
} | ||
|
||
task TestHost -If { | ||
task TestHost { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait I thought these tests were evil? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are but ideally we can restore them at some point. The build rule exists but isn't called anywhere (used to be under task Test
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - with one little comment on clean up! 🎉
Are we ready for v2 then??
🛳 it |
Aight I'm pushing the button. Hold onto your hats |
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS. [Ignore] Fix test typos [Ignore] Use correct AppVeyor version
UPDATE: The tests are now all passing on all platforms. So I think this PR is ready to be reviewed.
Some outstanding points:
[Fact]
[Theory]
s insteadAsyncDebouncer
interval test was failing intermittently in .NET 4.6.1 and might need looking at.\file.ps1
) on *nix, but I don't think this work has caused that, just uncovered it.Old WIP comments
I've migrated PSES to netstandard2.0 and PowerShell Standard and everything seems to work. That's the easy part.But I'm also migrating the tests. I managed to get them to run on Linux by targeting the PSES build to the PowerShell SDK, and doing that I managed to find all the platform-specific parts of the existing tests (which were heavily Windows-oriented) and change them (there's one left that I think is best just commenting out for now, which tests the tooltip forImport-Module
).The current problem I'm having is:The src project is built against PSStandard, which works fine when it's imported as a module into PowerShellBut the tests need to emulate the PowerShell hosting to getPowerShellContext
to workI tried building the tests against the PowerShell SDK, but I get aSystem.IO.FileNotFoundException
when the tests run and the methods return the defaultnull
values from PSStandard's implementationI've tried things like the binding redirect entry in dotnet/standard#481 and making sure I'm using the latest xUnit 2.4.1 preview build, but haven't had any luck there. (See also xunit/xunit#1807)I also looked into trying to get the tests to recompile the src against the SDK instead with something like:test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj:src/PowerShellEditorServices/PowerShellEditorServices.csproj:(I drew upon https://stackoverflow.com/questions/45622882/can-i-pass-compilation-constants-to-a-project-reference and https://stackoverflow.com/questions/48526219/is-there-a-way-to-force-a-project-reference-to-net-standard-project-to-a-specif for info there -- trying to work out how msbuild works is painful...)But this hasn't worked either yet.So let me know if you have any suggestions!