Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Use Set-Content for PowerShell 7 compatibility #209

Merged
merged 1 commit into from
May 5, 2020
Merged
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
2 changes: 1 addition & 1 deletion AU/Public/Update-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Update-Package {
if (Test-Path $Env:ChocolateyInstall\extensions) { cp -recurse -force $Env:ChocolateyInstall\extensions $choco_tmp_path\extensions }

$fun_path = "$choco_tmp_path\helpers\functions\Get-ChocolateyWebFile.ps1"
(gc $fun_path) -replace '^\s+return \$fileFullPath\s*$', ' throw "au_break: $fileFullPath"' | sc $fun_path -ea ignore
(gc $fun_path) -replace '^\s+return \$fileFullPath\s*$', ' throw "au_break: $fileFullPath"' | Set-Content $fun_path -ea ignore
}

"Automatic checksum started" | result
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function create_help() {

$help_dir = "$module_path/en-US"
mkdir -Force $help_dir | Out-Null
gc $PSScriptRoot/README.md | select -Skip 4 | sc "$help_dir/about_${module_name}.help.txt" -Encoding ascii
gc $PSScriptRoot/README.md | select -Skip 4 | Set-Content "$help_dir/about_${module_name}.help.txt" -Encoding ascii
}

function create_manifest() {
Expand Down
16 changes: 8 additions & 8 deletions tests/Update-AUPackages.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
$nu = nuspec_file
$nu.package.metadata.id = $name
rm "$path\*.nuspec"
$nu.OuterXml | sc "$path\$name.nuspec"
$nu.OuterXml | Set-Content "$path\$name.nuspec"
mv "$path\test_package_with_streams.json" "$path\$name.json"

$module_path = Resolve-Path $PSScriptRoot\..\AU
"import-module '$module_path' -Force", (gc $path\update.ps1 -ea ignore) | sc $path\update.ps1
"import-module '$module_path' -Force", (gc $path\update.ps1 -ea ignore) | Set-Content $path\update.ps1
}

$Options = [ordered]@{}
Expand All @@ -35,7 +35,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
It 'should ignore the package that returns "ignore"' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace 'update', "Write-Host 'test ignore'; 'ignore'" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1

$res = updateall -Options $Options -NoPlugins:$false 6>$null

Expand All @@ -47,7 +47,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'text'
Expand Down Expand Up @@ -96,7 +96,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Expand Down Expand Up @@ -146,7 +146,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2' }" | set content
$content -replace '@\{.+1\.2.+\}', "@{ Version = '1.2.4' }" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1

$Options.GitReleases = @{
ApiToken = 'apiToken'
Expand Down Expand Up @@ -179,7 +179,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace '@\{.+1\.3.+\}', "@{ Version = '1.3.2'; ChecksumType32 = 'sha256'; Checksum32 = '$choco_hash'}" | set content
$content -replace 'update', "update -ChecksumFor 32" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1

$res = updateall -Options $Options 6> $null
$res.Count | Should Be $pkg_no
Expand All @@ -189,7 +189,7 @@ Describe 'Update-AUPackages using streams' -Tag updateallstreams {
It 'should limit update time' {
gc $global:au_Root\test_package_with_streams_1\update.ps1 | set content
$content -replace 'update', "sleep 10; update" | set content
$content | sc $global:au_Root\test_package_with_streams_1\update.ps1
$content | Set-Content $global:au_Root\test_package_with_streams_1\update.ps1
$Options.UpdateTimeout = 5

$res = updateall -Options $Options 3>$null 6> $null
Expand Down
20 changes: 10 additions & 10 deletions tests/Update-AUPackages.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Describe 'Update-AUPackages' -Tag updateall {
$nu = nuspec_file
$nu.package.metadata.id = $name
rm "$au_root\$name\*.nuspec"
$nu.OuterXml | sc "$path\$name.nuspec"
$nu.OuterXml | Set-Content "$path\$name.nuspec"

$module_path = Resolve-Path $PSScriptRoot\..\AU
"import-module '$module_path' -Force", (gc $path\update.ps1 -ea ignore) | sc $path\update.ps1
"import-module '$module_path' -Force", (gc $path\update.ps1 -ea ignore) | Set-Content $path\update.ps1
}

$Options = [ordered]@{}
Expand Down Expand Up @@ -79,7 +79,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should ignore the package that returns "ignore"' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace 'update', "Write-Host 'test ignore'; 'ignore'" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$res = updateall -Options $Options -NoPlugins:$false 6>$null

Expand All @@ -90,7 +90,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should repeat and ignore on specific error' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace 'update', "1|Out-File -Append $TestDrive\tmp_test; throw 'test ignore'; update" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$Options.RepeatOn = @('test ignore')
$Options.RepeatCount = 2
Expand All @@ -107,7 +107,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should execute text Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'text'
Expand Down Expand Up @@ -141,7 +141,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should execute markdown Report plugin' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$Options.Report = @{
Type = 'markdown'
Expand Down Expand Up @@ -208,7 +208,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should execute GitReleases plugin per package when there are updates' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$Options.GitReleases = @{
ApiToken = 'apiToken'
Expand Down Expand Up @@ -236,7 +236,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should execute GitReleases plugin per date when there are updates' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3' }" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$Options.GitReleases = @{
ApiToken = 'apiToken'
Expand All @@ -261,7 +261,7 @@ Describe 'Update-AUPackages' -Tag updateall {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace '@\{.+\}', "@{ Version = '1.3'; ChecksumType32 = 'sha256'; Checksum32 = '$choco_hash'}" | set content
$content -replace 'update', "update -ChecksumFor 32" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1

$res = updateall -Options $Options 6> $null
$res.Count | Should Be $pkg_no
Expand All @@ -271,7 +271,7 @@ Describe 'Update-AUPackages' -Tag updateall {
It 'should limit update time' {
gc $global:au_Root\test_package_1\update.ps1 | set content
$content -replace 'update', "sleep 10; update" | set content
$content | sc $global:au_Root\test_package_1\update.ps1
$content | Set-Content $global:au_Root\test_package_1\update.ps1
$Options.UpdateTimeout = 5

$res = updateall -Options $Options 3>$null 6> $null
Expand Down