Files
PowerShell-PowerShell/test/powershell/Language/Scripting/Requires.Tests.ps1
T
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

40 lines
1.7 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Requires tests" -Tags "CI" {
Context "Parser error" {
$testcases = @(
@{command = "#requiresappID`r`n$foo = 1; $foo" ; testname = "appId with newline"}
@{command = "#requires -version A `r`n$foo = 1; $foo" ; testname = "version as character"}
@{command = "#requires -version 2b `r`n$foo = 1; $foo" ; testname = "alphanumeric version"}
@{command = "#requires -version 1. `r`n$foo = 1; $foo" ; testname = "version with dot"}
@{command = "#requires -version '' `r`n$foo = 1; $foo" ; testname = "empty version"}
@{command = "#requires -version 1.0. `r`n$foo = 1; $foo" ; testname = "version with two dots"}
@{command = "#requires -version 1.A `r`n$foo = 1; $foo" ; testname = "alphanumeric version with dots"}
)
It "throws ParserException - <testname>" -TestCases $testcases {
param($command)
{ [scriptblock]::Create($command) } | Should -Throw -ErrorId "ParseException"
}
}
Context "Interactive requires" {
BeforeAll {
$ps = [powershell]::Create()
}
AfterAll {
$ps.Dispose()
}
It "Successfully does nothing when given '#requires' interactively" {
$settings = [System.Management.Automation.PSInvocationSettings]::new()
$settings.AddToHistory = $true
{ $ps.AddScript("#requires").Invoke(@(), $settings) } | Should -Not -Throw
}
}
}