diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index 7313d4c9ac..a96ec5e015 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -1,123 +1,208 @@ -function requires_7zip($manifest, $architecture) { - foreach($dlurl in @(url $manifest $architecture)) { - if(file_requires_7zip $dlurl) { return $true } +function Test-7ZipRequirement { + [CmdletBinding(DefaultParameterSetName = "URL")] + [OutputType([Boolean])] + param( + [Parameter(Mandatory = $true, ParameterSetName = "URL")] + [String[]] + $URL, + [Parameter(Mandatory = $true, ParameterSetName = "File")] + [String] + $File + ) + if ($URL) { + if (get_config 7ZIPEXTRACT_USE_EXTERNAL) { + return $false + } else { + return ($URL | Where-Object { Test-7ZipRequirement -File $_ }).Count -gt 0 + } + } else { + return $File -match '\.((gz)|(tar)|(tgz)|(lzma)|(bz)|(bz2)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))$' } } -function requires_lessmsi ($manifest, $architecture) { - $useLessMsi = get_config MSIEXTRACT_USE_LESSMSI - if (!$useLessMsi) { return $false } - - $(url $manifest $architecture | Where-Object { - $_ -match '\.(msi)$' - } | Measure-Object | Select-Object -exp count) -gt 0 -} - -function file_requires_7zip($fname) { - $fname -match '\.((gz)|(tar)|(tgz)|(lzma)|(bz)|(bz2)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))$' -} - -function extract_7zip($path, $to, $recurse) { - $output = 7z x "$path" -o"$to" -y - if($lastexitcode -ne 0) { abort "Exit code was $lastexitcode." } - - # check for tar - $tar = (split-path $path -leaf) -replace '\.[^\.]*$', '' - if($tar -match '\.tar$') { - if(test-path "$to\$tar") { extract_7zip "$to\$tar" $to $true } +function Test-LessMSIRequirement { + [CmdletBinding()] + [OutputType([Boolean])] + param( + [Parameter(Mandatory = $true)] + [String[]] + $URL + ) + if (get_config MSIEXTRACT_USE_LESSMSI) { + return ($URL | Where-Object { $_ -match '\.msi$' }).Count -gt 0 + } else { + return $false } - - if($recurse) { Remove-Item $path } # clean up intermediate files -} - -function extract_msi($path, $to) { - $logfile = "$(split-path $path)\msi.log" - $ok = run 'msiexec' @('/a', "`"$path`"", '/qn', "TARGETDIR=`"$to`"", "/lwe `"$logfile`"") - if(!$ok) { abort "Failed to extract files from $path.`nLog file:`n $(friendly_path $logfile)" } - if(test-path $logfile) { Remove-Item $logfile } } -function lessmsi_config ($extract_dir) { - $extract_fn = 'extract_lessmsi' - if ($extract_dir) { - $extract_dir = join-path SourceDir $extract_dir +function Expand-7ZipArchive { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [String] + $Path, + [Parameter(Position = 1)] + [String] + $DestinationPath = (Split-Path $Path), + [Switch] + $Removal + ) + $LogLocation = "$(Split-Path $Path)\7zip.log" + if (get_config 7ZIPEXTRACT_USE_EXTERNAL) { + try { + 7z x "$Path" -o"$DestinationPath" -y | Out-File $LogLocation + } catch [System.Management.Automation.CommandNotFoundException] { + abort "Cannot find external 7Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7Zip manually and try again." + } } else { - $extract_dir = "SourceDir" + &(file_path 7zip 7z.exe) x "$Path" -o"$DestinationPath" -y | Out-File $LogLocation + } + if ($LASTEXITCODE -ne 0) { + abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" + } + if (Test-Path $LogLocation) { + Remove-Item $LogLocation -Force + } + if ((strip_ext $Path) -match '\.tar$' -or $Path -match '\.tgz$') { + # Check for tar + $ArchivedFile = &(file_path 7zip 7z.exe) l "$Path" + if ($LASTEXITCODE -eq 0) { + $TarFile = $ArchivedFile[-3] -replace '.{53}(.*)', '$1' # get inner tar file name + Expand-7ZipArchive "$DestinationPath\$TarFile" $DestinationPath -Removal + } else { + abort "Failed to list files in $Path.`nNot a 7Zip supported archive file." + } + } + if ($Removal) { + # Remove original archive file + Remove-Item $Path -Force } - - $extract_fn, $extract_dir } -function extract_lessmsi($path, $to) { - Invoke-Expression "lessmsi x `"$path`" `"$to\`"" +function Expand-MSIArchive { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [String] + $Path, + [Parameter(Position = 1)] + [String] + $DestinationPath = (Split-Path $Path), + [Switch] + $Removal + ) + $LogLocation = "$(Split-Path $Path)\msi.log" + if (get_config MSIEXTRACT_USE_LESSMSI) { + &(file_path lessmsi lessmsi.exe) x "$Path" "$DestinationPath\" | Out-File $LogLocation + if ($LASTEXITCODE -ne 0) { + abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" + } + if (Test-Path "$DestinationPath\SourceDir") { + movedir "$DestinationPath\SourceDir" "$DestinationPath" | Out-Null + } + } else { + $ok = run 'msiexec' @('/a', "`"$Path`"", '/qn', "TARGETDIR=`"$DestinationPath`"", "/lwe `"$LogLocation`"") + if (!$ok) { + abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" + } + Remove-Item "$DestinationPath\$(fname $Path)" -Force + } + if (Test-Path $LogLocation) { + Remove-Item $LogLocation -Force + } + if ($Removal) { + # Remove original archive file + Remove-Item $Path -Force + } } -function unpack_inno($fname, $manifest, $dir) { - if (!$manifest.innosetup) { return } - - write-host "Unpacking innosetup... " -nonewline - innounp -x -d"$dir\_scoop_unpack" "$dir\$fname" > "$dir\innounp.log" - if ($lastexitcode -ne 0) { - abort "Failed to unpack innosetup file. See $dir\innounp.log" +function Expand-InnoArchive { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [String] + $Path, + [Parameter(Position = 1)] + [String] + $DestinationPath = (Split-Path $Path), + [Switch] + $Removal + ) + $LogLocation = "$(Split-Path $Path)\innounp.log" + &(file_path innounp innounp.exe) -x -d"$DestinationPath" -c'{app}' "$Path" -y | Out-File $LogLocation + if ($LASTEXITCODE -ne 0) { + abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" + } + if (Test-Path $LogLocation) { + Remove-Item $LogLocation -Force + } + if ($Removal) { + # Remove original archive file + Remove-Item $Path -Force } - - Get-ChildItem "$dir\_scoop_unpack\{app}" -r | Move-Item -dest "$dir" -force - - Remove-Item -r -force "$dir\_scoop_unpack" - - Remove-Item "$dir\$fname" - Write-Host "done." -f Green } -function extract_zip($path, $to) { - if (!(test-path $path)) { abort "can't find $path to unzip"} - try { add-type -assembly "System.IO.Compression.FileSystem" -ea stop } - catch { unzip_old $path $to; return } # for .net earlier than 4.5 - $retries = 0 - while ($retries -le 10) { - if ($retries -eq 10) { +function Expand-ZipArchive { + [CmdletBinding()] + param( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [String] + $Path, + [Parameter(Position = 1)] + [String] + $DestinationPath = (Split-Path $Path), + [Switch] + $Removal + ) + # All methods to unzip the file require .NET4.5+ + if ($PSVersionTable.PSVersion.Major -lt 5) { + Add-Type -AssemblyName System.IO.Compression.FileSystem + try { + [System.IO.Compression.ZipFile]::ExtractToDirectory($Path, $DestinationPath) + } catch [System.IO.PathTooLongException] { + # try to fall back to 7zip if path is too long if (7zip_installed) { - extract_7zip $path $to $false + Expand-7ZipArchive $Path $DestinationPath -Removal return } else { - abort "Unzip failed: Windows can't unzip because a process is locking the file.`nRun 'scoop install 7zip' and try again." + abort "Unzip failed: Windows can't handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again." } + } catch [System.IO.IOException] { + if (7zip_installed) { + Expand-7ZipArchive $Path $DestinationPath -Removal + return + } else { + abort "Unzip failed: Windows can't handle the file names in this zip file.`nRun 'scoop install 7zip' and try again." + } + } catch { + abort "Unzip failed: $_" } - if (isFileLocked $path) { - write-host "Waiting for $path to be unlocked by another process... ($retries/10)" - $retries++ - Start-Sleep -s 2 - } else { - break - } + } else { + # Use Expand-Archive to unzip in PowerShell 5+ + Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force } - - try { - [io.compression.zipfile]::extracttodirectory($path, $to) - } catch [system.io.pathtoolongexception] { - # try to fall back to 7zip if path is too long - if (7zip_installed) { - extract_7zip $path $to $false - return - } else { - abort "Unzip failed: Windows can't handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again." - } - } catch [system.io.ioexception] { - if (7zip_installed) { - extract_7zip $path $to $false - return - } else { - abort "Unzip failed: Windows can't handle the file names in this zip file.`nRun 'scoop install 7zip' and try again." - } - } catch { - abort "Unzip failed: $_" + if ($Removal) { + # Remove original archive file + Remove-Item $Path -Force } } -function unzip_old($path, $to) { - # fallback for .net earlier than 4.5 - $shell = (new-object -com shell.application -strict) - $zipfiles = $shell.namespace("$path").items() - $to = ensure $to - $shell.namespace("$to").copyHere($zipfiles, 4) # 4 = don't show progress dialog +function extract_7zip($path, $to, $removal) { + Show-DeprecationMessage $MyInvocation 'Expand-7ZipArchive' + Expand-7ZipArchive -Path $path -DestinationPath $to -Removal:$removal +} + +function extract_msi($path, $to, $removal) { + Show-DeprecationMessage $MyInvocation 'Expand-MSIArchive' + Expand-MSIArchive -Path $path -DestinationPath $to -Removal:$removal +} + +function extract_inno($path, $to, $removal) { + Show-DeprecationMessage $MyInvocation 'Expand-InnoArchive' + Expand-InnoArchive -Path $path -DestinationPath $to -Removal:$removal +} + +function extract_zip($path, $to, $removal) { + Show-DeprecationMessage $MyInvocation 'Expand-ZipArchive' + Expand-ZipArchive -Path $path -DestinationPath $to -Removal:$removal } diff --git a/lib/depends.ps1 b/lib/depends.ps1 index f8cd2bdcbd..e6926abe1a 100644 --- a/lib/depends.ps1 +++ b/lib/depends.ps1 @@ -1,11 +1,11 @@ # resolve dependencies for the supplied apps, and sort into the correct order function install_order($apps, $arch) { $res = @() - foreach($app in $apps) { - foreach($dep in deps $app $arch) { - if($res -notcontains $dep) { $res += $dep} + foreach ($app in $apps) { + foreach ($dep in deps $app $arch) { + if ($res -notcontains $dep) { $res += $dep} } - if($res -notcontains $app) { $res += $app } + if ($res -notcontains $app) { $res += $app } } return $res } @@ -15,7 +15,7 @@ function deps($app, $arch) { $resolved = new-object collections.arraylist dep_resolve $app $arch $resolved @() - if($resolved.count -eq 1) { return @() } # no dependencies + if ($resolved.count -eq 1) { return @() } # no dependencies return $resolved[0..($resolved.count - 2)] } @@ -33,9 +33,9 @@ function dep_resolve($app, $arch, $resolved, $unresolved) { $deps = @(install_deps $manifest $arch) + @(runtime_deps $manifest) | Select-Object -Unique - foreach($dep in $deps) { - if($resolved -notcontains $dep) { - if($unresolved -contains $dep) { + foreach ($dep in $deps) { + if ($resolved -notcontains $dep) { + if ($unresolved -contains $dep) { abort "Circular dependency detected: '$app' -> '$dep'." } dep_resolve $dep $arch $resolved $unresolved @@ -46,17 +46,15 @@ function dep_resolve($app, $arch, $resolved, $unresolved) { } function runtime_deps($manifest) { - if($manifest.depends) { return $manifest.depends } + if ($manifest.depends) { return $manifest.depends } } function install_deps($manifest, $arch) { $deps = @() - if((requires_7zip $manifest $arch) -and !(7zip_installed)) { - $deps += '7zip' - } - if(requires_lessmsi $manifest $arch) { $deps += 'lessmsi' } - if($manifest.innosetup) { $deps += 'innounp' } + if (Test-7ZipRequirement -URL (url $manifest $arch)) { $deps += '7zip' } + if (Test-LessMSIRequirement -URL (url $manifest $arch)) { $deps += 'lessmsi' } + if ($manifest.innosetup) { $deps += 'innounp' } return $deps } diff --git a/lib/install.ps1 b/lib/install.ps1 index dbab39b7b4..69ec146fef 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -41,7 +41,6 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru $persist_dir = persistdir $app $global $fname = dl_urls $app $version $manifest $bucket $architecture $dir $use_cache $check_hash - unpack_inno $fname $manifest $dir pre_install $manifest $architecture run_installer $fname $manifest $architecture $dir $global ensure_install_dir_not_in_path $dir $global @@ -103,7 +102,7 @@ function dl_with_cache($app, $version, $url, $to, $cookies = $null, $use_cache = $cached = fullpath (cache_path $app $version $url) if(!(test-path $cached) -or !$use_cache) { - $null = ensure $cachedir + ensure $cachedir | Out-Null do_dl $url "$cached.download" $cookies Move-Item "$cached.download" $cached -force } else { write-host "Loading $(url_remote_filename $url) from cache"} @@ -532,39 +531,29 @@ function dl_urls($app, $version, $manifest, $bucket, $architecture, $dir, $use_c # work out extraction method, if applicable $extract_fn = $null - if($fname -match '\.zip$') { - $extract_fn = 'extract_zip' + if ($manifest.innosetup) { + $extract_fn = 'Expand-InnoArchive' + } elseif($fname -match '\.zip$') { + $extract_fn = 'Expand-ZipArchive' } elseif($fname -match '\.msi$') { # check manifest doesn't use deprecated install method - $msi = msi $manifest $architecture - if(!$msi) { - $useLessMsi = get_config MSIEXTRACT_USE_LESSMSI - if ($useLessMsi -eq $true) { - $extract_fn, $extract_dir = lessmsi_config $extract_dir - } - else { - $extract_fn = 'extract_msi' - } - } else { + if(msi $manifest $architecture) { warn "MSI install is deprecated. If you maintain this manifest, please refer to the manifest reference docs." + } else { + $extract_fn = 'Expand-MSIArchive' } - } elseif(file_requires_7zip $fname) { # 7zip - if(!(7zip_installed)) { - warn "Aborting. You'll need to run 'scoop uninstall $app' to clean up." - abort "7-zip is required. You can install it with 'scoop install 7zip'." - } - $extract_fn = 'extract_7zip' + } elseif(Test-7ZipRequirement -File $fname) { # 7zip + $extract_fn = 'Expand-7ZipArchive' } if($extract_fn) { Write-Host "Extracting " -NoNewline Write-Host $fname -f Cyan -NoNewline Write-Host " ... " -NoNewline - $null = mkdir "$dir\_tmp" - & $extract_fn "$dir\$fname" "$dir\_tmp" - Remove-Item "$dir\$fname" + ensure "$dir\_tmp" | Out-Null + & $extract_fn "$dir\$fname" "$dir\_tmp" -Removal if ($extract_to) { - $null = mkdir "$dir\$extract_to" -force + ensure "$dir\$extract_to" | Out-Null } # fails if zip contains long paths (e.g. atom.json) #cp "$dir\_tmp\$extract_dir\*" "$dir\$extract_to" -r -force -ea stop @@ -576,7 +565,7 @@ function dl_urls($app, $version, $manifest, $bucket, $architecture, $dir, $use_c abort $(new_issue_msg $app $bucket "extract_dir error") } - if(test-path "$dir\_tmp") { # might have been moved by movedir + if(Test-Path "$dir\_tmp") { # might have been moved by movedir try { Remove-Item -r -force "$dir\_tmp" -ea stop } catch [system.io.pathtoolongexception] { @@ -1173,7 +1162,7 @@ function persist_data($manifest, $original_dir, $persist_dir) { # we don't have persist data in the store, move the source to target, then create link } elseif (Test-Path $source) { # ensure target parent folder exist - $null = ensure (Split-Path -Path $target) + ensure (Split-Path -Path $target) | Out-Null Move-Item $source $target # we don't have neither source nor target data! we need to crate an empty target, # but we can't make a judgement that the data should be a file or directory... diff --git a/test/Scoop-Decompress.Tests.ps1 b/test/Scoop-Decompress.Tests.ps1 index 566258bd8b..d46d03f8f1 100644 --- a/test/Scoop-Decompress.Tests.ps1 +++ b/test/Scoop-Decompress.Tests.ps1 @@ -1,62 +1,152 @@ . "$psscriptroot\Scoop-TestLib.ps1" -. "$psscriptroot\..\lib\core.ps1" . "$psscriptroot\..\lib\decompress.ps1" . "$psscriptroot\..\lib\unix.ps1" +. "$psscriptroot\..\lib\install.ps1" +. "$psscriptroot\..\lib\manifest.ps1" +. "$psscriptroot\..\lib\config.ps1" $isUnix = is_unix -describe "unzip_old" -Tag 'Scoop' { - beforeall { - $working_dir = setup_working "unzip_old" +function install_app_ci($app, $architecture) { + $manifest = manifest $app + $version = $manifest.version + $dir = ensure (versiondir $app $version) + $fname = dl_urls $app $version $manifest $null $architecture $dir + $dir = link_current $dir + success "'$app' ($version) was installed successfully!" +} + +function test_extract($extract_fn, $from, $removal) { + $to = (strip_ext $from) -replace '\.tar$', '' + & $extract_fn ($from -replace '/', '\') ($to -replace '/', '\') -Removal:$removal + return $to +} + +Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { + BeforeAll { + $working_dir = setup_working 'decompress' } - function test-unzip($from) { - $to = strip_ext $from + if (!$isUnix) { + # Expanding Test Cases + $testcases = "$working_dir\TestCases.zip" + $testcases | Should -Exist + compute_hash $testcases 'sha256' | Should -Be '695bb18cafda52644a19afd184b2545e9c48f1a191f7ff1efc26cb034587079c' + Expand-Archive $testcases $working_dir + } + + Context "7zip extraction" { - if(is_unix) { - unzip_old ($from -replace '\\','/') ($to -replace '\\','/') - } else { - unzip_old ($from -replace '/','\') ($to -replace '/','\') + if (!$isUnix) { + install_app_ci 7zip 64bit + $test1 = "$working_dir\7ZipTest1.7z" + $test2 = "$working_dir\7ZipTest2.tgz" + $test3 = "$working_dir\7ZipTest3.tar.bz2" + $test4 = "$working_dir\7ZipTest4.tar.gz" } - $to - } + It "extract normal compressed file" -Skip:$isUnix { + $to = test_extract "Expand-7ZipArchive" $test1 + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 + } - context "zip file size is zero bytes" { - $zerobyte = "$working_dir\zerobyte.zip" - $zerobyte | should -exist + It "extract nested compressed file" -Skip:$isUnix { + # file ext: tgz + $to = test_extract "Expand-7ZipArchive" $test2 + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 - it "unzips file with zero bytes without error" -skip:$isUnix { - # some combination of pester, COM (used within unzip_old), and Win10 causes a bugged return value from test-unzip - # `$to = test-unzip $zerobyte` * RETURN_VAL has a leading space and complains of $null usage when used in PoSH functions - $to = ([string](test-unzip $zerobyte)).trimStart() + # file ext: tar.bz2 + $to = test_extract "Expand-7ZipArchive" $test3 + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 + } - $to | should -not -match '^\s' - $to | should -not -benullorempty + It "extract nested compressed file with different inner name" -Skip:$isUnix { + $to = test_extract "Expand-7ZipArchive" $test4 + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 + } - $to | should -exist + It "works with '-Removal' switch (`$removal param)" -Skip:$isUnix { + $test1 | Should -Exist + test_extract "Expand-7ZipArchive" $test1 $true + $test1 | Should -Not -Exist + } + } + + Context "msi extraction" { + if (!$isUnix) { + install_app_ci lessmsi + $test1 = "$working_dir\MSITest.msi" + $test2 = "$working_dir\MSITestNull.msi" + } - (Get-ChildItem $to).count | should -be 0 + It "extract normal MSI file" -Skip:$isUnix { + mock get_config { $false } + $to = test_extract "Expand-MSIArchive" $test1 + $to | Should -Exist + "$to\MSITest\empty" | Should -Exist + (Get-ChildItem "$to\MSITest").Count | Should -Be 1 + } + + It "extract empty MSI file using lessmsi" -Skip:$isUnix { + mock get_config { $true } + $to = test_extract "Expand-MSIArchive" $test2 + $to | Should -Exist + } + + It "works with '-Removal' switch (`$removal param)" -Skip:$isUnix { + mock get_config { $false } + $test1 | Should -Exist + test_extract "Expand-MSIArchive" $test1 $true + $test1 | Should -Not -Exist } } - context "zip file is small in size" { - $small = "$working_dir\small.zip" - $small | should -exist + Context "inno extraction" { - it "unzips file which is small in size" -skip:$isUnix { - # some combination of pester, COM (used within unzip_old), and Win10 causes a bugged return value from test-unzip - # `$to = test-unzip $small` * RETURN_VAL has a leading space and complains of $null usage when used in PoSH functions - $to = ([string](test-unzip $small)).trimStart() + if (!$isUnix) { + install_app_ci innounp + $test = "$working_dir\InnoTest.exe" + } - $to | should -not -match '^\s' - $to | should -not -benullorempty + It "extract Inno Setup file" -Skip:$isUnix { + $to = test_extract "Expand-InnoArchive" $test + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 + } - $to | should -exist + It "works with '-Removal' switch (`$removal param)" -Skip:$isUnix { + $test | Should -Exist + test_extract "Expand-InnoArchive" $test $true + $test | Should -Not -Exist + } + } + + Context "zip extraction" { + + if (!$isUnix) { + $test = "$working_dir\ZipTest.zip" + } + + It "extract compressed file" -Skip:$isUnix { + $to = test_extract "Expand-ZipArchive" $test + $to | Should -Exist + "$to\empty" | Should -Exist + (Get-ChildItem $to).Count | Should -Be 1 + } - # these don't work for some reason on appveyor - #join-path $to "empty" | should -exist - #(gci $to).count | should -be 1 + It "works with '-Removal' switch (`$removal param)" -Skip:$isUnix { + $test | Should -Exist + test_extract "Expand-ZipArchive" $test $true + $test | Should -Not -Exist } } } diff --git a/test/bin/test.ps1 b/test/bin/test.ps1 index 7413550acf..81e8c10318 100644 --- a/test/bin/test.ps1 +++ b/test/bin/test.ps1 @@ -10,40 +10,46 @@ $resultsXml = "$PSScriptRoot/TestResults.xml" $excludes = @() $splat = @{ - Path = $TestPath - OutputFile = $resultsXml + Path = $TestPath + OutputFile = $resultsXml OutputFormat = 'NUnitXML' - PassThru = $true + PassThru = $true } -if($env:CI -eq $true) { - $commit = if($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT } +if ($env:CI -eq $true) { + $commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT } $commitMessage = "$env:APPVEYOR_REPO_COMMIT_MESSAGE $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED".TrimEnd() - if($commitMessage -match '!linter') { + if ($commitMessage -match '!linter') { Write-Warning "Skipping code linting per commit flag '!linter'" $excludes += 'Linter' } $changed_scripts = (Get-GitChangedFile -Include '*.ps1' -Commit $commit) - if(!$changed_scripts) { + if (!$changed_scripts) { Write-Warning "Skipping tests and code linting for *.ps1 files because they didn't change" $excludes += 'Linter' $excludes += 'Scoop' } - if($commitMessage -match '!manifests') { + $changed_scripts = (Get-GitChangedFile -Include '*decompress.ps1' -Commit $commit) + if (!$changed_scripts) { + Write-Warning "Skipping tests and code linting for decompress.ps1 files because it didn't change" + $excludes += 'Decompress' + } + + if ($commitMessage -match '!manifests') { Write-Warning "Skipping manifest validation per commit flag '!manifests'" $excludes += 'Manifests' } $changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit) - if(!$changed_manifests) { + if (!$changed_manifests) { Write-Warning "Skipping tests and validation for manifest files because they didn't change" $excludes += 'Manifests' } - if($excludes.Length -gt 0) { + if ($excludes.Length -gt 0) { $splat.ExcludeTag = $excludes } } @@ -53,6 +59,6 @@ $result = Invoke-Pester @splat (New-Object Net.WebClient).UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resultsXml) -if($result.FailedCount -gt 0) { +if ($result.FailedCount -gt 0) { exit $result.FailedCount } diff --git a/test/fixtures/decompress/TestCases.zip b/test/fixtures/decompress/TestCases.zip new file mode 100644 index 0000000000..f5a7227088 Binary files /dev/null and b/test/fixtures/decompress/TestCases.zip differ diff --git a/test/fixtures/unzip_old/small.zip b/test/fixtures/unzip_old/small.zip deleted file mode 100644 index 09e3f8bd9a..0000000000 Binary files a/test/fixtures/unzip_old/small.zip and /dev/null differ diff --git a/test/fixtures/unzip_old/zerobyte.zip b/test/fixtures/unzip_old/zerobyte.zip deleted file mode 100644 index e69de29bb2..0000000000