Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected override void BeginProcessing()
// If they didn't specify -Append, empty the file
if (!_shouldAppend)
{
System.IO.File.WriteAllText(effectiveFilePath, string.Empty);
System.IO.File.WriteAllText(effectiveFilePath, string.Empty, Utils.utf8NoBom);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
}
## function ends here

$defaultEncoding = [System.Text.UTF8Encoding]::new($true)
function GetFileEncoding {
param (
[string] $filePath
)

$reader = [System.IO.StreamReader]::new($filePath, $defaultEncoding, $true)
$reader.Read() | Out-Null
return $reader.CurrentEncoding.BodyName
}

$transcriptFilePath = Join-Path $TestDrive "transcriptdata.txt"
Remove-Item $transcriptFilePath -Force -ErrorAction SilentlyContinue
}
Expand Down Expand Up @@ -129,6 +140,31 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
# Nothing should have been returned by the FileSystemWatcher
Receive-Job $job | Should -Be $null
}
It "Should keep the existing file's encoding if the 'Append' parameter is used"{
"Text" | Out-File -Encoding unicode $transcriptFilePath

Start-Transcript -Append -Path $transcriptFilePath
Get-Date | Out-Null
Stop-Transcript

GetFileEncoding $transcriptFilePath | Should -BeExactly 'utf-16'
}
It "Should default to utf8 with 'Append' parameter and file doesn't exist"{
Start-Transcript -Append -Path $transcriptFilePath
Get-Date | Out-Null
Stop-Transcript

GetFileEncoding $transcriptFilePath | Should -BeExactly 'utf-8'
}
It "Should create a new utf8 encoded file if no 'Append' parameter is set regardless of existing file's encoding"{
"Text" | Out-File -Encoding unicode $transcriptFilePath

Start-Transcript -Path $transcriptFilePath
Get-Date | Out-Null
Stop-Transcript

GetFileEncoding $transcriptFilePath | Should -BeExactly 'utf-8'
}
It "Transcription should remain active if other runspace in the host get closed" {
try {
$ps = [powershell]::Create()
Expand Down