-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-Files.ps1
52 lines (46 loc) · 1.76 KB
/
Test-Files.ps1
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
[CmdletBinding()]
param(
[String]$FileIdExe,
[String]$Folder,
[String[]]$Ignoreables = @(".gitattributes","LICENSE","README.md","Test-Files.ps1", "*.txt", "*.json", "*.ps1"),
[Switch]$ShowAll
)
Set-Alias -Name fileid -Value (Resolve-Path -Path ($FileIdExe) -ErrorAction Stop)
Write-Verbose -Message ("Using FileId executable: " + (Get-Alias fileid).Definition )
Get-ChildItem -Path $Folder -Exclude $Ignoreables | ForEach-Object {
$ext = $_.Name
$testFolderExt = $_.FullName
$children = Get-ChildItem -Path $testFolderExt -Recurse -File
if ($children.Length -gt 0) {
$children | ForEach-Object {
$r = fileid $_.FullName json | ConvertFrom-Json -ErrorAction Stop -ErrorVariable $convertError
if ($convertError) {
Write-Error ("Error converting JSON from file: " + $_.FullName)
break
}
$actual = $r.extensions.extension
$expected = $_.Extension.Trim('.')
## Handle the case where the expected extension contains a "."
if ($expected.Contains("_")) {
$expected = $expected.Replace("_",".")
}
if ($actual -is [array]) {
if ($actual -notcontains $expected -or $ShowAll) {
New-Object PSObject -Property @{
File = $_.FullName
Expected = $expected
Actual = $actual
}
}
} elseif ($actual -ne $expected -or $ShowAll) {
New-Object PSObject -Property @{
File = $_.FullName
Expected = $expected
Actual = $actual
}
}
}
} else {
Write-Warning -Message ("No files for extension: " + $ext)
}
}