Improve whitespace for Parser tests (#9806)

This commit is contained in:
Joel Sallow (/u/ta11ow) 2019-06-05 01:09:45 -04:00 committed by Ilya
parent b4e2423fab
commit f5e3de036e

View file

@ -1,11 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" -Tags "CI" {
BeforeAll {
$functionDefinitionFile = Join-Path -Path $TestDrive -ChildPath "functionDefinition.ps1"
$functionDefinition = @'
function testcmd-parserbvt
{
function testcmd-parserbvt {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
@ -29,8 +29,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)"
$ReturnType = "default"
}
switch ( $ReturnType )
{
switch ( $ReturnType ) {
"default" {
$result = "$Property1;$Property2;$Property3"
break
@ -90,12 +89,10 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)"
$shellfile = Join-Path -Path $TestDrive -ChildPath "testfile.cmd"
$testfolder1 = Join-Path -Path $TestDrive -ChildPath "dir1"
$testfolder2 = Join-Path -Path $testfolder1 -ChildPath "dir2"
if(-Not(Test-Path $testfolder1))
{
if (-Not(Test-Path $testfolder1)) {
New-Item $testfolder1 -Type Directory
}
if(-Not(Test-Path $testfolder2))
{
if (-Not(Test-Path $testfolder2)) {
New-Item $testfolder2 -Type Directory
}
$testdirfile1 = Join-Path -Path $testfolder2 -ChildPath "testdirfile1.txt"
@ -104,35 +101,28 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)"
"">$testdirfile2
}
AfterEach {
if(Test-Path $testfile)
{
if (Test-Path $testfile) {
Remove-Item $testfile
}
if(Test-Path $shellfile)
{
if (Test-Path $shellfile) {
Remove-Item $shellfile
}
if(Test-Path $testdirfile1)
{
if (Test-Path $testdirfile1) {
Remove-Item $testdirfile1
}
if(Test-Path $testdirfile2)
{
if (Test-Path $testdirfile2) {
Remove-Item $testdirfile2
}
if(Test-Path $testfolder2)
{
if (Test-Path $testfolder2) {
Remove-Item $testfolder2
}
if(Test-Path $testfolder1)
{
if (Test-Path $testfolder1) {
Remove-Item $testfolder1
}
}
AfterAll {
if(Test-Path $functionDefinitionFile)
{
if (Test-Path $functionDefinitionFile) {
Remove-Item $functionDefinitionFile
}
}
@ -149,7 +139,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)"
{ ExecuteCommand "| get-location" } | Should -Throw -ErrorId "ParseException"
}
It "Throws an CommandNotFoundException exception if using a label in front of an if statement is not allowed. (line 225)"{
It "Throws an CommandNotFoundException exception if using a label in front of an if statement is not allowed. (line 225)" {
$PowerShell.Streams.Error.Clear()
ExecuteCommand ":foo if ($x -eq 3) { 1 }"
$PowerShell.HadErrors | Should -BeTrue
@ -165,7 +155,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)"
}
It "Throws when you pipe into a value expression (line 238)" {
foreach($command in "1;2;3|3",'1;2;3|$(1+1)',"1;2;3|'abc'") {
foreach ($command in "1;2;3|3", '1;2;3|$(1+1)', "1;2;3|'abc'") {
{ ExecuteCommand $command } | Should -Throw -ErrorId "ParseException"
}
}
@ -279,7 +269,7 @@ foo``u{2195}abc
}
It "Test that a Unicode escape sequence can be used in a command name." {
function xyzzy`u{2195}($p) {$p}
function xyzzy`u{2195}($p) { $p }
$cmd = Get-Command xyzzy`u{2195} -ErrorAction SilentlyContinue
$cmd | Should -Not -BeNullOrEmpty
$cmd.Name | Should -BeExactly 'xyzzy↕'
@ -364,8 +354,7 @@ foo``u{2195}abc
" foreach(`$a in 1,2,3) { 1; foreach( `$b in 1,2,3 ) { 2; break; 3; }; 4; break; 5; } "
$results = "1", "2", "4"
$i = 0
for(;$i -lt $commands.Count;$i++)
{
for (; $i -lt $commands.Count; $i++) {
$result = ExecuteCommand $commands[$i]
$result | Should -Be $results
}
@ -377,8 +366,7 @@ foo``u{2195}abc
" :foo foreach(`$a in 1,2,3) { 1; :foo foreach( `$b in 1,2,3 ) { 2; break foo; 3; }; 4; break; 5; } "
$results = "1", "2", "4"
$i = 0
for(;$i -lt $commands.Count;$i++)
{
for (; $i -lt $commands.Count; $i++) {
$result = ExecuteCommand $commands[$i]
$result | Should -Be $results
}
@ -490,7 +478,7 @@ foo``u{2195}abc
It "Test that typing a number at the command line will return that number. (line 1630)" {
$result = ExecuteCommand '3'
$result | Should -Be "3"
$result.gettype() |should -Be ([int])
$result.gettype() | should -Be ([int])
}
It "This test will check that an msh script can be run without invoking. (line 1641)" {
@ -504,7 +492,7 @@ foo``u{2195}abc
$result | Should -Be "unset;unset;unset"
}
It "Test that functions are resolved before cmdlets. (line 1678)"{
It "Test that functions are resolved before cmdlets. (line 1678)" {
$result_cmdlet = $PowerShell.AddScript('function test-parserfunc { [CmdletBinding()] Param() PROCESS { "cmdlet" } };test-parserfunc').Invoke()
$result_func = ExecuteCommand 'function test-parserfunc { "func" };test-parserfunc'
$PowerShell.Commands.Clear()
@ -633,12 +621,12 @@ foo``u{2195}abc
{ ExecuteCommand "trap [InvalidCastException] { continue; }; [int] 'abc'" } | Should -Not -Throw
}
It "Test that assign to input var and use then execute a script block with piped input. (line 2297)"{
It "Test that assign to input var and use then execute a script block with piped input. (line 2297)" {
$result = ExecuteCommand '$input = 1,2,3;4,-5,6 | & { $input }'
$result -join "" | Should -Be (4,-5,6 -join "")
$result -join "" | Should -Be (4, -5, 6 -join "")
}
It "Test that pipe objects into a script and use arguments. (line 2313)"{
It "Test that pipe objects into a script and use arguments. (line 2313)" {
"`$input; `$args;">$testfile
$result = ExecuteCommand "1,2,3 | $testfile"
$result -join "" | Should -Be (1, 2, 3 -join "")
@ -985,49 +973,49 @@ foo``u{2195}abc
It "<Script> should throw an error" -TestCases $testInvalidNumerals {
param($Script, $ErrorID)
{[ScriptBlock]::Create($Script).Invoke()} | Should -Throw -ErrorId $ErrorID
{ [ScriptBlock]::Create($Script).Invoke() } | Should -Throw -ErrorId $ErrorID
}
}
It "This is a simple test of the concatenation of two arrays. (line 2460)"{
It "This is a simple test of the concatenation of two arrays. (line 2460)" {
$result = ExecuteCommand '1,2,3 + 4,5,6'
$result -join "" | Should -Be (1, 2, 3, 4, 5, 6 -join "")
}
It "Test that an incomplete parse exception is thrown if the array is unfinished. (line 2473)"{
It "Test that an incomplete parse exception is thrown if the array is unfinished. (line 2473)" {
{ ExecuteCommand '1,2,' } | Should -Throw -ErrorId "IncompleteParseException"
}
It "Test that the unary comma is not valid in cmdlet parameters. (line 2482)"{
It "Test that the unary comma is not valid in cmdlet parameters. (line 2482)" {
{ ExecuteCommand 'write-output 2,,1' } | Should -Throw -ErrorId "ParseException"
}
It 'Test that "$var:" will expand to nothing inside a string. (line 2551)'{
It 'Test that "$var:" will expand to nothing inside a string. (line 2551)' {
{ ExecuteCommand '"$var:"' } | Should -Throw -ErrorId "ParseException"
}
It "Tests the assignment to a read-only property (line 2593)"{
It "Tests the assignment to a read-only property (line 2593)" {
$result = ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A.rank =5;$A.rank'
$result | Should -Be "1"
}
It 'Tests accessing using null as index. (line 2648)'{
It 'Tests accessing using null as index. (line 2648)' {
$PowerShell.Streams.Error.Clear()
ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[$NONEXISTING_VARIABLE];'
$PowerShell.HadErrors | Should -BeTrue
$PowerShell.Streams.Error.FullyQualifiedErrorId | Should -Be "NullArrayIndex"
}
It 'Tests the parser response to ArrayName[. (line 2678)'{
It 'Tests the parser response to ArrayName[. (line 2678)' {
{ ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[ ;' } | Should -Throw -ErrorId "ParseException"
}
It 'Tests the parser response to ArrayName[]. (line 2687)'{
It 'Tests the parser response to ArrayName[]. (line 2687)' {
{ ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[] ;' } | Should -Throw -ErrorId "ParseException"
}
#Issue#1430
It "Tests function scopes in a script. (line 2800)" -Pending{
It "Tests function scopes in a script. (line 2800)" -Pending {
" function global:func { 'global' }; " +
" function func { 'default' }; " +
" local:func; " +
@ -1039,7 +1027,7 @@ foo``u{2195}abc
$result | Should -Be "global"
}
It 'Test piping arguments to a script block. The objects should be accessible from "$input". (line 2870)'{
It 'Test piping arguments to a script block. The objects should be accessible from "$input". (line 2870)' {
ExecuteCommand '$script = { $input; };$results = @(0,0),-1 | &$script'
$result = ExecuteCommand '$results[0][0]'
$result | Should -Be "0"
@ -1049,29 +1037,38 @@ foo``u{2195}abc
$result | Should -Be "-1"
}
It 'Test piping null into a scriptblock. The script block should not be passed anything. (line 2903)'{
It 'Test piping null into a scriptblock. The script block should not be passed anything. (line 2903)' {
$result = ExecuteCommand '$() | &{ $count = 0; foreach ($i in $input) { $count++ }; $count }'
$result | Should -Be "1"
$result = ExecuteCommand '$() | &{ $input }'
$result | Should -BeNullOrEmpty
}
It 'Test that types in System.dll are found automatically. (line 2951)'{
It 'Test that types in System.dll are found automatically. (line 2951)' {
$result = ExecuteCommand '[ System.IO.FileInfo]'
$result | Should -Be "System.IO.FileInfo"
}
Context "Mathematical Operations Tests (starting at line 2975 to line 3036)" {
$testData = @(
@{ Script = '$a=6; $a -= 2;$a'; Expected = 4 }
@{ Script = "20 %
6"; Expected = "2" }
@{ Script = "(20 %
@{
Script = '$a=6; $a -= 2;$a'
Expected = 4
}
@{
Script = "20 %
6"
Expected = "2"
}
@{
Script = "(20 %
6 *
4 +
2 ) /
2 -
3"; Expected = "2" }
3"
Expected = "2"
}
)
It "<Script> should return <Expected>" -TestCases $testData {
param ( $Script, $Expected )
@ -1079,7 +1076,7 @@ foo``u{2195}abc
}
}
It 'This test will call a cmdlet that returns an array and assigns it to a variable. Then it will concatenate this array with itself and check that what results is an array of double the size of the original. (line 3148)'{
It 'This test will call a cmdlet that returns an array and assigns it to a variable. Then it will concatenate this array with itself and check that what results is an array of double the size of the original. (line 3148)' {
$result = ExecuteCommand '$list=$(testcmd-parserBVT -ReturnType "array"); $list = $list + $list;$list.length'
$result | Should -Be 6
}
@ -1129,7 +1126,7 @@ foo``u{2195}abc
@{ script = "#requires"; firstToken = $null; lastToken = $null },
@{ script = "#requires -Version 5.0`n10"; firstToken = "10"; lastToken = "10" },
@{ script = "Write-Host 'Hello'`n#requires -Version 5.0`n7"; firstToken = "Write-Host"; lastToken = "7" },
@{ script = "Write-Host 'Hello'`n#requires -Version 5.0"; firstToken = "Write-Host"; lastToken = "Hello"}
@{ script = "Write-Host 'Hello'`n#requires -Version 5.0"; firstToken = "Write-Host"; lastToken = "Hello" }
)
It "Correctly resets the first and last tokens in the tokenizer after nested scan in script" -TestCases $testCases {