forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml.tests.ps1
More file actions
68 lines (57 loc) · 3.05 KB
/
Copy pathxml.tests.ps1
File metadata and controls
68 lines (57 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Describe "XML cmdlets" -Tags "Feature" {
Context "Select-XML" {
BeforeAll {
$fileName = New-Item -Path 'TestDrive:\testSelectXml.xml'
Push-Location "$fileName\.."
"<Root>" | out-file -LiteralPath $fileName
" <Node Attribute='blah' />" | out-file -LiteralPath $fileName -Append
"</Root>" | out-file -LiteralPath $fileName -Append
$fileNameWithDots = $fileName.FullName.Replace("\", "\.\")
$driveLetter = [string]($fileName.FullName)[0]
$fileNameAsNetworkPath = "\\localhost\$driveLetter`$" + $fileName.FullName.SubString(2)
class TestData
{
[string] $testName
[hashtable] $parameters
TestData($name, $parameters)
{
$this.testName = $name
$this.parameters = $parameters
}
}
$testcases = @()
$testcases += [TestData]::new('literalpath with relative paths', @{LiteralPath = $fileName.Name; XPath = 'Root'})
$testcases += [TestData]::new('literalpath with absolute paths', @{LiteralPath = $fileName.FullName; XPath = 'Root'})
$testcases += [TestData]::new('literalpath with path with dots', @{LiteralPath = $fileNameWithDots; XPath = 'Root'})
if ( ! $IsCoreCLR ) {
$testcases += [TestData]::new('literalpath with network path', @{LiteralPath = $fileNameAsNetworkPath; XPath = 'Root'})
}
$testcases += [TestData]::new('path with relative paths', @{Path = $fileName.Name; XPath = 'Root'})
$testcases += [TestData]::new('path with absolute paths', @{Path = $fileName.FullName; XPath = 'Root'})
$testcases += [TestData]::new('path with path with dots', @{Path = $fileNameWithDots; XPath = 'Root'})
if ( ! $IsCoreCLR ) {
$testcases += [TestData]::new('path with network path', @{Path = $fileNameAsNetworkPath; XPath = 'Root'})
}
}
AfterAll {
Remove-Item -LiteralPath $fileName -Force -ErrorAction SilentlyContinue
Pop-Location
}
$testcases | % {
$params = $_.parameters
It $_.testName {
@(Select-XML @params).Count | Should Be 1
}
}
It "literalpath with non filesystem path" {
$__data = "abcdefg"
Select-XML -literalPath variable:__data "Root" -ErrorVariable selectXmlError -ErrorAction SilentlyContinue
$selectXmlError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'
}
It "path with non filesystem path" {
$__data = "abcdefg"
Select-XML -Path variable:\__data "Root" -ErrorVariable selectXmlError -ErrorAction SilentlyContinue
$selectXmlError.FullyQualifiedErrorId | Should Be 'ProcessingFile,Microsoft.PowerShell.Commands.SelectXmlCommand'
}
}
}