Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Utility/PowerShellData.tests.ps1
T
Steve Lee c1c5344a88 Update copyright and license headers (#6134)
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files.

Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks.

Separate PR coming to update contribution document for new source files: #6140

Manually reviewed each change.

Fix #6073
2018-02-13 09:23:53 -08:00

69 lines
2.1 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Tests for the Import-PowerShellDataFile cmdlet" -Tags "CI" {
It "Validates error on a missing path" {
try
{
Import-PowerShellDataFile -Path /SomeMissingDirectory -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Validates error on a directory" {
try
{
Import-PowerShellDataFile ${TESTDRIVE} -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "PathNotFound,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Generates a good error on an insecure file" {
$path = Setup -f insecure.psd1 -content '@{ Foo = Get-Process }' -pass
try
{
Import-PowerShellDataFile $path -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Generates a good error on a file that isn't a PowerShell Data File (missing the hashtable root)" {
$path = setup -f NotAPSDataFile -content '"Hello World"' -Pass
try
{
Import-PowerShellDataFile $path -ErrorAction Stop
Throw "Command did not throw exception"
}
catch
{
$_.FullyQualifiedErrorId | Should be "CouldNotParseAsPowerShellDataFileNoHashtableRoot,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand"
}
}
It "Can parse a PowerShell Data File (detailed tests are in AST.SafeGetValue tests)" {
$path = Setup -F gooddatafile -content '@{ "Hello" = "World" }' -pass
$result = Import-PowerShellDataFile $path -ErrorAction Stop
$result.Hello | Should be "World"
}
}