From f92ecfe085f2356582cd5239c1a173a990df7d89 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 29 Sep 2018 22:17:03 -0700 Subject: [PATCH] Enable building with dotnet cli for non-Windows (#692) * Enable building with PSCore6 * Fix tests to work on non-Windows * Added clipboard capability for non-Windows --- .vscode/launch.json | 19 +++ GenerateFunctionHelp.ps1 | 5 +- PSReadLine.build.ps1 | 169 +++++++++++++++++---------- PSReadLine/Clipboard.cs | 104 +++++++++++++++-- PSReadLine/ConsoleLib.cs | 2 + PSReadLine/PSReadLine.csproj | 128 +++----------------- PSReadLine/packages.config | 5 - README.md | 21 ++++ TestPSReadLine/App.config | 6 - TestPSReadLine/AssemblyInfo.cs | 35 ------ TestPSReadLine/TestPSReadLine.csproj | 61 ++-------- TestPSReadLine/packages.config | 4 - appveyor.yml | 9 ++ nuget.config | 8 ++ test/AssemblyInfo.cs | 35 ------ test/BasicEditingTest.cs | 23 +++- test/CompletionTest.cs | 15 +-- test/KillYankTest.cs | 13 ++- test/PSReadLine.Tests.csproj | 148 ++++------------------- test/UnitTestReadLine.cs | 19 +-- 20 files changed, 346 insertions(+), 483 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 PSReadLine/packages.config delete mode 100644 TestPSReadLine/App.config delete mode 100644 TestPSReadLine/AssemblyInfo.cs delete mode 100644 TestPSReadLine/packages.config create mode 100644 nuget.config delete mode 100644 test/AssemblyInfo.cs diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2d929fb --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}", + "justMyCode": true, + "symbolOptions": { + "searchMicrosoftSymbolServer": true + } + } + ] +} \ No newline at end of file diff --git a/GenerateFunctionHelp.ps1 b/GenerateFunctionHelp.ps1 index 2655398..0f91a20 100644 --- a/GenerateFunctionHelp.ps1 +++ b/GenerateFunctionHelp.ps1 @@ -14,7 +14,8 @@ $t ='Microsoft.PowerShell.PSConsoleReadLine' -as [type] if ($null -ne $t -and $t.Assembly.Location -ne $ourAssembly) { # Make sure we're runnning in a non-interactive session by relaunching - powershell -NoProfile -NonInteractive -File $PSCommandPath $Configuration $OutFile + $powershell = [System.AppDomain]::CurrentDomain.FriendlyName + & $powershell -NoProfile -NonInteractive -File $PSCommandPath $Configuration $OutFile exit $LASTEXITCODE } @@ -22,7 +23,7 @@ try { Import-Module "$PSScriptRoot\bin\$Configuration\PSReadLine\PSReadLine.psd1" -$helpContent = [xml](Get-Content "$PSScriptRoot\PSReadLine\bin\$Configuration\Microsoft.PowerShell.PSReadLine.xml") +$helpContent = [xml](Get-Content "$PSScriptRoot\bin\$Configuration\PSReadLine\en-US\Microsoft.PowerShell.PSReadLine2.dll-help.xml") Set-PSReadLineOption -EditMode Windows $cmdKeyBindings = Get-PSReadLineKeyHandler -Bound diff --git a/PSReadLine.build.ps1 b/PSReadLine.build.ps1 index 62c9196..6625143 100644 --- a/PSReadLine.build.ps1 +++ b/PSReadLine.build.ps1 @@ -18,11 +18,43 @@ param([switch]$Install, [string]$Configuration = (property Configuration Release)) -use 15.0 MSBuild - # Final bits to release go here $targetDir = "bin/$Configuration/PSReadLine" +if ($PSVersionTable.PSEdition -eq "Core") +{ + $target = "netcoreapp2.1" +} +else +{ + $target = "net461" +} +Write-Verbose "Building for '$target'" -Verbose +<# +Synopsis: Ensure dotnet is installed +#> +task CheckDotnetInstalled ` +{ + $script:dotnet = (Get-Command dotnet -ErrorAction Ignore).Path + if ($script:dotnet -eq $null) + { + $searchPaths = "~/.dotnet/dotnet", "~\AppData\Local\Microsoft\dotnet\dotnet.exe" + $foundDotnet = $false + foreach ($path in $searchPaths) + { + if (Test-Path $path) + { + $foundDotnet = $true + $script:dotnet = $path + break + } + } + if (!$foundDotnet) + { + throw "Could not find 'dotnet' command. Install DotNetCore SDK and ensure it is in the path." + } + } +} <# Synopsis: Ensure nuget is installed @@ -52,21 +84,6 @@ task CheckPlatyPSInstalled ` } } - -$restoreNugetParameters = @{ - Inputs = "PSReadLine/packages.config" - # We could look for other files, but this is probably good enough. - Outputs = "PSReadLine/packages/Microsoft.PowerShell.5.ReferenceAssemblies.1.0.0/Microsoft.PowerShell.5.ReferenceAssemblies.1.0.0.nupkg" -} - -<# -Synopsis: Restore PowerShell reference assemblies -#> -task RestoreNugetPackages @restoreNugetParameters CheckNugetInstalled,{ - exec { & $nugetExe restore PSReadLine/PSReadLine.sln } -} - - $buildMamlParams = @{ Inputs = { Get-ChildItem docs/*.md } Outputs = "$targetDir/en-US/Microsoft.PowerShell.PSReadLine2.dll-help.xml" @@ -82,7 +99,7 @@ task BuildMamlHelp @buildMamlParams { $buildAboutTopicParams = @{ Inputs = { Get-ChildItem docs/about_PSReadLine.help.txt - "PSReadLine/bin/$Configuration/Microsoft.PowerShell.PSReadLine2.dll" + "PSReadLine/bin/$Configuration/$target/Microsoft.PowerShell.PSReadLine2.dll" "$PSScriptRoot/GenerateFunctionHelp.ps1" "$PSScriptRoot/CheckHelp.ps1" } @@ -97,7 +114,8 @@ task BuildAboutTopic @buildAboutTopicParams { # so the file isn't locked in any way for the rest of the build. $generatedFunctionHelpFile = New-TemporaryFile - powershell -NoProfile -NonInteractive -File $PSScriptRoot/GenerateFunctionHelp.ps1 $Configuration $generatedFunctionHelpFile.FullName + $powershell = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.Filename + & $powershell -NoProfile -NonInteractive -File $PSScriptRoot/GenerateFunctionHelp.ps1 $Configuration $generatedFunctionHelpFile.FullName assert ($LASTEXITCODE -eq 0) "Generating function help failed" $functionDescriptions = Get-Content -Raw $generatedFunctionHelpFile @@ -106,20 +124,20 @@ task BuildAboutTopic @buildAboutTopicParams { $newAboutTopic = $newAboutTopic -replace "`r`n","`n" $newAboutTopic | Out-File -FilePath $targetDir\en-US\about_PSReadLine.help.txt -NoNewline -Encoding ascii - powershell -NoProfile -NonInteractive -File $PSScriptRoot/CheckHelp.ps1 $Configuration + & $powershell -NoProfile -NonInteractive -File $PSScriptRoot/CheckHelp.ps1 $Configuration assert ($LASTEXITCODE -eq 0) "Checking help and function signatures failed" } $binaryModuleParams = @{ Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx } - Outputs = "PSReadLine/bin/$Configuration/Microsoft.PowerShell.PSReadLine2.dll" + Outputs = "PSReadLine/bin/$Configuration/$target/Microsoft.PowerShell.PSReadLine2.dll" } <# Synopsis: Build main binary module #> -task BuildMainModule @binaryModuleParams RestoreNugetPackages, { - exec { msbuild PSReadLine/PSReadLine.csproj /t:Rebuild /p:Configuration=$Configuration /p:Platform=AnyCPU } +task BuildMainModule @binaryModuleParams CheckDotnetInstalled, { + exec { & $script:dotnet publish -f $target -c $Configuration PSReadLine } } <# @@ -139,49 +157,49 @@ $buildTestParams = @{ Outputs = "TestPSReadLine/bin/$Configuration/TestPSReadLine.exe" } -<# -Synopsis: Build executable for interactive testing/development -#> -task BuildTestHost @buildTestParams BuildMainModule, { - exec { msbuild TestPSReadLine/TestPSReadLine.csproj /t:Rebuild /p:Configuration=$Configuration /p:Platform=AnyCPU } -} - - -$buildUnitTestParams = @{ - Inputs = { Get-ChildItem test/*.cs, test/PSReadLine.Tests.csproj } - Outputs = "test/bin/$Configuration/PSReadLine.Tests.dll" -} - - -<# -Synopsis: Build the unit tests -#> -task BuildTests @buildUnitTestParams BuildMainModule, { - exec { msbuild test/PSReadLine.tests.csproj /t:Rebuild /p:Configuration=$Configuration /p:Platform=AnyCPU } -} - <# Synopsis: Run the unit tests #> -task RunTests BuildTests, { - exec { - $env:PSREADLINE_TESTRUN = 1 - $runner = "$PSScriptRoot\PSReadLine\packages\xunit.runner.console.2.3.1\tools\net452\xunit.console.exe" - if ($env:APPVEYOR) +task RunTests BuildMainModule, { + $env:PSREADLINE_TESTRUN = 1 + $runner = $script:dotnet + + # need to copy implemented assemblies so test code can host powershell otherwise we have to build for a specific runtime + if ($PSVersionTable.PSEdition -eq "Core") + { + $psAssemblies = "System.Management.Automation.dll", "Newtonsoft.Json.dll", "System.Management.dll", "System.DirectoryServices.dll" + foreach ($assembly in $psAssemblies) { - $outXml = "$PSScriptRoot\xunit-results.xml" - & $runner $PSScriptRoot\test\bin\$Configuration\PSReadLine.Tests.dll -appveyor -xml $outXml - $wc = New-Object 'System.Net.WebClient' - $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", $outXml) - } - else - { - & $runner $PSScriptRoot\test\bin\$Configuration\PSReadLine.Tests.dll + if (Test-Path "$PSHOME\$assembly") + { + Copy-Item "$PSHOME\$assembly" "test\bin\$configuration\$target" + } + else + { + throw "Could not find '$PSHOME\$assembly'" + } } + } + + if ($env:APPVEYOR) + { + $outXml = "$PSScriptRoot\xunit-results.xml" + Push-Location test + exec { & $runner test --no-build -c $configuration -f $target --logger "trx;LogFileName=$outXml" } + $wc = New-Object 'System.Net.WebClient' + $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", $outXml) + Pop-Location + } + else + { + Push-Location test + exec { & $runner test --no-build -c $configuration -f $target } + Pop-Location + } + Remove-Item env:PSREADLINE_TESTRUN } -} <# Synopsis: Copy all of the files that belong in the module to one place in the layout for installation @@ -199,15 +217,35 @@ task LayoutModule BuildMainModule, BuildMamlHelp, { Copy-Item $file $targetDir } + $binPath = "PSReadLine/bin/$Configuration/$target/publish" + Copy-Item $binPath/Microsoft.PowerShell.PSReadLine2.dll $targetDir - Copy-Item PSReadLine/bin/$Configuration/Microsoft.PowerShell.PSReadLine2.dll $targetDir - Copy-Item PSReadLine/bin/$Configuration/System.Runtime.InteropServices.RuntimeInformation.dll $targetDir + if (Test-Path $binPath/System.Runtime.InteropServices.RuntimeInformation.dll) + { + Copy-Item $binPath/System.Runtime.InteropServices.RuntimeInformation.dll $targetDir + } + else + { + Write-Warning "Build using $target is not sufficient to be downlevel compatible" + } # Copy module manifest, but fix the version to match what we've specified in the binary module. $version = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine2.dll).VersionInfo.FileVersion $moduleManifestContent = Get-Content -Path 'PSReadLine/PSReadLine.psd1' -Raw - $b = Get-Content -Encoding Byte -Raw ./bin/$Configuration/PSReadLine/Microsoft.PowerShell.PSReadLine2.dll + $getContentArgs = @{ + Raw = $true; + Path = "./bin/$Configuration/PSReadLine/Microsoft.PowerShell.PSReadLine2.dll" + } + if ($PSVersionTable.PSEdition -eq 'Core') + { + $getContentArgs += @{AsByteStream = $true} + } + else + { + $getContentArgs += @{Encoding = "Byte"} + } + $b = Get-Content @getContentArgs $a = [System.Reflection.Assembly]::Load($b) $semVer = ($a.GetCustomAttributes([System.Reflection.AssemblyInformationalVersionAttribute], $false)).InformationalVersion @@ -235,7 +273,7 @@ task LayoutModule BuildMainModule, BuildMamlHelp, { <# Synopsis: Zip up the binary for release. #> -task ZipRelease RunTests, LayoutModule, { +task ZipRelease CheckDotNetInstalled, LayoutModule, RunTests, { Compress-Archive -Force -LiteralPath $targetDir -DestinationPath "bin/$Configuration/PSReadLine.zip" } @@ -307,6 +345,13 @@ task Publish -If ($Configuration -eq 'Release') LayoutModule, { Publish-Module @publishParams } +<# +Synopsis: Remove temporary items. +#> +task Clean { + git clean -fdx +} + <# Synopsis: Default build rule - build and create module layout #> diff --git a/PSReadLine/Clipboard.cs b/PSReadLine/Clipboard.cs index 582b368..8cce298 100644 --- a/PSReadLine/Clipboard.cs +++ b/PSReadLine/Clipboard.cs @@ -3,6 +3,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; @@ -10,31 +11,120 @@ namespace Microsoft.PowerShell.Internal { static class Clipboard { + private static bool? _clipboardSupported; + + private static string StartProcess( + string tool, + string args, + string stdin = "" + ) + { + ProcessStartInfo startInfo = new ProcessStartInfo(); + startInfo.UseShellExecute = false; + startInfo.RedirectStandardInput = true; + startInfo.RedirectStandardOutput = true; + startInfo.RedirectStandardError = true; + startInfo.FileName = tool; + startInfo.Arguments = args; + string stdout; + + using (Process process = new Process()) + { + process.StartInfo = startInfo; + try + { + process.Start(); + } + catch (System.ComponentModel.Win32Exception) + { + _clipboardSupported = false; + PSConsoleReadLine.Ding(); + return ""; + } + + if (stdin != "") + { + process.StandardInput.Write(stdin); + process.StandardInput.Close(); + } + stdout = process.StandardOutput.ReadToEnd(); + process.WaitForExit(250); + + _clipboardSupported = process.ExitCode == 0; + } + + return stdout; + } + public static string GetText() { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (_clipboardSupported == false) { PSConsoleReadLine.Ding(); return ""; } - string clipboardText = ""; - ExecuteOnStaThread(() => GetTextImpl(out clipboardText)); + string tool = ""; + string args = ""; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + string clipboardText = ""; + ExecuteOnStaThread(() => GetTextImpl(out clipboardText)); + return clipboardText; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + tool = "xclip"; + args = "-selection clipboard -out"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + tool = "pbpaste"; + } + else + { + _clipboardSupported = false; + PSConsoleReadLine.Ding(); + return ""; + } - return clipboardText; + return StartProcess(tool, args); } public static void SetText(string text) { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (string.IsNullOrEmpty(text)) return; + + if (_clipboardSupported == false) { PSConsoleReadLine.Ding(); return; } - if (string.IsNullOrEmpty(text)) return; + string tool = ""; + string args = ""; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT))); + return; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + tool = "xclip"; + args = "-selection clipboard -in"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + tool = "pbcopy"; + } + else + { + _clipboardSupported = false; + PSConsoleReadLine.Ding(); + return; + } - ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT))); + StartProcess(tool, args, text); } public static void SetRtf(string plainText, string rtfText) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 7ee977f..37b1655 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -12,7 +12,9 @@ namespace Microsoft.PowerShell.Internal // These two fields are used by PowerShellEditorServices to inject a // custom ReadKey implementation. This is not a public API, but it is // part of a private contract with that project. + #pragma warning disable CS0649 private static Func _readKeyOverride; + #pragma warning restore CS0649 private static Lazy> _readKeyMethod = new Lazy>( () => _readKeyOverride == null ? Console.ReadKey : _readKeyOverride); diff --git a/PSReadLine/PSReadLine.csproj b/PSReadLine/PSReadLine.csproj index 0844de3..50cff58 100644 --- a/PSReadLine/PSReadLine.csproj +++ b/PSReadLine/PSReadLine.csproj @@ -1,107 +1,19 @@  - - + - Debug - AnyCPU - {615788CB-1B9A-4B34-97B3-4608686E59CA} Library Microsoft.PowerShell.PSReadLine Microsoft.PowerShell.PSReadLine2 - v4.6.1 - 512 - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - false - bin\Debug\Microsoft.PowerShell.PSReadLine.xml - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true - false - bin\Release\Microsoft.PowerShell.PSReadLine.xml + 2.0.0.0 + 2.0.0 + 2.0.0-beta3 + net461;netcoreapp2.1 - - - - packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll - True - - - packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - True - True - PSReadLineResources.resx - - - - - - - - - - - - - - - - - ResXFileCodeGenerator - Microsoft.PowerShell.PSReadLine.PSReadLineResources.resources - PSReadLineResources.Designer.cs - Microsoft.PowerShell.PSReadLine - Designer - - - - @@ -109,23 +21,13 @@ - - - - - + + + + + + + + - - - IF EXIST ..\..\CopyDLL.cmd ( - ..\..\CopyDLL.cmd $(TargetPath) -) - - diff --git a/PSReadLine/packages.config b/PSReadLine/packages.config deleted file mode 100644 index a85d3fe..0000000 --- a/PSReadLine/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 15f3208..b6419de 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,27 @@ If you want to change the command line in some unimplmented way in your custom k [Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition ``` +## Building + +### Prerequisites + +To build PSReadLine on Windows, Linux, or macOS, you must have [.NET Core SDK 2.1.400 or newer](https://www.microsoft.com/net/download) installed. +The build script also depends on [InvokeBuild](https://www.powershellgallery.com/packages/InvokeBuild) which can be installed using: + +```powershell + install-module invokebuild -scope currentuser +``` + +### Building and running tests + +You can create a new build and run tests by simply running within PowerShell: + +```powershell + invoke-build +``` + +After a successful build, the tests are automatically run. + ## Change Log The change log is available [here](https://github.com/lzybkr/PSReadLine/blob/master/PSReadLine/Changes.txt). diff --git a/TestPSReadLine/App.config b/TestPSReadLine/App.config deleted file mode 100644 index bae5d6d..0000000 --- a/TestPSReadLine/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/TestPSReadLine/AssemblyInfo.cs b/TestPSReadLine/AssemblyInfo.cs deleted file mode 100644 index 694177a..0000000 --- a/TestPSReadLine/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestPSReadLine")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestPSReadLine")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2892ed9f-6820-48a0-819b-0452c3b5401b")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestPSReadLine/TestPSReadLine.csproj b/TestPSReadLine/TestPSReadLine.csproj index 89c5960..e8a0feb 100644 --- a/TestPSReadLine/TestPSReadLine.csproj +++ b/TestPSReadLine/TestPSReadLine.csproj @@ -1,59 +1,20 @@  - - + - Debug - AnyCPU {08218B1A-8B85-4722-9E3F-4D6C0BF58AD8} Exe Properties TestPSReadLine TestPSReadLine - v4.6.1 + net461;netcoreapp2.1 512 - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - true - - - - ..\PSReadLine\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll - True - - - - - - - - - - - - - - + + + + + @@ -64,12 +25,4 @@ - - diff --git a/TestPSReadLine/packages.config b/TestPSReadLine/packages.config deleted file mode 100644 index b4ef22e..0000000 --- a/TestPSReadLine/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 1302495..252d45b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,15 @@ image: Visual Studio 2017 +install: + - ps: | + $env:DOTNET_INSTALL_DIR = "$pwd\.dotnet" + $env:CLI_VERSION = "2.1.300" + mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null + Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dotnet/cli/release/2.1/scripts/obtain/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" + '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version $env:CLI_VERSION -InstallDir $env:DOTNET_INSTALL_DIR' + $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" + before_build: - ps: | nuget install platyPS -Version 0.9.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory . -ExcludeVersion diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..e88d0fb --- /dev/null +++ b/nuget.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/AssemblyInfo.cs b/test/AssemblyInfo.cs deleted file mode 100644 index a5f212e..0000000 --- a/test/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("UnitTestPSReadLine")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UnitTestPSReadLine")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("78ace245-ec04-43f0-b817-334ed4560845")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/BasicEditingTest.cs b/test/BasicEditingTest.cs index 5aa2252..67594e8 100644 --- a/test/BasicEditingTest.cs +++ b/test/BasicEditingTest.cs @@ -1,6 +1,7 @@ -using System; +using Microsoft.PowerShell; +using System; using System.Linq; -using Microsoft.PowerShell; +using System.Runtime.InteropServices; using Xunit; namespace Test @@ -77,16 +78,26 @@ namespace Test [Fact] public void ForwardDeleteLine() { - TestSetup(KeyMode.Cmd); + ConsoleKeyInfo deleteToEnd; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + TestSetup(KeyMode.Cmd); + deleteToEnd = _.CtrlEnd; + } + else + { + TestSetup(KeyMode.Emacs); + deleteToEnd = _.CtrlK; + } // Empty input (does nothing but don't crash) - Test("", Keys("", _.CtrlEnd)); + Test("", Keys("", deleteToEnd)); // at end of input - doesn't change anything - Test("abc", Keys("abc", _.CtrlEnd)); + Test("abc", Keys("abc", deleteToEnd)); // More normal usage - actually delete stuff - Test("a", Keys("abc", _.LeftArrow, _.LeftArrow, _.CtrlEnd)); + Test("a", Keys("abc", _.LeftArrow, _.LeftArrow, deleteToEnd)); } [Fact] diff --git a/test/CompletionTest.cs b/test/CompletionTest.cs index 541e3e1..dcb32ba 100644 --- a/test/CompletionTest.cs +++ b/test/CompletionTest.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.ObjectModel; +using System.IO; using System.Management.Automation; using System.Reflection; using Microsoft.PowerShell; @@ -164,17 +165,17 @@ namespace Test Test("", Keys( "Get-Directory", _.Tab, - CheckThat(() => AssertLineIs("abc\\")), + CheckThat(() => AssertLineIs("abc" + Path.DirectorySeparatorChar)), _.Tab, - CheckThat(() => AssertLineIs("'e f\\'")), + CheckThat(() => AssertLineIs("'e f" + Path.DirectorySeparatorChar + "'")), CheckThat(() => AssertCursorLeftIs(5)), _.Tab, - CheckThat(() => AssertLineIs("a\\")), + CheckThat(() => AssertLineIs("a" + Path.DirectorySeparatorChar)), _.Tab, - CheckThat(() => AssertLineIs("'a b\\'")), + CheckThat(() => AssertLineIs("'a b" + Path.DirectorySeparatorChar + "'")), CheckThat(() => AssertCursorLeftIs(5)), _.Tab, - CheckThat(() => AssertLineIs("\"a b\\\"")), + CheckThat(() => AssertLineIs("\"a b" + Path.DirectorySeparatorChar + "\"")), CheckThat(() => AssertCursorLeftIs(5)), _.CtrlC, InputAcceptedNow)); } @@ -234,8 +235,8 @@ namespace Test completions.Add(new CompletionResult("abc", "abc", CompletionResultType.ProviderContainer, "abc")); completions.Add(new CompletionResult("'e f'", "'e f'", CompletionResultType.ProviderContainer, "'e f'")); completions.Add(new CompletionResult("a", "a", CompletionResultType.ProviderContainer, "a")); - completions.Add(new CompletionResult("'a b\\'", "a b\\'", CompletionResultType.ProviderContainer, "a b\\'")); - completions.Add(new CompletionResult("\"a b\\\"", "\"a b\\\"", CompletionResultType.ProviderContainer, "\"a b\\\"")); + completions.Add(new CompletionResult("'a b" + Path.DirectorySeparatorChar + "'", "a b" + Path.DirectorySeparatorChar + "'", CompletionResultType.ProviderContainer, "a b" + Path.DirectorySeparatorChar + "'")); + completions.Add(new CompletionResult("\"a b" + Path.DirectorySeparatorChar + "\"", "\"a b" + Path.DirectorySeparatorChar + "\"", CompletionResultType.ProviderContainer, "\"a b" + Path.DirectorySeparatorChar + "\"")); break; case "invalid result 1": replacementIndex = -1; diff --git a/test/KillYankTest.cs b/test/KillYankTest.cs index fc980a5..548c4d4 100644 --- a/test/KillYankTest.cs +++ b/test/KillYankTest.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Windows; using Microsoft.PowerShell; using Xunit; +using Microsoft.PowerShell.Internal; namespace Test { @@ -304,10 +305,10 @@ namespace Test { TestSetup(KeyMode.Cmd); - ExecuteOnSTAThread(() => Clipboard.SetText("pastetest1")); + Clipboard.SetText("pastetest1"); Test("pastetest1", Keys(_.CtrlV)); - ExecuteOnSTAThread(() => Clipboard.SetText("pastetest2")); + Clipboard.SetText("pastetest2"); Test("echo pastetest2", Keys( "echo foobar", _.CtrlShiftLeftArrow, _.CtrlV)); } @@ -317,7 +318,7 @@ namespace Test { TestSetup(KeyMode.Cmd); - ExecuteOnSTAThread(() => Clipboard.SetText("")); + Clipboard.SetText(""); Test("", Keys( "cuttest1", _.CtrlShiftLeftArrow, _.CtrlX)); AssertClipboardTextIs("cuttest1"); @@ -328,12 +329,12 @@ namespace Test { TestSetup(KeyMode.Cmd); - ExecuteOnSTAThread(() => Clipboard.SetText("")); + Clipboard.SetText(""); Test("copytest1", Keys( "copytest1", _.CtrlShiftC)); AssertClipboardTextIs("copytest1"); - ExecuteOnSTAThread(() => Clipboard.SetText("")); + Clipboard.SetText(""); Test("echo copytest2", Keys( "echo copytest2", _.CtrlShiftLeftArrow, _.CtrlShiftC)); AssertClipboardTextIs("copytest2"); @@ -344,7 +345,7 @@ namespace Test { TestSetup(KeyMode.Cmd); - ExecuteOnSTAThread(() => Clipboard.SetText("")); + Clipboard.SetText(""); Test("echo copytest2", Keys( "echo copytest2", _.CtrlShiftLeftArrow, _.CtrlC)); AssertClipboardTextIs("copytest2"); diff --git a/test/PSReadLine.Tests.csproj b/test/PSReadLine.Tests.csproj index 0d80631..dc44bbc 100644 --- a/test/PSReadLine.Tests.csproj +++ b/test/PSReadLine.Tests.csproj @@ -1,104 +1,47 @@  - - - - + - Debug - AnyCPU {8ED51D01-158C-4B29-824A-35B9B861E45A} - Library + library Properties UnitTestPSReadLine PSReadLine.Tests - v4.6.1 + net461;netcoreapp2.1 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\PSReadLine\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.0.0\lib\net4\System.Management.Automation.dll - True - - - - ..\PSReadLine\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - - - ..\PSReadLine\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll - - - ..\PSReadLine\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll - - - ..\PSReadLine\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll + + + + + + + + + + + + + + + + False + $(windir)\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll - - - - - - - - - + Keys.cs CharMap.cs - - - - - - - - - - - - - - - - - - - - - - - + + Clipboard.cs + @@ -109,47 +52,4 @@ - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - diff --git a/test/UnitTestReadLine.cs b/test/UnitTestReadLine.cs index 0b01bdc..390bc2e 100644 --- a/test/UnitTestReadLine.cs +++ b/test/UnitTestReadLine.cs @@ -408,7 +408,7 @@ namespace Test { static ReadLine() { - var iss = InitialSessionState.CreateDefault2(); + var iss = InitialSessionState.CreateDefault(); var rs = RunspaceFactory.CreateRunspace(iss); rs.Open(); Runspace.DefaultRunspace = rs; @@ -528,22 +528,7 @@ namespace Test private static string GetClipboardText() { - string fromClipboard = null; - ExecuteOnSTAThread(() => - { - for (int i = 0; i < 5; i++) - { - try - { - Assert.True(Clipboard.ContainsText()); - fromClipboard = Clipboard.GetText(); - } - catch (System.Runtime.InteropServices.COMException) - { - } - } - }); - return fromClipboard; + return Clipboard.GetText(); } private void AssertClipboardTextIs(string text)