Commit graph

1406 commits

Author SHA1 Message Date
Bruce Payette bbb4f2ea84 Fix for #4520 '-ArgumentList should accept @() or $null' (#6597)
* Fix for #4520 '-ArgumentList should accept @() or $null'
Removed the [ValidateIsNotNulOrEmpty] attribute from the parameter.

* Fixed null and @() empty list tests to not both test null

* [Feature] Fixed test issue on non-Windows; added code to suppress displaying new windows on Windows.
2018-06-22 11:29:46 -07:00
Steve Lee 6c9eea6390 Add back ADSI and WMI type accelerators (#7085) 2018-06-21 09:57:14 -07:00
Aditya Patwardhan d76cdc3c5c Fix New-TemporaryFile online help URI (#6608) 2018-06-20 12:15:50 -07:00
Bruce Payette 3a4c410499 Fix for #6855 - Measure-Object should handle scriptblock properties. (#6934)
Measure-Object should handle `ScriptBlock` properties. Fixed by renaming `MshExpression` to `PSPropertyExpression` and making it public. Then in `MeasureObjectCommand`, lifting it up to the parameter level. Previously the implementation exposed the Property as a string and
wrapped it internally as a `PSPropertyExpression`. Now the parameter type is `PSPropertyExpression` directly allowing for both wildcard strings and `ScriptBlock`.

`PSPropertyExpression` now lives in a public namespace where it can be used by cmdlet and script authors to easily add the same type of functionality to their commands. I also modified `PSPropertyExpression` to handle hashtables properly as objects so
         @{prop = 3} | measure-object prop
and
         @{prop = 3} | measure-object {$_.prop}
will work the same. (Previously the example using just the property name would fail.)
2018-06-20 00:23:11 -07:00
Hubert Bukowski 9ac701dbee Fix conditions for transcription of Write-Information command. (#6917)
Makes a transcription of Write-Information command consistent with $InfomrationPreference variable.
2018-06-16 21:11:21 +05:00
Dongbo Wang 9804ae5f97
Merge the v6.1.0-preview.3 release branch to master (#7060) 2018-06-13 15:59:27 -07:00
Dan Thompson ce3cb68551 Make Select-Object/ForEach-Object/Where-Object see dynamic properties (#6898)
Dynamic (DLR) objects work in some places today, but not others.  This change expands that support to ForEach-Object, Where-Object and the family of cmdlets that use 'MshExpression' (Select-Object, etc.).

This change addresses both wildcard and non-wildcard cases. In wildcard cases, it uses the existing support of generating PSDynamicMember objects for names returned by GetDynamicMemberNames.

In non-wildcard cases, a dynamic property access is attempted whether or not the name shows up in GetDynamicMemberNames, but a truly "blind" access is only attempted if we see that the base object is an IDMOP. If the dynamic access fails, you'll get the same or a similar error experience as before ("The property 'Blarg' cannot be found", or no error at all, depending on the cmdlet and the strict mode setting).

The included test coverage includes a stub for the.ForEach operator--once people are happy with this change, I can continue by adding support there.

This change should allegedly also have positive perf impact, though in actual perf testing, although it does seem ever-so-slightly faster, I found it difficult to measure much difference at all.
2018-06-12 23:48:34 -07:00
Steve Lee c2bbc2291a add additional checks for test that passes inconsistently (#7051) 2018-06-12 14:35:19 -07:00
Ilya e177fcaef6 CodeFactor code style cleanup: replace literal empty strings with 'string.Empty' (#6950) 2018-06-12 12:30:10 -07:00
Aditya Patwardhan 0d67d4dc3a Merged PR 3115: Use Directory.CreateDirectory instead of DirectoryInfo.CreateSubDirectory
Change to use Directory.CreateDirectory because of regression introduced by https://github.com/dotnet/corefx/pull/27810 in creating a subdirectory under root path.
2018-06-11 23:06:08 +00:00
Steve Lee 50d061148d Remove 'SemanticVersion' from 'knowntypes' list in serialization code to enable interop between WinPS and PSCore (#7016)
PowerShell serialization has a list of known PowerShell types. When an object is deserialized containing a known type it tries to deserialize the object to that specific type and throws an exception if it can't succeed. SemanticVersion only exists in PSCore6 so when remoting from Windows PowerShell or importing clixml generated from PSCore6 that contains SemanticVersion, it fails.

With this fix, it will be rehydrated as a "PSObject" with "Deseriealized.System.Management.Automation.SemanticVersion" in the 'TypeNames' in both Windows PowerShell and PowerShell Core.
2018-06-08 11:38:14 -07:00
Christoph Bergmeister fa544c33db Update links that contain 'en-us' culture (#7013)
Update links that contain 'en-us' culture to remove 'en-us' culture (if possible) and in some cases update to newer re-directed link to docs.microsoft.com
2018-06-08 10:49:03 +05:00
Steve Lee 92cb949cac Use PSReadLine 2.0.0-beta2 from PSGallery (#6998)
Removed building PSReadLine from the repository. Instead, change to downloading from PSGallery.
2018-06-06 09:42:19 -07:00
Dongbo Wang b20dd31398
Fix parser to continue parsing key-value pairs after an If-Statement value in a HashExpression (#7002)
After parsing `if () { }`, new lines are skipped in order to see if either `elseif` or `else` is present. When neither is present, we should resync back to the pointer before skipping those possibly available new lines, so that the new line tokens can be utilized by the subsequent parsing.
2018-06-06 09:38:05 -07:00
Christoph Bergmeister faf832401f Fix broken links due to PR 6899 that removed GitHub docs on installation docs, known issues and breaking changes due to complete migration to docs.microsoft.com (#6981)
* Fix broken installation links in README.md

* fix remaining broken links due to removal of breakingchanges and knownissues docs

* Remove en-us culture from docs links in readme

* Remove last en-us culture link from issue template
2018-06-05 19:37:14 -07:00
Klaudia Algiz cda6ef175c Remove not initialized variable $IsElevated from test in New-Item.Tests.ps1 (#6746)
* Remove not initialized variable  from PowerShell tests

* Separate the tests that requires no elevation from the others.
2018-06-05 10:26:04 -07:00
Steve Lee 5dc7a6cb07 Add Windows Compatibility Pack 2.0.0 to PS Core and adopt the official .NET Core 2.1 (#6958)
To support PowerShell modules built with .NET Windows Compatibility Pack, we decided that it was best to ship the WCP assemblies with PS Core. This also adds many new .NET APIs be default while only adding ~3.5 MB additional disk footprint (to a ~137 MB install currently).
Also update the build to adopt the official .NET Core 2.1.
2018-06-03 22:06:26 -07:00
Ilya 57b3d3380b
Cleanup FileSystem provider (#6909)
The cleanup is coming from a code review to cleanup psl. Here we clean up the side branch of the code that will allow later to clean up a branch which uses psl.
- IO.FileInfo does not make system calls in constructor. So we can create the object and then use the required attributes without direct call IO.FileInfo.GetAttributes() ( SafeGetFileAttributes() ). This allow us to exclude some p/invoke calls in our code in later cleanups. Also we get unified code for both Windows and Unix.
- Remove SafeGetFileAttributes() and WinSafeGetFileAttributes(). Currently .Net Core support file attributes on all platforms in fastest way and we can remove our workaround. We get a regression in rare case (for files like pagefile.sys). Fix is ready in CoreFX, we get it in 2.1.1. I suggest ignore the regression because this is a very-very rare situation (Get-ChildItem c:\pagefile.sys -Hidden). The .Net Core team was not even able to create an artificial test for such files and uses a real pagefile.sys file for the test. Also the enumeration is still working (dir c:\ -hidden).
- Re-add test which we lost in #4050. The test is pending because of the regression.
2018-06-04 10:00:56 +05:00
Ilya a5f77955e8
Fix xUnit test GetTempFileName (#6943)
Use Path.GetTempFileName() to get a temporary file.
2018-05-31 11:03:14 +05:00
Ilya c297eac50e
Cleanup NonWindowsGetDomainName() (#6948)
Add an optional extended description…
2018-05-31 10:18:33 +05:00
Klaudia Algiz facb228451 Remove ShouldBeErrorId custom function. (#6891) 2018-05-23 07:57:03 +05:00
Ilya 626a83bcd4
Fix tab completions for a hash table (#6839)
Now working:
- Get-Date | Sort-Object @{Expression=<tab>
- Get-Date | Sort-Object @{Expression=...;<tab>
2018-05-21 09:05:59 +05:00
Klaudia Algiz 2df9aac811 Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests (#6682)
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
2018-05-17 14:42:04 -07:00
Steve Lee ed282ce0ef Update PowerShell to build against netcoreapp.2.1-rc1 (#6873) 2018-05-16 23:18:53 -07:00
Matthew Bobke 4e3db1bb93 Fix 'Set-Location DriveName:' to restore current working directory in the drive (#6774) 2018-05-16 17:13:22 -07:00
Dongbo Wang aa0af5ed56
Further improve PSMethod to Delegate conversion (#6851)
Refactor code to make it easier to maintain and a little faster. Changes are as follows:

1. Support finding a matching signature with variance. But make PowerShell prefer exact match over a match with variance.
2. The metadata signatures in `PSMethod<..>` are generated based on the array of method overloads in `MethodCacheEntry.MethodInformationStructures`, in the exact same order. So in `LanguagePrimitive.ConvertViaParseMethod`, when we try to figure out if there is a match using the metadata signatures in `PSMethod<..>`, we can get the index of the matching signature, and the same index should locate the matching method in `MethodCacheEntry.MethodInformationStructures`. Therefore, we don't need to compare signatures again in the actual conversion method, and instead, we can just leverage the index we found when figuring out the conversion in `ConvertViaParseMethod`.
   - This gets rid of the reflection call `GetMethod("Invoke")` and the subsequent signature comparisons in the final conversion method.
   - Also, when comparing signatures using `PSMethod<..>` in `ConvertViaParseMethod`, we can just use the generic argument types of each `Func<..>` metadata type, instead of calling `GetMethod("Invoke")` and then `GetParameters()`. This makes the code for comparing signatures simpler (the type `SignatureComparator`).
   - Move `MatchesPSMethodProjectedType` from `PSMemberInfo.cs` to the type `SignatureComparator` in `LanguagePrimitives.cs`, as it's closely related to the signature comparison. Also, renamed it to `ProjectedTypeMatchesTargetType`.
   - These changes make PSMethod-to-Delegate conversion a little faster, but no big improvement, as the true bottleneck probably is in delegate creation(?). Actually, the performance of this conversion is not critical at all at this moment because this feature should rarely be used in any hot script path. So this exercise is mainly for fun. 
3. Remove `PSEnum<T>`. We can directly use enum types when constructing the metadata type `Func<..>`.
4. Remove the code that generates metadata signatures for generic method definitions (call `MakeGenericMethod` with fake types like `GenericType0`, `GenericType1`). This is because:
   - We don't support convert generic method to delegate today, so may be better not spending time on preparing the metadata signature types for those methods. 
   - When the day comes that we need to support it, it's better to use generic argument types directly to construct the `Func<..>` metadata types. I left comments in `GetMethodGroupType` method in `PSMemberInfo.cs` to explain why that approach is better.
2018-05-15 11:45:04 -07:00
Mark Kraus 525f5933b1 Fix Web Cmdlets for .NET Core 2.1 (#6806)
closes #6728
Breaking change approved in #6728
This PR switches the logic of when the Web Cmdlets handle redirects when the Authorization header is present. .NET Core 2.1 no longer sends the Authorization header by default (dotnet/corefx#26864). however, we introduced the ability to do so leveraging the previous default behavior through the use of the -PreserveAuthorizationOnRedirect switch.

This PR also corrects a bug introduced 6.0.0 where certain redirect types redirect from POST to GET were set which should have passed through POST to POST and some were improperly passing through POST to POST which should have been doing POST to GET. This correction is a breaking change. It was made apparent as now the redirection behavior is being managed by CoreFX which is doing the correct behavior, tests were added for both when CoreFX and the Web Cmdlets manage redirection.
2018-05-14 11:37:30 -07:00
Dongbo Wang db45785341
Fix a module-loading regression that caused an infinite loop (#6843)
This regression was introduced by #6523, in `PSModuleInfo.cs`. A circular nested module check was removed because the comment there suggested it happens only with a deprecated workflow module. This causes a `StackOverflow` exception when running into circular nested modules.

Circular nested modules could happen for a module that is not well structured. For example, the module folder `test` contains two files: `test.psd1` and `test.psm1`, and `test.psd1` has the following content:
   @{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }

The same value `test` is put in both RootModule and NestedModule, which will end up with a module whose nested module points to itself.

There are two changes in this PR:
1. Add back the check for circular nested modules in `PSModuleInfo.cs`.
2. Remove a wrong `Dbg.Assert` in `ModuleCmdletBase.cs` and two checks before it.
   - For the assertion `Dbg.Assert(newManifestInfo.SessionState == ss`, when facing the example above, the nested module will first be loaded with a different session state, and then when trying to load the root module, the same loaded nested module will be reused for it. So 'newManifestInfo.SessionState' is not `ss`. The assertion will fail in that case.
   - For the two checks before the assertion, they are not needed anymore based on the comments there.
2018-05-10 16:09:36 -07:00
Mark Kraus 0f036d9939 Enable Web Cmdlets Tests for Greater Platform Support (#6836) 2018-05-09 16:35:52 +05:00
Ilya 4737ebae20
Remove web cmdlet tests using proxy env variables (#6808) 2018-05-08 09:15:49 +05:00
Travis Plunk 8f37c920ef
Blacklist System.Windows.Forms form loaded to prevent a crash (#6822)
Blacklist `System.Windows.Forms` (`WinForms`) from being loaded to prevent a crash
2018-05-07 16:38:27 -07:00
Sergey Vasin 0b414f67a0 Change -Quiet parameter of Invoke-Pester to -Show None. (#6798) 2018-05-04 09:54:00 -07:00
Sergey Vasin 1be0594f45 Improve code coverage in Export-Csv.Tests.ps1. (#6795)
* Improve code coverage in Export-Csv.Tests.ps1.

* Change test logic.
2018-05-04 09:46:26 -07:00
Ilya c1026b3ae8 Remove 'more' function and move the $env:PAGER capability into the help function (#6059) 2018-05-04 09:25:05 -07:00
Ilya 84344cbb32 Update PowerShell to build with .NET Core SDK 2.1.300-rc1-008662 (#6718)
* Build Update
- Change `TargetFramework` to `netcoreapp2.1` and removed unnecessary `RuntimeFrameworkVersion` from `PowerShell.Common.props`
- Update dotnet SDK to 2.1.300-rc1-008662
- Update `TypeGen` target in `Build.psm1` to work with 2.1
- Rename macOS runtime to `osx-x64` as the old build logic expects 10.12 and breaks running on 10.13 system.
- Remove `PackageReference` to `System.Memory` as it's part of dotnetcore 2.1
- Update search for `crossgen` executable to find the matching version

* Test Update
- Update test tools `WebListener` to latest `asp.net core`
- Marked `AuthHeader Redirect` tests as `Pending` due to change in CoreFX
2018-05-02 16:58:39 -07:00
Dan Travison 385cc1b796 Disallow Basic Auth over HTTP on Unix (#6787)
Disallow Basic Auth over HTTP on Unix

Fix: #6779
2018-05-02 14:29:10 -07:00
Steve Lee 77d10e969e Fix Format-Table where rows were being trimmed unnecessarily if there's only one row of headers (#6772) 2018-05-02 17:59:48 +05:00
Aditya Patwardhan c51a6e38cf
Fix test and infrastructure blocking code coverage runs (#6790)
* Fix Remove-Item test to use a test directory instead of relying on pre-existing directory
* Increase timeout as we are regularly going over it.
2018-05-01 17:28:57 -07:00
Robert Holt 9ca059dcf8 Revert changes from PR #6600 which cause a regression in drive behavior (#6751)
This reverts the commit 35d8de927b, which caused a regression in drive behavior where drive paths were not restored. See issue #6749.
2018-04-30 15:25:11 -07:00
Klaudia Algiz bee98547e4 Fix Select-Object.Tests.ps1 which might fail for Unix OS. (#6747)
Fix Select-Object.Tests.ps1 which might fail for Unix OS.
In the test, the processes which name matches i* are selected and it checks if there is non zero number of these processes. The test assumes that there is always at least one process, probably `init` - idle, but on Unix idle process does not have the name and hence the test might fail
2018-04-30 13:09:16 -07:00
Robert Holt 0c3f429780 Add tests for PowerShell classes inheriting from abstract .NET classes (#6752) 2018-04-30 10:17:20 -07:00
Sergey Vasin 24069241bc Fix CimCmdlets tests. (#6755) 2018-04-28 09:48:13 +05:00
Aditya Patwardhan 2c3177a08d Add tests for PowerShell hosting API to verify MyGet packages (#6737) 2018-04-27 13:25:33 -07:00
Ilya ffa7e4bac0 Enhance and refactor Add-Type cmdlet (#6141)
- Can compile a source from strings (TypeDefinition and MemberDefinition).
- Can compile from files.
- Can compile only to a file (without loading the produced assembly).
- Do not recompile and don't reload if the sources have not changed.
- Implement `-IgnoreWarnings` to not treat warnings as errors. By default, the cmdlet considers warnings as errors.
- Add VisualBasic support.
- Add new `-CompilerOptions` parameter to allow setting Roslyn command line parameters including:
    - Parser options.
    - Compile options.
    - Emit options.

**ATTENTION:** The `CompilerOptions` can be specified along with other options like `-OutputAssembly`, `-Language` and `-IgnoreWarnings`. The explicit setting parameters will take precedence over the same settings specified in `-CompileOptions`.

See docs about the compiler options:
https://github.com/dotnet/roslyn/blob/master/docs/compilers/CSharp/CommandLine.md
https://github.com/dotnet/roslyn/blob/master/docs/compilers/Visual%20Basic/CommandLine.md

**ATTENTION:** `-OutputType` default is `Library`. If `-OutputType` is absent the `-OutputType` default overlaps a value in `CompileOptions`. In other words output type ("target" ot "t" in command line) is always ignored in `CompileOptions`. We have to use `-OutputType` to set an output type.
2018-04-25 22:40:26 -07:00
Robert Holt 63c0d8d783 Add error handling for interactive #requires (#6469) 2018-04-25 18:04:04 -07:00
Klaudia Algiz 4b149e4191 Use new Pester syntax for Pester tests in module PSDesiredStateConfiguration (#6622) 2018-04-25 17:29:40 -07:00
Matthew Bobke 35d8de927b Fix New-Item to work correctly when given path is drive root and $PWD is a sub folder of the drive root. (#6600) 2018-04-25 14:32:57 -07:00
Steve Lee a9d10dda42 Fix two tests that are failing on nightly run (#6723)
- For ConsoleHosts tests, the test is validating error condition, but did not redirect stderr to stdout so the output isn't captured and thus an empty string failing the assertion.
- For SSHConnectionInfo API tests, it's calling a constructor that got overwritten with a new parameter. Fix is to put back that public API and overload it with a new one.
2018-04-24 16:25:55 -07:00
Ilya 313a8596bb
Pretty print Export-FormatData XML output (#6691)
Pretty print Export-FormatData XML output by default.
Refactor Export-FormatData tests, remove test duplications.
2018-04-24 10:04:42 +05:00
Steve Lee 942c68e796 Add '-WorkingDirectory' parameter to pwsh (#6612)
Add `-WorkingDirectory` parameter to `pwsh` to allow starting in right working directory.
2018-04-23 14:27:47 -07:00