From b22369e2becb2d7684aba1c342341838dbdcdcef Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 9 Feb 2017 05:42:44 +0400 Subject: [PATCH] Make small optimization in parser tests (#3072) * Make small optimization in parser tests * Add Clear() for common command Remove commands from AfterEach * Refactoring test 'functions are resolved before cmdlets' --- test/powershell/Language/Parser/Parser.Tests.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/powershell/Language/Parser/Parser.Tests.ps1 b/test/powershell/Language/Parser/Parser.Tests.ps1 index 97c097380a..1a9f3938ca 100644 --- a/test/powershell/Language/Parser/Parser.Tests.ps1 +++ b/test/powershell/Language/Parser/Parser.Tests.ps1 @@ -71,10 +71,11 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" $functionDefinition>$functionDefinitionFile $PowerShell = [powershell]::Create() + $PowerShell.AddScript(". $functionDefinitionFile").Invoke() + $PowerShell.Commands.Clear() function ExecuteCommand { param ([string]$command) try { - $PowerShell.AddScript(". $functionDefinitionFile").Invoke() $PowerShell.AddScript($command).Invoke() } finally { @@ -101,8 +102,6 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" "">$testdirfile2 } AfterEach { - $PowerShell.Commands.Clear() - $PowerShell.Streams.Error.Clear() if(Test-Path $testfile) { Remove-Item $testfile @@ -167,6 +166,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" } 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 be $true $PowerShell.Streams.Error.FullyQualifiedErrorId | should be "CommandNotFoundException" @@ -517,8 +517,11 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" } It "Test that functions are resolved before cmdlets. (line 1678)"{ - $result = ExecuteCommand 'function testcmd-parserBVT { 3 };testcmd-parserBVT' - $result | should be "3" + $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() + $result_cmdlet | should be "cmdlet" + $result_func | should be "func" } It "Check that a command that uses shell execute can be run from the command line and that no exception is thrown. (line 1702)" { @@ -738,6 +741,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" } 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 be $true $PowerShell.Streams.Error.FullyQualifiedErrorId | should be "NullArrayIndex"