Commit graph

77 commits

Author SHA1 Message Date
Dongbo Wang ad231a8a7f
Make minor fixes in Compiler to properly handle void type expression (#5764) 2018-01-02 09:25:29 -08:00
James Truher [MSFT] fe3e44f305 Change $OutputEncoding to be utf8 without BOM rather than ASCII (#5369) 2017-11-07 14:49:14 -08:00
Jason Shirk 8391b9e155 Rework passing array literal to native commands (#5301) 2017-11-06 17:05:26 -08:00
Jason Shirk 6cbcf5dd3e Glob native command args only when not quoted
Also fix some minor issues with exceptions being raised when resolving
the path - falling back to no glob.

Fix: #3931 #4971
2017-10-31 23:34:50 -07:00
Steve Lee a384c6ea11 Change to not insert line breaks to output (except for tables) (#5193) 2017-10-30 09:54:44 -07:00
Steve Lee 4bc52d2358 Use consistent '(c)' for copyright symbol (#5210)
- Remove the year about copyright
- Fix casing of `All rights reserved`
- Replace Unicode characters representing single quote with a single quote
2017-10-26 14:12:19 -07:00
Steve Lee b1af9ea230 -Verbose should not override $ErrorActionPreference (#5113)
* -Verbose should not override $ErrorActionPreference

* apply same fix to -debug and added test case

* address Aditya's feedback
2017-10-26 13:40:14 -07:00
Steve Lee d85b9a472c Put command discovery before scripts for Unix (#5116)
* put command discovery before scripts for Unix

* remove unnecessary test
2017-10-23 17:54:28 -07:00
Steve Lee 2cc091115b Rename powershell.exe to pwsh.exe (#5101)
- Rename powershell.exe to pwsh.exe
- Fixe appveyor.psm1
- Update MSI to include 'pwsh' in path and app paths
- Revert change for hyper-v powershell direct
- Update names in packaging.psm1.
- Fix check for SxS
2017-10-17 17:25:11 -07:00
Steve Lee 59311d03e1 Properly escape trailing backslash so that it doesn't end up escaping the quotes (#4965)
The native command receives the arg ".\test 1" as  .\test 1"  as the last  \"  is treated as escaping the quotes. Fix is to add an extra backslash to escape the last enclosing quote.
2017-10-11 18:01:09 +04:00
Steve Lee 2639cd89ce Autocorrected CRLF to LF (#4943)
Also, fix `Parser.Tests.ps1` after correcting CRLF.
2017-09-29 16:28:15 -07:00
Dongbo Wang c06ffc4a5c Add a generic file watcher function in HelpersCommon.psm1 (#4775)
Add a generic file watcher function in HelpersCommon.psm1 and update some tests to use the `Wait-FileToBePresent`.
2017-09-12 13:05:47 -07:00
Steve Lee 7c9b188c13 Rename $IsOSX to $IsMacOS (#4757) 2017-09-07 10:34:40 -07:00
Steve Lee fb286e6cf8 Removed double spaces from .cs and .ps1 files (#4743) 2017-09-04 19:45:51 -07:00
Dongbo Wang 384a9fe3fc Clean up ShellExecute code to use the .NET Core implementation (#4523)
* Clean up ShellExecuteHelper and enable ShellExecute in NativeCommandProcessor

* Minor fix

* [Feature] Fix NativeCommandProcessor to clean up in case an exception is thron

* [Feature] Update tests

* [Feature] Address comments

* address one more comment

* Address some more comments
2017-08-10 13:32:57 -07:00
Dongbo Wang 0d8eff6446 Fix array expression to not return null or throw error (#4296)
This change fixes 3 issues:
- According to [PowerShell Language Specification Version 3.0](https://www.microsoft.com/en-us/download/details.aspx?id=36389), as quoted: "_The result is the (possibly empty) unconstrained 1-dimensional array_", `@(...)` should only return `object[]` array.
- `@([object[]]$null).GetType()` fails with error `"You cannot call a method on a null-valued expression."`
- `@([System.Collections.Generic.List[object]]$null)` fails with error `"Object reference not set to an instance of an object."`
2017-07-24 21:52:30 -07:00
bergmeister ffd39b2853 PSScriptAnalyzer fixes by category (#4261)
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'ForEach-Object' (alias is '%' or 'foreach')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Where-Object' (alias is '?' or 'where')
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Select-Object' (alias is 'select')
- Fix PSScriptAnalyzer warnings of type PSPossibleIncorrectComparisonWithNull. Essentially, $null has to be on the left-hand side when using it for comparison.
- A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison
- Replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '$object | Should Be $null'
2017-07-21 21:03:49 -07:00
Dongbo Wang 3e35fb9918 Move powershell to 2.0.0-preview3-25426-01 using the .NET CLI 2.0.0-preview2-006502 (#4144) 2017-06-30 13:07:14 -07:00
Dongbo Wang b4973fc920 Move PowerShell back to .NET Core 2.0.0-preview1-002106-00 (#4026) 2017-06-15 16:29:25 -07:00
Dongbo Wang 440590ef8a Add a test for chaining more than 2 native commands in pipeline (#4012) 2017-06-14 16:50:18 -07:00
Steve Lee ea0082ab8d Consolidated the two test exes into one (#3982)
Combined the previous echoargs and createchildprocess test exes into a single TestExe that can be extended for other tests.
2017-06-13 17:49:56 -07:00
Aditya Patwardhan f20178275a Removed 'Import-Module $helperModule' as it is not needed. (#3814) 2017-05-19 10:42:20 -07:00
Ilya e00161a8af Add autoload for TestLanguage.psm1 TestHelpers.psm1 (#3456)
* Add autoload for TestHelpers.psm1

Test.Helpers.psm1 was renamed to TestHelpers.psm1

* Resolve conflit and rebase Add autoload for TestLanguage.psm1

* Remove unneeded comments from PSD1 files

* Rename test modules

Remove approved verbs (Get-Verb) from module names.

* Enhance ShouldBeErrorId to output exception into pipeline for later analysis

* Remove unneeded comments

* Resolve merge conflict
2017-05-17 11:09:27 -07:00
James Truher [MSFT] 563806c15d Change native execution tests to use df instead of stty (#3685)
when automating test execution, some environments don't have a tty which causes
the tests to fail. df is just as good a test as stty as it is also guaranteed to be
present. This change also allows the tests to be run on OSX
2017-05-02 18:45:35 -07:00
Bruce Payette 11ad02a15a Adding support for native command globbing on UNIX (#3643)
This change enables globbing (wildcard expansion) against the file system for native commands like '/bin/ls'. The expansion is only done in the file system. In non-filesystem drives expansion is not done and the pattern is returned unchanged.

Limitations of the fix:
Currently quoting is not honored so for a command like /bin/ls "*.txt", wildcard expansion will still be done. Adding support for bare word detection will come in a future PR. Use --% to suppress wildcard expansion e.g. git add --% *
2017-05-01 12:23:36 -07:00
Staffan Gustafsson fa901b646f Add ErrorMessage property to ValidatePattern, ValidateSet and ValidateScript attributes (#2728)
This makes it possibe to write for example
[ValidatePattern('[A-Z]:',  ErrorMessage='The Drive should be specified as a single letter followed by a colon, for example "D:"')]
[string] $Drive,

The element being validated is also passed, so {0} can be used in the custom error message
2017-04-20 11:31:57 -07:00
Dongbo Wang 7a55bf98b2 Move powershell to .NET Core 2.0 (#3556)
This change moves powershell to .NET Core 2.0. Major changes are:
1. PowerShell assemblies are now targeting `netcoreapp2.0`. We are using `microsoft.netcore.app-2.0.0-preview1-001913-00`, which is from dotnet-core build 4/4/17. We cannot target `netstandard2.0` because the packages `System.Reflection.Emit` and `System.Reflection.Emit.Lightweight`, which are needed for powershell class, cannot be referenced when targeting `netstandard2.0`.
2. Refactor code to remove most CLR stub types and extension types.
3. Update build scripts to enable CI builds. The `-cache` section is specified to depend on `appveyor.yml`, so the cache will be invalidated if `appveyor.yml` is changed.
4. Ship `netcoreapp` reference assemblies with powershell to fix the issues in `Add-Type` (#2764). By default `Add-Type` will reference all those reference assemblies when compiling C# code. If `-ReferenceAssembly` is specified, then we search reference assemblies first, then the framework runtime assemblies, and lastly the loaded assemblies (possibly a third-party one that was already loaded).
5. `dotnet publish` generates executable on Unix platforms, but doesn't set "x" permission and thus it cannot execute. Currently, the "x" permission is set in the build script, `dotnet/cli` issue [#6286](https://github.com/dotnet/cli/issues/6286) is tracking this.
6. Replace the use of some APIs with the ones that take `SecureString`.
7. osx.10.12 is required to update to `netcoreapp2.0` because `dotnet-cli` 2.0.0-preview only works on osx.10.12.
8. Add dependency to `System.ValueTuple` to work around a ambiguous type identity issue in coreclr. The issue is tracked by `dotnet/corefx` [#17797](https://github.com/dotnet/corefx/issues/17797). When moving to newer version of `netcoreapp2.0`, we need to verify if this dependency is still needed.
2017-04-17 11:52:38 -07:00
Ilya a99fb531e6 Add autoload for test modules (#3342)
Related #3238

1. Add autoload for test modules
2. Move TestHostCS.psm1 to 'test\tools\Modules\' folder
3. Remove explicit load TestHostCS.psm1 from test files
2017-03-26 21:46:39 -07:00
Steve Lee 76de340e79 corrected use of PSModulePath casing to be consistent with Windows PowerShell (#3255)
* corrected use of PSModulePath casing to be consistent with Windows PowerShell
addresses #3227

* addressing review feedback
make "PSModulePath" into const
fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in

* addressing review feedback
make "PSModulePath" into const
fixed some test workarounds due to failures for external reasons that wasn't meant to be checked in
2017-03-15 12:04:28 -07:00
Ilya 409ab7443f Fix GetType() bad pattern and related issues in tests (#3134)
* Fix GetType() bad pattern and related issues in tests

$var.GetType() can raise an exception in tests so we should check $var
before make the call. A large part of the tests does not make this
check.
I start with searching ".GetType()" but discovered many related issues
in tests (reduntant and unneeded tests, "throw" bad pattens, bugs,
formattings (sorry!) and so on) - I had to fix them too.

* Fix after code review
* Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
2017-02-15 16:40:51 -08:00
Ilya fd70adbc90 Improve console cmdlets tests (#3101)
* Improve console cmdlets tests
Main improvements refer to tests of the Write-Host cmdlet.
Original tests:
1. Slow because run external processes
2. Don't test colors and -NoNewLine in fact.

1. The original tests is preserved (deleted one as redundant) but marked
by 'Slow' tag. They is preserved because they actually check the output
on the work, not a test console.
2. Add negative color tests. (Code cover grow!)
3. Add tests based on TestHostCS. This test host has been refined so we
can see colors and a new line in output.
4. Add minor fixes for test modules loads.

Also I add support for Information stream. I originally planned to use
it but not actually used. However, I have left this as a useful addition
for future tests.
I wonder that a Write-Host console output is duplicated in Information
Stream - Is it by design? I left a debug print on this matter in the
test code.

* Fix after code review
* Corrections after code review
Suppress import-module warnings
Rename Describes
Add "-Object" test
Add Stream.Information tests with TestHostCS
* Add checks for Streams.Information and add comments
2017-02-14 11:00:03 -08:00
Jason Shirk 02b5f357a2 Remove trailing whitespace (#3001) 2017-01-16 13:31:14 -08:00
Sergei Vorobev f4f576c92b Rename Wait-CompleteExecution to Wait-UntilTrue 2017-01-12 14:25:07 -08:00
Sergei Vorobev 684a25b9ea Fix Wait-CompleteExecution usage 2017-01-12 14:25:07 -08:00
Sergei Vorobev fab25c5d50 Remove -Force from Import-Module in tests 2017-01-12 14:25:07 -08:00
Sergei Vorobev ab06adf774 Another attempt to make native timer test less flaky 2017-01-12 14:25:07 -08:00
James Truher [MSFT] c97ca777df Jameswtruher/travisdailybuild (#2958)
* Stifle progress output in build.psm1 for some operations

Modify test failure presentation to use platform available XML methods

* Add timeout support for returning runtime parsing errors

Some of the language/parser tests have been hanging in a non-reproducable manner which
causes the CI system to invalidate the entire run. This change adds support for timeout
which will fail a test if it runs to long, rather than invalidate the entire run.

current behavior is still supported, and is not done in a new session:
PS> get-runtimeerror -src '1/'
At line:1 char:3
+ 1/
+   ~
You must provide a value expression following the '/' operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

Adding a timeout will do the operation in a async powershell session
PS> get-runtimeerror -src '1/' -timeout 5
You must provide a value expression following the '/' operator.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

If the operation takes longer than the supplied timeout, a timeout error will be returned
PS> get-runtimeerror -src 'start-sleep 6' -timeout 2
get-runtimeerror : Operation Timed Out ('start-sleep 6')
At line:1 char:1
+ get-runtimeerror -src 'start-sleep 6' -timeout 2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RuntimeError

* Modify native linux command tests to skip on Windows and pending on Mac

* remove verbose and progress output from help tests

* Be sure that Feature Counter tests only run on Windows

Also, only call add-type in CounterTestHelperFunctions.ps1 if we're going to actually run the tests

* do not run any get-computerinfo tests on non-windows systems

* suppress progress output from PowerShell Get tests

* remove -quiet from API and CRON Builds

Travis watches output from the build to ensure that it hasn't hung
we need to find a balance between too much output and not enough output.
A run which has too much output is killed because it looks like an error loop
A run which has too little output is killed because it looks like a hang

* Remove commented line in Import-Counter.Tests.ps1

Remove extraneous extra line in PowerShellGet.Tests.ps1

* Change `-as "type"` to `-as [type]` in build.psm1

Alter timeout to 10 seconds to be improve chances of not timing out for runtime parser checks
improve logic for counter tests to also skip for IoT

* use the existing function of SkipCounterTests rather than duplicate the logic in import-counter.tests.ps1
2017-01-10 14:42:27 -08:00
Charu Bassi 821c965aee Fix type completion w/ type aliases (accelerators) (#2533)
Type completion would behave strangely when there were multiple aliases for a given type (currently only possible with type accelerators).

The fix is to only select the accelerator that matches what the user typed.

Closes #2295
2016-12-21 15:33:05 -08:00
Dongbo Wang bbf1766ac7 Fix try/catch to choose the more specific exception handler (#2429)
* Refactor 'FindMatchingHandler' to get rid of recursion
Search state can be saved and used throughout the searching process without the recursion.

* Rank the exception types based on how specific they are

* Refactor code to find handler based on the rank of given handlers
2016-12-09 12:37:08 -08:00
Aditya Patwardhan 9a195f44c1 Marked flaky test as pending to unblock daily builds (#2838) 2016-12-04 00:12:51 -08:00
Dongbo Wang 20a0ba041c Fix the indicator for redirecting standard input (#2749) 2016-11-21 16:02:52 -08:00
Sergei Vorobev 32837f06ee Trying to make 'native command lifecycle' test unflaky
Also move it to the Feature category
2016-11-15 14:49:39 -08:00
Sergei Vorobev 616c15556f Re-shuffle minishell tests 2016-11-15 14:49:39 -08:00
Sergei Vorobev f0a4a7d821 Replace spin-lock by a proper BlockingCollection in NativeCommandProcessor 2016-11-15 14:49:39 -08:00
Sergei Vorobev a6fc5387c2 Add a code to handle finished process correctly on Unix 2016-11-15 14:49:39 -08:00
Sergei Vorobev 9658e62682 Add a test for broken linux pipe in native pipeline 2016-11-15 14:49:39 -08:00
Sergei Vorobev 584aec7c92 Add motivation example for the native pipeline changes 2016-11-15 14:49:39 -08:00
Sergei Vorobev 6acc1e0629 Add error stream and information stream tests
for native pipes
2016-11-15 14:49:39 -08:00
Sergei Vorobev a05fffd9dc Add a minishell clixml tests 2016-11-15 14:49:39 -08:00
Jason Shirk c8c55b7ce7 Fix NullReferenceException in binder (#2591)
There was a NullReferenceException after turning on constrained language mode
if creating a binding on a thread with no runspace.

The fix is to assume if there is no runspace that we are not in constrained language
mode, and also generate a binding restriction that assumes the same.
2016-11-03 14:15:58 -07:00