Skip to content

Commit 244a7cb

Browse files
committed
Fix tests for cross-platform builds
1 parent a825a55 commit 244a7cb

6 files changed

+482
-483
lines changed

Specs/Configuration.Steps.ps1

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
$PSModuleAutoLoadingPreference = "None"
22

33
BeforeEachFeature {
4-
Remove-Module Configuration -ErrorAction Ignore -Force
5-
Import-Module Configuration -MinimumVersion 1.1
4+
Remove-Module "Configuration" -ErrorAction Ignore -Force
5+
Import-Module "Configuration" -MinimumVersion 1.1
66
}
77
AfterEachFeature {
8-
Remove-Module Configuration -ErrorAction Ignore -Force
9-
Import-Module Configuration -MinimumVersion 1.1
8+
Remove-Module "Configuration" -ErrorAction Ignore -Force
9+
Import-Module "Configuration" -MinimumVersion 1.1
1010
}
1111

1212
Given 'the configuration module is imported with testing paths:' {
1313
param($Table)
14-
$ModuleBase = (Get-Module Configuration -ListAvailable | Sort-Object Version -Descending)[0].ModuleBase
15-
Remove-Module Configuration -ErrorAction Ignore -Force
16-
Import-Module $ModuleBase\Configuration.psd1 -Args @($null, $Table.Enterprise, $Table.User, $Table.Machine) -Scope Global
14+
$ModuleBase = (Get-Module "Configuration" -ListAvailable | Sort-Object Version -Descending)[0].ModuleBase
15+
Remove-Module "Configuration" -ErrorAction Ignore -Force
16+
Import-Module $ModuleBase/Configuration.psd1 -Args @($null, $Table.Enterprise, $Table.User, $Table.Machine) -Scope Global
1717
}
1818

