Skip to content

Commit 3f1790b

Browse files
committed
Added Get-BuildConfiguration cmldet
1 parent e9cad95 commit 3f1790b

File tree

9 files changed

+53
-1
lines changed

9 files changed

+53
-1
lines changed

DLLInfo/DLLInfo.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Foreach ($import in @($Public + $Private)) {
1010
catch {
1111
Write-Error -Message "Failed to import function $($import.fullname): $_"
1212
}
13-
}
13+
}
14+
Export-ModuleMember -Function $Public.Basename
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function Get-BuildConfiguration {
2+
[cmdletbinding()]
3+
param (
4+
[string]$dllPath
5+
)
6+
$dll = [System.Reflection.Assembly]::LoadFile($dllPath)
7+
$type = [System.Type]::GetType("System.Diagnostics.DebuggableAttribute")
8+
$debugAttribute = $dll.GetCustomAttributes($type, $false)
9+
if ($debugAttribute.IsJITTrackingEnabled) {
10+
"Debug"
11+
}
12+
else {
13+
"Release"
14+
}
15+
}

Tests/DLLInfo.Tests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
if (-not $PSScriptRoot) {
2+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
3+
}
4+
Import-Module -Name Pester -Force
5+
Import-Module .\DLLInfo\DLLInfo.psm1 -Force
6+
7+
Describe 'Get-BuildConfiguration' {
8+
Context "Check test DLLs - x64" {
9+
It "Given valid -Assembly '<Assembly>', it returns '<Expected>'" -TestCases @(
10+
@{ Assembly = "$PSScriptRoot\bin\Debug\AssemblyInfoTest.dll"; Expected = 'Debug' }
11+
@{ Assembly = "$PSScriptRoot\bin\Release\AssemblyInfoTest.dll"; Expected = 'Release' }
12+
@{ Assembly = "$PSScriptRoot\bin\x64\Debug\AssemblyInfoTest.dll"; Expected = 'Debug' }
13+
@{ Assembly = "$PSScriptRoot\bin\x64\Release\AssemblyInfoTest.dll"; Expected = 'Release' }
14+
) {
15+
param ($Assembly, $Expected)
16+
Get-BuildConfiguration $Assembly | Should -Be $Expected
17+
}
18+
}
19+
20+
Context "Check test DLLs - x86" {
21+
It "Given valid -Assembly '<Assembly>', it returns '<Expected>'" -TestCases @(
22+
@{ Assembly = "$PSScriptRoot\bin\x86\Debug\AssemblyInfoTest.dll"; Expected = 'Debug' }
23+
@{ Assembly = "$PSScriptRoot\bin\x86\Release\AssemblyInfoTest.dll"; Expected = 'Release' }
24+
) {
25+
param ($Assembly, $Expected)
26+
$RunAs32Bit = {
27+
param($Assembly)
28+
Import-Module .\DLLInfo\DLLInfo.psm1 -Force
29+
Get-BuildConfiguration $Assembly
30+
}
31+
32+
$Job = Start-Job $RunAs32Bit -RunAs32 -Arg $Assembly
33+
$Job | Wait-Job | Receive-Job | Should -Be $Expected
34+
}
35+
}
36+
}
4 KB
Binary file not shown.
4 KB
Binary file not shown.
3.5 KB
Binary file not shown.
3.5 KB
Binary file not shown.
4 KB
Binary file not shown.
4 KB
Binary file not shown.

0 commit comments

Comments
 (0)