Skip to content

Commit 1fa35ea

Browse files
committed
update tests after pester upgrade
1 parent 258bd6f commit 1fa35ea

3 files changed

Lines changed: 46 additions & 74 deletions

File tree

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ Install-Module PestWatch
2828
# Run all & watch
2929
Invoke-PesterWatcher
3030
31-
# Run a single "Describe" test suite
32-
Invoke-Pester -TestName "Parse-GitStatus"
33-
3431
# Run matching files
3532
Invoke-Pester ./tests/Parse-GitStatus*
3633
@@ -40,7 +37,7 @@ Invoke-Pester -PassThru
4037

4138
Use `Write-Host` to log something inside a test.
4239

43-
[wiki/Should](https://github.com/pester/Pester/wiki/Should)
40+
[Assertions: Should](https://pester.dev/docs/assertions/should-command)
4441

4542

4643

Tests/Parse-GitStatus-WithNumstat.Tests.ps1

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
. $PSScriptRoot\TestBed.ps1
22

3-
$file0 = "TestDrive:\file0"
4-
$file1 = "TestDrive:\file1"
5-
$file2 = "TestDrive:\spacey file2"
6-
73
Describe 'Parse-GitStatus - with Numstat' {
8-
New-Item $file0
9-
New-Item $file1
10-
New-Item $file2
11-
12-
# BeforeEach {
13-
# Push-Location "TestDrive:"
14-
# }
15-
16-
# AfterEach {
17-
# Pop-Location
18-
# }
4+
BeforeAll {
5+
New-Item -Path "TestDrive:\file0" -ItemType File
6+
New-Item -Path "TestDrive:\file1" -ItemType File
7+
New-Item -Path "TestDrive:\spacey file2" -ItemType File
8+
}
199

2010
It '--numstat works for quoted files' {
2111
Mock Invoke-Git {
2212
if (([string]$args).StartsWith("status")) {
23-
" M $file2"
13+
" M `"TestDrive:\spacey file2`""
2414
} else {
2515
# git diff --numstat
26-
"`t5`t3`t$file2"
16+
"`t5`t3`tTestDrive:\spacey file2"
2717
}
2818
}
2919

@@ -37,17 +27,17 @@ Describe 'Parse-GitStatus - with Numstat' {
3727
It 'Adds git diff --numstat to the output' {
3828
Mock Invoke-Git {
3929
if (([string]$args).StartsWith("status")) {
40-
" M $file0"
30+
" M TestDrive:\file0"
4131
} else {
4232
# git diff --numstat
43-
"`t5`t3`t$file0"
33+
"`t5`t3`tTestDrive:\file0"
4434
}
4535
}
4636

4737
$result = Parse-GitStatus $true
4838

4939
$result.Length | Should -Be 1
50-
$result.file | Should -Be $file0
40+
$result.file | Should -Be "TestDrive:\file0"
5141
$result.added | Should -Be 5
5242
$result.deleted | Should -Be 3
5343
}
@@ -56,17 +46,17 @@ Describe 'Parse-GitStatus - with Numstat' {
5646
It 'numstat works for binary files' {
5747
Mock Invoke-Git {
5848
if (([string]$args).StartsWith("status")) {
59-
" M $file0"
49+
" M TestDrive:\file0"
6050
} else {
6151
# git diff --numstat
62-
"`t-`t-`t$file0"
52+
"`t-`t-`tTestDrive:\file0"
6353
}
6454
}
6555

6656
$result = Parse-GitStatus $true
6757

6858
$result.Length | Should -Be 1
69-
$result.file | Should -Be $file0
59+
$result.file | Should -Be "TestDrive:\file0"
7060
$result.added | Should -Be "-"
7161
$result.deleted | Should -Be "-"
7262
}
@@ -77,16 +67,16 @@ Describe 'Parse-GitStatus - with Numstat' {
7767
# Adding -ErrorAction silentlycontinue already made it crash locally
7868
Mock Invoke-Git {
7969
if (([string]$args).StartsWith("status")) {
80-
" M $file0"
70+
" M TestDrive:\file0"
8171
} else {
8272
# git diff --numstat
83-
Write-Error "warning: LF will be replaced by CRLF in $file0."
73+
Write-Error "warning: LF will be replaced by CRLF in TestDrive:\file0."
8474
Write-Error "The file will have its original line endings in your working directory."
8575

86-
# $Host.UI.WriteErrorLine("warning: LF will be replaced by CRLF in $file0.")
76+
# $Host.UI.WriteErrorLine("warning: LF will be replaced by CRLF in TestDrive:\file0.")
8777
# $Host.UI.WriteErrorLine("The file will have its original line endings in your working directory.")
8878

89-
" `t5`t3`t$file0"
79+
" `t5`t3`tTestDrive:\file0"
9080
}
9181
}
9282

Tests/Parse-GitStatus.Tests.ps1

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,111 @@
22

33

44
Describe 'Parse-GitStatus' {
5-
$file0 = "TestDrive:\file0"
6-
$file1 = "TestDrive:\file1"
7-
$file2 = "TestDrive:\spacey file2"
8-
9-
New-Item $file0
10-
New-Item $file1
11-
New-Item $file2
12-
13-
# Setup/Cleanup crashed...
14-
# BeforeEach {
15-
# Push-Location "TestDrive:"
16-
# New-Item $file0
17-
# New-Item $file1
18-
# }
19-
20-
# AfterEach {
21-
# Remove-Item $file0
22-
# Remove-Item $file1
23-
# Pop-Location
24-
# }
5+
BeforeAll {
6+
New-Item "TestDrive:\file0"
7+
New-Item "TestDrive:\file1"
8+
New-Item "TestDrive:\spacey file2"
9+
}
2510

2611
It 'Can parse a modified file rename' {
27-
Mock Invoke-Git { "RM $file0 -> $file2" }
12+
Mock Invoke-Git { "RM TestDrive:\file0 -> TestDrive:\spacey file2" }
2813
$result = Parse-GitStatus
2914

3015
$result.Length | Should -Be 2
31-
$result[0].file | Should -Be "`"$file2`""
16+
$result[0].file | Should -Be "`"TestDrive:\spacey file2`""
3217
$result[0].state | Should -Be "R"
33-
$result[0].oldFile | Should -Be $file0
18+
$result[0].oldFile | Should -Be "TestDrive:\file0"
3419
$result[0].staged | Should -Be $true
3520

36-
$result[1].file | Should -Be "`"$file2`""
21+
$result[1].file | Should -Be "`"TestDrive:\spacey file2`""
3722
$result[1].state | Should -Be "M"
3823
$result[1].oldFile | Should -Be $null
3924
$result[1].staged | Should -Be $false
4025
}
4126

4227
It 'Add quotes around filename with spaces if it is not yet the case' {
43-
Mock Invoke-Git { "?? $file2" }
28+
Mock Invoke-Git { "?? TestDrive:\spacey file2" }
4429
$result = Parse-GitStatus
4530

46-
$result.relativePath | Should -Be "`"$file2`""
47-
$result.file | Should -Be "`"$file2`""
31+
$result.relativePath | Should -Be "`"TestDrive:\spacey file2`""
32+
$result.file | Should -Be "`"TestDrive:\spacey file2`""
4833

49-
$fullPath = "`"$(Get-Location)\$file2`""
34+
$fullPath = "`"$(Get-Location)\TestDrive:\spacey file2`""
5035
$result.fullPath | Should -Be $fullPath
5136
}
5237

5338

5439
It 'Passes extra CLI arguments along to git status' {
5540
Mock Invoke-Git {
5641
[string]$args | Should -BeLike "* -u"
57-
" M $file0"
42+
" M TestDrive:\file0"
5843
}
5944

6045
$result = Parse-GitStatus $false "-u"
6146
}
6247

6348
It 'Parses a single modified file in working directory' {
64-
Mock Invoke-Git { " M $file0" }
49+
Mock Invoke-Git { " M TestDrive:\file0" }
6550
$result = Parse-GitStatus
6651
$result.Length | Should -Be 1
67-
$result.file | Should -Be $file0
52+
$result.file | Should -Be "TestDrive:\file0"
6853
$result.staged | Should -Be $false
6954
$result.state | Should -Be M
7055
}
7156

7257
It 'Parses a single new file in working directory' {
73-
Mock Invoke-Git { "?? $file0" }
58+
Mock Invoke-Git { "?? TestDrive:\file0" }
7459
$result = Parse-GitStatus
7560
$result.Length | Should -Be 1
76-
$result.file | Should -Be $file0
61+
$result.file | Should -Be "TestDrive:\file0"
7762
$result.staged | Should -Be $false
7863
$result.state | Should -Be A
7964
}
8065

8166
It 'Parses a single modified file in staging area' {
82-
Mock Invoke-Git { "M $file0" }
67+
Mock Invoke-Git { "M TestDrive:\file0" }
8368
$result = Parse-GitStatus
8469
$result.Length | Should -Be 1
85-
$result.file | Should -Be $file0
70+
$result.file | Should -Be "TestDrive:\file0"
8671
$result.staged | Should -Be $true
8772
$result.state | Should -Be M
8873
}
8974

9075
It 'Parses a single new file in staging area' {
91-
Mock Invoke-Git { "A $file0" }
76+
Mock Invoke-Git { "A TestDrive:\file0" }
9277
$result = Parse-GitStatus
9378
$result.Length | Should -Be 1
94-
$result.file | Should -Be $file0
79+
$result.file | Should -Be "TestDrive:\file0"
9580
$result.staged | Should -Be $true
9681
$result.state | Should -Be A
9782
}
9883

9984
It 'Parses a single modified file in staging area AND working directory' {
100-
Mock Invoke-Git { "MM $file0" }
85+
Mock Invoke-Git { "MM TestDrive:\file0" }
10186
$result = Parse-GitStatus
10287

10388
$result.Length | Should -Be 2
10489

105-
$result[0].file | Should -Be $file0
90+
$result[0].file | Should -Be "TestDrive:\file0"
10691
$result[0].staged | Should -Be $true
10792
$result[0].state | Should -Be M
10893

109-
$result[1].file | Should -Be $file0
94+
$result[1].file | Should -Be "TestDrive:\file0"
11095
$result[1].staged | Should -Be $false
11196
$result[1].state | Should -Be M
11297
}
11398

11499
It 'Parses multiple files' {
115-
Mock Invoke-Git { "M $file0"," D $file1" }
100+
Mock Invoke-Git { "M TestDrive:\file0"," D TestDrive:\file1" }
116101
$result = Parse-GitStatus
117102

118103
$result.Length | Should -Be 2
119104

120-
$result[0].file | Should -Be $file0
105+
$result[0].file | Should -Be "TestDrive:\file0"
121106
$result[0].staged | Should -Be $true
122107
$result[0].state | Should -Be M
123108

124-
$result[1].file | Should -Be $file1
109+
$result[1].file | Should -Be "TestDrive:\file1"
125110
$result[1].staged | Should -Be $false
126111
$result[1].state | Should -Be D
127112
}

0 commit comments

Comments
 (0)