Commit graph

1197 commits

Author SHA1 Message Date
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
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
Ilya 2da7576736
Add tests for Format-Table -Wrap (#6670) 2018-04-23 12:45:14 +05:00
Ilya 5a326135ec
Add new reliable tests for Get-Date -UFormat (#6614) 2018-04-19 13:58:29 +05:00
Paul Higinbotham 80951777cf Port Windows PowerShell AppLocker and DeviceGuard UMCI application white listing support (#6133)
These changes port Windows PowerShell support for Applocker and DeviceGuard User Mode Code Integrity (UMCI) to PSCore6. Windows PowerShell uses public APIs to determine if a system is in locked down mode via AppLocker or DeviceGuard, and automatically runs in constrained language mode. For more information about PowerShell constrained language, see: https://blogs.msdn.microsoft.com/powershell/2017/11/02/powershell-constrained-language-mode/

This support for application whitelisting has mostly existed in PSCore6, but the primary APIs were stubbed out in CorePSStub.cs because they relied on Windows only DeviceGuard (wldp.dll) and AppLocker (Safer APIs) public APIs. These changes re-implement PowerShell lock down APIs on PSCore6 for Windows platforms only. The AppLocker and DeviceGuard public APIs are currently only implemented in Windows OSes and are not supported on Linux or MacOS platforms.

Tests have also been ported to PSCore6 and run only for Windows platforms.
2018-04-17 13:09:17 -07:00
Ilya 62bb0899ac
Reformat Format-Table tests (#6657)
* Convert identations to spaces
* Remove alias tests and extra lines
* Remane extra Describe
* Remove extra parentheses and add spaces
2018-04-17 10:06:39 +05:00
Steve Lee c2accff785 Support importing module paths that end in trailing directory separator (#6602) 2018-04-13 08:07:50 +04:00
Sergey Vasin 25dbc68b8e Fix formatting in Add-Content.Tests.ps1 file. (#6591)
* Fix formatting.
* Capitalize TestDrive and add empty strings.
2018-04-11 07:23:30 +04:00
Klaudia Algiz 3cd2308af9 Create the default PSSession configuration, not tied to a specific PowerShell version. (#6519)
Create the default PSSession configuration, not tied to a specific PowerShell version.

When Enable-PSRemoting command is run, it creates 2 sessions configurations:

first, the same as it was before with the name containing the current version expressed as: 'PowerShell.$PSVersionTable.GitCommitId'
second with the default name 'PowerShell.6' so that administrators wouldn't have to guess which specific version is installed on the target.
PR addresses the issue: #6470
2018-04-10 12:21:44 -07:00
Mark Kraus 18e6a5c654 Add Missing Start-WebListener to Web Cmdlet Tests (#6604) 2018-04-10 10:12:45 +04:00
Ilya 6bd70bc2d0
Some fixes in Get-Date -UFormat (#6542)
* Use UTC datetime in Get-Date -UFormat %s
Fix %l output from 0..11 to 1..12
Fix %V using Gregorian calendar

* Use a workaround for ISO 8601 week of year (uformat %V)
2018-04-10 08:13:19 +04:00
Sergey Vasin 3ec98bbbe8 Fix typos and formatting in Clear-Content.Tests.ps1 (#6592)
* Fix typos and formatting.
* Capitalize function parameters.
2018-04-10 07:47:39 +04:00
Sergey Vasin a3e8929d6a Fix formatting Clear-EventLog.Tests.ps1 (#6594) 2018-04-10 07:17:52 +04:00
Sergey Vasin ca5aacca16 Fix formatting in Clear-Item.Tests.ps1. (#6593) 2018-04-09 16:24:01 +04:00
Sergey Vasin 9d3c2633e7 Fix formatting in Convert-Path.Tests.ps1. (#6595) 2018-04-09 16:22:45 +04:00
Sergey Vasin 1f7b3a65d3 Fix Copy.Item.Tests.ps1 (#6596)
Fix formatting, absent parameter names and use -Throw and -ErrorID parameters with Should function.
2018-04-09 16:21:47 +04:00
Florian Feldhaus 94c8ce007d Added check for existence of Location HTTP header before using it (#6560)
The HTTP RFC (https://tools.ietf.org/html/rfc7231#section-6.4) does not require a Location header to be present for redirects, thus it is required to check if the Location header is returned before using it.
2018-04-08 16:51:17 +04:00
Sergey Vasin 4554679a08 Use -Throw and -ErrorId native Pester parameters. (#6574) 2018-04-06 16:15:37 +04:00
Dongbo Wang e0b1f1f3af
Fix line ending in 'DefaultCommands.Tests.ps1' from CRLF to LF (#6553) 2018-04-03 13:32:16 -07:00
Ilya 24cf020442 Add ported Test-Connection cmdlet (#5328)
The Test-Connection cmdlet works on Windows and Unix.

Implemented:
Ping
Continues Ping
Traceroute
Detect MTU size (seems don't work on Unix because of .Net Core issue)
Connect to TCP port
Not jet implemented:
I'm putting this off for the future.

Detect blackhole routers
PingPath
Additional considerations
As you can see in the tests .Net Core has issues in API implementation. As a result, some tests are skipped on Unix. There is also one issue on Windows. Related comments added to tests.
I'm going to open an issue(s) in CoreFX repo.

I think we should break the feedback into two parts:

scripting functionality
interactive functionality (display output)
Now I have implemented the output to the screen as the progress bar and as text (without ETS) - we have to decide what is best to use.
2018-04-03 11:59:26 -07:00
Takuya Shibata cd1d2d2063 Fix error when 'Format-Wide -AutoSize | Out-String' is called. (#6491)
* Add checking if an output width is specified.

* change _failedToReadConsoleWidth variable to _noConsole bool value. 
This variable is to cache the default console width when failed to get 'Console.WindowWidth' value.
2018-04-03 11:17:05 -07:00
Klaudia Algiz f0b6ef2eb4 Terminate the loop in PsUtils.GetMainModule() which was infinite in case there was no main module. (#6358)
* Terminate the loop in GetMainModule if main module is null.

* Run tests with FileVersionInfo also on non-windows platforms. Add test for process which main module can be null.
2018-04-03 10:58:06 -07:00
Steve Lee 5d3456d11b Fix formatting of tables where headers span multiple rows (#6504)
* In cases where the header spans multiple rows, need to correctly calculate whitespace and trim appropriately

* Use System.Span<int> and C# 7.2 language in SMA

* Added new ref assemblies to Files.wxs
refactor tests to remove similar xml content
added single column test case
2018-04-03 07:24:23 +04:00
Dongbo Wang d1cf82ec20 Clean up workflow logic in the module loading component (#6523)
Clean up workflow logic in the module loading component.
Workflow module is not supported in PSCore.
Currently, Import-Module throws a terminating error when seeing .xaml modules. After the change, Import-Module throws a non-terminating error when seeing .xaml modules.
2018-04-02 16:18:56 -07:00
Aditya Patwardhan 610ae1a63f Update 'Update-Help' to save help content in user scope by default (#6352)
Add the parameter `-Scope` to `Update-Help`, which takes `AllUsers` or `CurrentUser`. The default value is `CurrentUser`.
2018-04-02 15:32:55 -07:00
Aditya Patwardhan 260c16ff4f
Mark Save-Help PackageManagement tests as pending (#6545) 2018-04-02 14:07:02 -07:00
Kevin Marquette 986a9eeecd Remove empty Should -Be statements (#6536) 2018-04-01 15:05:45 +04:00
Kevin Marquette e3ba6bd92c Fixed scenarios where NullOrEmpty string was used instead of -BeNullOrEmpty (#6535) 2018-04-01 15:05:08 +04:00
Kevin Marquette 404e876740 Use new Pester syntax: -Parameter for Pester tests in modules: PowerShellGet, PackageManagement, PSReadLine (#6488) 2018-03-30 09:22:26 +04:00
Dongbo Wang cd075ea4b4 Make LanguagePrimitive.GetEnumerable treat 'DataTable' as Enumerable (#6511)
* Make LanguagePrimitive.GetEnumerable treat 'DataTable' as Enumerable
2018-03-29 16:22:44 -07:00
Dan Travison ec0f1116db Add PowerShell logging tests for macOS and Linux (#6025)
This PR fixes the logging issue on Linux where logging is initialized before `-settingsFile` is parsed causing custom log settings to be ignored. (see ConsoleHost.cs and ManagedEntrance.cs)

The PR also includes basic logging tests for Linux and MacOS. PSSyslog.psm1 contains the functions to retrieve selected logged items (based on PowerShell's log id and a timestamp) and Logging.Tests.ps1 contains tests for Linux and MacOS.
2018-03-29 14:46:08 -07:00
Kevin Marquette 5da5a4bf62 Use new Pester syntax: -Parameter for Pester in SDK and Provider tests (#6490) 2018-03-29 08:08:22 +04:00
Steve Lee c18b9999d6 Enable [Environment]::OSVersion to return current OS rather than compatible version (#6457)
* add application manifest dictating compatibility so that osversion shows appropriate os version on Windows
2018-03-28 13:36:16 -07:00
James Truher [MSFT] a6479f8181 Make sure that the width of the header is at least the size of the label (or propertyname) (#6487) 2018-03-28 13:34:29 -07:00
Michael Klement 87834d07b4 Fix error in windows provider when the environment has accidental duplicates that differ only by case (#6489)
Fix error in windows provider when the environment has accidental duplicates that differ only by case.

Make the provider storage for the environment on windows ignore duplicates
 and only report the effective value.
Add tests to verify existing environment get-item behavior and to ensure that Get-Item env:<var> reports the same as $env:<var>, namely the effective value.
Fixes #6305 and supersedes #6320 based on discussion in #6460.
2018-03-27 14:58:26 -07:00
Simon Wåhlin 31405f7283 Add the parameter '-Not' to 'Where-Object' (#6464) 2018-03-26 16:34:13 -07:00
Mark Kraus d20d53eaac Add -Resume Feature to Web Cmdlets (#6447)
Fixes #5964

Adds -Resume switch to Invoke-WebRequest and Invoke-RestMethod

-Resume requires -OutFile

Enables the ability to resume downloading a partially or incompletely downloaded file.

File Size is the only indicator of local and remote file parity.

If the local file is smaller than the remote file and the remote endpoint supports resume, the local file will be appended with the remaining bytes.

If the local file is larger than the remote file, the local file will be overwritten

If the remote server does not support resume, the local file will be overwritten

If the local file is the same size as the remote file, the remote endpoint will return a 416 status code. This response is special-cased as a success in this instance. The local file remains untouched and it is assumed the file was already successfully downloaded previously.

If the local file does not exist it will be created and the entire remote file will be requested.

Added tests for all code new code paths (I'm pretty sure anyway)

Added /Resume Controller to WebListener

Documented /Resume Controller

Updated .spelling to reflect terms in WebListener docs

Note: I had to change the way GetResponse() tracks the current URI as we now have 3 places where the call is taking place. I don't foresee this causing any regressions. This area needs some refactoring. especially if we want to implement a retry mechanism
2018-03-26 12:23:24 -07:00
Ilya 1b745f6a98 Add Test-Json cmdlet (NJsonSchema) (#5229)
Resolve #4220.

The cmdlet is based on NJsonSchema.
It allows to check:

JSON by only parsing
JSON against Schema
implicitly check Schema by parsing (based on previous line check)
NJsonSchema is under MIT (approved see https://github.com/PowerShell/PowerShell/pull/5229#issuecomment-342983215)
2018-03-26 11:52:48 -07:00
Christoph Bergmeister e86fea6acd Upgrade tests in test\powershell\Host folder to PesterV4 syntax (#6250) 2018-03-23 10:48:26 -07:00
Kevin Marquette acb52b3d9c Update tests in Microsoft.PowerShell.Security folder to use Pesterv4 syntax (#6256) 2018-03-23 10:41:14 -07:00
Klaudia Algiz ff2486416d Update tests in Modules/Microsoft.PowerShell.Core to use new Pester syntax. (#6349) 2018-03-23 10:36:11 -07:00
Klaudia Algiz eeb03c89e6 Update tests in Modules/Microsoft.PowerShell.Diagnostics to use new Pester syntax. (#6351) 2018-03-23 10:33:43 -07:00
Klaudia Algiz dfa11d7f5e Add '-AsArray' parameter to 'ConvertoTo-Json' command (#6438)
Add `-AsArray` parameter to `ConvertoTo-Json` command to always pack the output string in array brackets, even if the input is a single object.
2018-03-23 10:32:13 -07:00