1919
Given 'the configuration module is imported with a URL converter' {
2020
param($Table)
2121
$ModuleBase = "."
22-
$ModuleBase = (Get-Module Configuration).ModuleBase
23-
Remove-Module Configuration -ErrorAction Ignore -Force
24-
Import-Module $ModuleBase\Configuration.psd1 -Args @{
22+
$ModuleBase = (Get-Module "Configuration").ModuleBase
23+
Remove-Module "Configuration" -ErrorAction Ignore -Force
24+
Import-Module $ModuleBase/Configuration.psd1 -Args @{
2525
[Uri] = { "Uri '$_' " }
2626
"Uri" = {
2727
param([string]$Value)
@@ -32,15 +32,15 @@ Given 'the configuration module is imported with a URL converter' {
3232

3333
Given 'the manifest module is imported' {
3434
param($Table)
35-
$ModuleBase = (Get-Module Configuration).ModuleBase
36-
Remove-Module Configuration, Manifest
37-
Import-Module $ModuleBase\Manifest.psm1 -Scope Global
35+
$ModuleBase = (Get-Module "Configuration").ModuleBase
36+
Remove-Module "Configuration", Manifest
37+
Import-Module $ModuleBase/Manifest.psm1 -Scope Global
3838
}
3939

4040
Given "a module with(?:\s+\w+ name '(?<name>.+?)'|\s+\w+ the company '(?<company>.+?)'|\s+\w+ the author '(?<author>.+?)')+" {
4141
param($name, $Company = "", $Author = "")
4242

43-
$ModulePath = "TestDrive:\Modules\$name"
43+
$ModulePath = "TestDrive:/Modules/$name"
4444
Remove-Module $name -ErrorAction Ignore
4545
Remove-Item $ModulePath -Recurse -ErrorAction Ignore
4646

@@ -51,27 +51,27 @@ Given "a module with(?:\s+\w+ name '(?<name>.+?)'|\s+\w+ the company '(?<company
5151
if(!(Test-Path $ModulePath -PathType Container)) {
5252
$null = New-Item $ModulePath -Type Directory -Force
5353
}
54-
$Env:PSModulePath = $Env:PSModulePath + ";TestDrive:\Modules" -replace "(;TestDrive:\\Modules)+?$", ";TestDrive:\Modules"
54+
$Env:PSModulePath = $Env:PSModulePath + ";TestDrive:/Modules" -replace "(;TestDrive:/Modules)+?$", ";TestDrive:/Modules"
5555

56-
Set-Content $ModulePath\${Name}.psm1 "
56+
Set-Content $ModulePath/${Name}.psm1 "
5757
function GetStoragePath { Get-StoragePath @Args }
5858
function ImportConfiguration { Import-Configuration }
5959
function ImportConfigVersion { Import-Configuration -Version 2.0 }
6060
filter ExportConfiguration { `$_ | Export-Configuration }
6161
filter ExportConfigVersion { `$_ | Export-Configuration -Version 2.0 }
6262
"
6363

64-
New-ModuleManifest $ModulePath\${Name}.psd1 -RootModule .\${Name}.psm1 -Description "A Super Test Module" -Company $Company -Author $Author
64+
New-ModuleManifest $ModulePath/${Name}.psd1 -RootModule ./${Name}.psm1 -Description "A Super Test Module" -Company $Company -Author $Author
6565

6666
# New-ModuleManifest sets things even when we don't want it to:
6767
if(!$Author) {
68-
Set-Content $ModulePath\${Name}.psd1 ((Get-Content $ModulePath\${Name}.psd1) -Replace "^(Author.*)$", '#$1')
68+
Set-Content $ModulePath/${Name}.psd1 ((Get-Content $ModulePath/${Name}.psd1) -Replace "^(Author.*)$", '#$1')
6969
}
7070
if(!$Company) {
71-
Set-Content $ModulePath\${Name}.psd1 ((Get-Content $ModulePath\${Name}.psd1) -Replace "^(Company.*)$", '#$1')
71+
Set-Content $ModulePath/${Name}.psd1 ((Get-Content $ModulePath/${Name}.psd1) -Replace "^(Company.*)$", '#$1')
7272
}
7373

74-
Import-Module $ModulePath\${Name}.psd1
74+
Import-Module $ModulePath/${Name}.psd1
7575
}
7676

7777
When "the module's (\w+) path should (\w+) (.+)$" {
@@ -81,7 +81,18 @@ When "the module's (\w+) path should (\w+) (.+)$" {
8181

8282
$LocalStoragePath = GetStoragePath -Scope $Scope
8383
foreach($PathAssertion in $Path) {
84-
$LocalStoragePath | Should $Comparator $PathAssertion
84+
$LocalStoragePath -replace "\\", "/" | Should $Comparator $PathAssertion
85+
}
86+
}
87+
88+
Then "the script's (\w+) path should (\w+) (.+)$" {
89+
param($Scope, $Comparator, $Path)
90+
91+
[string[]]$Path = $Path -split "\s*and\s*" | % { $_.Trim("['`"]") }
92+
93+
$LocalStoragePath = iex "TestDrive:/${ScriptName}.ps1"
94+
foreach ($PathAssertion in $Path) {
95+
$LocalStoragePath -replace "\\","/" | Should $Comparator $PathAssertion
8596
}
8697
}
8798

@@ -91,43 +102,31 @@ When "the resulting path should (\w+) (.+)$" {
91102
[string[]]$Path = $Path -split "\s*and\s*" | %{ $_.Trim("['`"]") }
92103

93104
foreach($PathAssertion in $Path) {
94-
$folder | Should $Comparator $PathAssertion
105+
$folder -replace "\\", "/" | Should $Comparator $PathAssertion
95106
}
96107
}
97108

98109
Given "a script with the name '(.+)' that calls Get-StoragePath with no parameters" {
99110
param($name)
100-
Set-Content "TestDrive:\${name}.ps1" "Get-StoragePath"
111+
Set-Content "TestDrive:/${name}.ps1" "Get-StoragePath"
101112
$ScriptName = $Name
102113
}
114+
103115
Given "a script with the name '(?<File>.+)' that calls Get-StoragePath (?:-Name (?<Name>\w*) ?|-Author (?<Author>\w*) ?){2}" {
104116
param($File, $Name, $Author)
105-
Set-Content "TestDrive:\${File}.ps1" "Get-StoragePath -Name $Name -Author $Author"
117+
Set-Content "TestDrive:/${File}.ps1" "Get-StoragePath -Name $Name -Author $Author"
106118
$ScriptName = $File
107119
}
108120

109121
Then "the script should throw an exception$" {
110-
{ $LocalStoragePath = iex "TestDrive:\${ScriptName}.ps1" } | Should throw
111-
}
112-
113-
114-
Then "the script's (\w+) path should (\w+) (.+)$" {
115-
param($Scope, $Comparator, $Path)
116-
117-
[string[]]$Path = $Path -split "\s*and\s*" | %{ $_.Trim("['`"]") }
118-
119-
$LocalStoragePath = iex "TestDrive:\${ScriptName}.ps1"
120-
foreach($PathAssertion in $Path) {
121-
$LocalStoragePath | Should $Comparator $PathAssertion
122-
}
122+
{ $LocalStoragePath = iex "TestDrive:/${ScriptName}.ps1" } | Should throw
123123
}
124124

125125
When "the module's storage path should end with a version number if one is passed in" {
126-
GetStoragePath -Version "2.0" | Should Match "\\2.0$"
127-
GetStoragePath -Version "4.0" | Should Match "\\4.0$"
126+
(GetStoragePath -Version "2.0") -replace "\\", "/" | Should Match "/2.0$"
127+
(GetStoragePath -Version "4.0") -replace "\\", "/" | Should Match "/4.0$"
128128
}
129129

130-
131130
When "a settings hashtable" {
132131
param($hashtable)
133132
$Settings = iex "[ordered]$hashtable"
@@ -156,7 +155,7 @@ When "a (?:settings file|module manifest) named (\S+)(?:(?: in the (?<Scope>\S+)
156155
} elseif(Test-Path "$ModulePath") {
157156
$folder = $ModulePath
158157
} else {
159-
$folder = "TestDrive:\"
158+
$folder = "TestDrive:/"
160159
}
161160
$SettingsFile = Join-Path $folder $fileName
162161

@@ -269,7 +268,7 @@ When "we convert the settings to metadata" {
269268
When "we export to a settings file named (.*)" {
270269
param($fileName)
271270
if(!$ModulePath -or !(Test-Path $ModulePath)) {
272-
$ModulePath = "TestDrive:\"
271+
$ModulePath = "TestDrive:/"
273272
}
274273
$SettingsFile = Join-Path $ModulePath $fileName
275274
$File = $Settings | Export-Metadata ${SettingsFile} -Passthru
@@ -331,7 +330,7 @@ When "the settings file should (\w+)\s*(.*)?" {
331330
Given "the settings file does not exist" {
332331
#
333332
if(!$ModulePath -or !(Test-Path $ModulePath)) {
334-
$ModulePath = "TestDrive:\"
333+
$ModulePath = "TestDrive:/"
335334
}
336335
if(!${SettingsFile}) {
337336
$SettingsFile = Join-Path $ModulePath "NoSuchFile.psd1"
@@ -556,7 +555,7 @@ Then "a settings file named (\S+) should exist(?:(?: in the (?<Scope>\S+) folder
556555
} elseif(Test-Path "${ModulePath}") {
557556
$folder = $ModulePath
558557
} else {
559-
$folder = "TestDrive:\"
558+
$folder = "TestDrive:/"
560559
}
561560
$SettingsFile = Join-Path $folder $fileName
562561
$SettingsFile | Should Exist

Specs/Configuration.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: Module Configuration
66
Background:
77
Given the configuration module is imported with testing paths:
88
| Enterprise | User | Machine |
9-
| TestDrive:\EnterprisePath | TestDrive:\UserPath | TestDrive:\MachinePath |
9+
| TestDrive:/EnterprisePath | TestDrive:/UserPath | TestDrive:/MachinePath |
1010

1111
@Modules @Import
1212
Scenario: Loading Default Settings

0 commit comments

Comments
 (0)