Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@altrive
Created March 6, 2018 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altrive/ec0f0f3107fc1a3ead5efea39072e125 to your computer and use it in GitHub Desktop.
Save altrive/ec0f0f3107fc1a3ead5efea39072e125 to your computer and use it in GitHub Desktop.
Import-Module Pester -MinimumVersion 4.0
Describe "テスト失敗時のスタックトレース表示確認"{
Context "通常実行"{
It "テスト01(日本語カルチャ)"{
# UIロケールが日本語となっていることを確認
[System.Threading.Thread]::CurrentThread.CurrentUICulture | Should -Be ([cultureInfo]::GetCultureInfo('ja-jp'))
# テスト失敗時の表示確認
$true | Should -Be $false
}
}
Context "InvariantCultureに設定を一時変更して実行"{
BeforeAll {
# [DebuggerStrings]::Culture にInvariantCultureに設定(要リフレクション)
$private:type = [Type]::GetType("DebuggerStrings, System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
$type.GetProperty('Culture', [Reflection.BindingFlags]::Static -bor [Reflection.BindingFlags]::NonPublic).SetValue($null, [cultureinfo]::InvariantCulture)
}
AfterAll {
# テストが終わったら元の設定(CurrentUICulture)に戻す
$private:type = [Type]::GetType("DebuggerStrings, System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
$culture = $type.GetProperty('Culture', [Reflection.BindingFlags]::Static -bor [Reflection.BindingFlags]::NonPublic).SetValue($null, [cultureinfo]::CurrentUICulture)
}
IT "テスト02(InvariantCulture)"{
# テスト失敗時の表示確認
$true | Should -Be $false
}
}
}
# テストコンテキスト外に影響が出ていないことを追加で確認
Write-Error "Test" -ErrorAction SilentlyContinue
$Error[0].ScriptStackTrace.ToString() | Should -Match "行"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment