Files
Scoop/test/Scoop-Decompress.Tests.ps1
Hsiao-nan Cheung ebd8c036fa chore(release): Bump to version 0.5.3 (#6257)
* fix (decompress): `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty (#6092)

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>

* refactor(download): Move download-related functions to 'download.ps1' (#6095)

* fix(download): Fallback to default downloader when aria2 fails (#4292)

* fix(commands): Handling broken aliases (#6141)

* fix(shim): properly check `wslpath`/`cygpath` command first (#6114)

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>

* fix(scoop-bucket): Add missing import for `no_junction` envs (#6181)

Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>

* docs(chglog): Update to 0.5.3 (#6258)

* perf(shim): Update kiennq-shim to v3.1.2 (#6261)

* fix(decompress): Replace deprecated 7ZIPEXTRACT_USE_EXTERNAL config (#6327)

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>

* fix(scoop-uninstall): Fix uninstaller does not gain Global state (#6430)

* global arg

* changelog

* refactor(Get-Manifest): Select actual source for manifest (#6142)

* first step

* Revert "first step"

This reverts commit c5907c3e25.

* refactor(Get-Manifest): Select actual source for installed manifest

* rework sub-commands, `scoop-depends` is NOT working at this stage

* URI manifest

* opt

* deprecated manifest

* source of manifests

* source of manifest pt2

- Mark URI(path/URL/UNC/etc.) query as standalone manifest
- Drop `installed` and `available update` items for [query] and [installed] are different sources.

* remove variable preventing I forget it

* scoop-info: fix source of manifest on bucket

* fix `scoop-depends`

* Fix Standalone and Source detection

* fix global install

* Fix scoop-cat, scoop-home

- Query for remote manifest

* scoop-list: info +deprecated

* manifest: Fix first selected manifest

* gramma..

* Fix 61b3259

* length

* fix(scoop-depends-tests): Mocking `USE_EXTERNAL_7ZIP` as $false (#6431)

* fix(scoop-depends-tests): Mocking `USE_EXTERNAL_7ZIP` as $false to avoding error when it is $true

* CHANGELOG

* feat(autoupdate): GitHub predefined hashes support (#6416)

* feat(autoupdate): predefined hash case for GitHub

- Remove `sha256:` prefix in `format_hash()`
- Add GitHub support in `get_hash_for_app()`

Close #6381

* doc(chglog): GitHub auto hash update

* fix(autoupdate): remove prefix only

* docs(CHANGELOG): Update to 0.5.3 (#6432)

* docs(CHANGELOG): Update to 0.5.3

* 6416

---------

Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Co-authored-by: Olav Rønnestad Birkeland <6450056+o-l-a-v@users.noreply.github.com>
Co-authored-by: kiennq <kien.n.quang@gmail.com>
Co-authored-by: HUMORCE <humorce@outlook.com>
Co-authored-by: Ryan <sitiom@proton.me>
Co-authored-by: Chawye Hsu <su+git@chawyehsu.com>
Co-authored-by: Bassel Rachid <101208715+basselworkforce@users.noreply.github.com>
Co-authored-by: Wordless Echo <wordless@echo.moe>
2025-08-11 00:38:38 +00:00

264 lines
9.1 KiB
PowerShell

BeforeAll {
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\decompress.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\versions.ps1"
}
Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
BeforeAll {
$working_dir = setup_working 'decompress'
function test_extract($extract_fn, $from, $removal) {
$to = (strip_ext $from) -replace '\.tar$', ''
& $extract_fn ($from -replace '/', '\') ($to -replace '/', '\') -Removal:$removal -ExtractDir $args[0]
return $to
}
}
Context 'Decompression test cases should exist' {
BeforeAll {
$testcases = "$working_dir\TestCases.zip"
}
It 'Test cases should exist and hash should match' {
$testcases | Should -Exist
(Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '591072faabd419b77932b7023e5899b4e05c0bf8e6859ad367398e6bfe1eb203'
}
It 'Test cases should be extracted correctly' {
{ Microsoft.PowerShell.Archive\Expand-Archive -Path $testcases -DestinationPath $working_dir } | Should -Not -Throw
}
}
Context '7zip extraction' {
BeforeAll {
if ($env:CI) {
Mock Get-AppFilePath { (Get-Command 7z.exe).Path }
} elseif (!(installed 7zip)) {
scoop install 7zip
}
$test1 = "$working_dir\7ZipTest1.7z"
$test2 = "$working_dir\7ZipTest2.tgz"
$test3 = "$working_dir\7ZipTest3.tar.bz2"
$test4 = "$working_dir\7ZipTest4.tar.gz"
$test5_1 = "$working_dir\7ZipTest5.7z.001"
$test5_2 = "$working_dir\7ZipTest5.7z.002"
$test5_3 = "$working_dir\7ZipTest5.7z.003"
$test6_1 = "$working_dir\7ZipTest6.part01.rar"
$test6_2 = "$working_dir\7ZipTest6.part02.rar"
$test6_3 = "$working_dir\7ZipTest6.part03.rar"
$test7 = "$working_dir\NSISTest.exe"
}
AfterEach {
Remove-Item -Path $to -Recurse -Force
}
It 'extract normal compressed file' {
$to = test_extract 'Expand-7zipArchive' $test1
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 4
}
It 'extract "extract_dir" correctly' {
$to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp'
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract "extract_dir" with spaces correctly' {
$to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp 2'
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract "extract_dir" with nested folder with same name' {
$to = test_extract 'Expand-7zipArchive' $test1 $false 'keep\sub'
$to | Should -Exist
"$to\keep\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
(Get-ChildItem "$to\keep").Count | Should -Be 1
}
It 'extract nested compressed file' {
# file ext: tgz
$to = test_extract 'Expand-7zipArchive' $test2
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
# file ext: tar.bz2
$to = test_extract 'Expand-7zipArchive' $test3
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract nested compressed file with different inner name' {
$to = test_extract 'Expand-7zipArchive' $test4
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract splited 7z archives (.001, .002, ...)' {
$to = test_extract 'Expand-7zipArchive' $test5_1
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract splited RAR archives (.part01.rar, .part02.rar, ...)' {
$to = test_extract 'Expand-7zipArchive' $test6_1
$to | Should -Exist
"$to\dummy" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'extract NSIS installer' {
$to = test_extract 'Expand-7zipArchive' $test7
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'self-extract NSIS installer' {
$to = "$working_dir\NSIS Test"
$null = Invoke-ExternalCommand -FilePath $test7 -ArgumentList @('/S', '/NCRC', "/D=$to")
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'works with "-Removal" switch ($removal param)' {
$test1 | Should -Exist
$to = test_extract 'Expand-7zipArchive' $test1 $true
$to | Should -Exist
$test1 | Should -Not -Exist
$test5_1 | Should -Exist
$test5_2 | Should -Exist
$test5_3 | Should -Exist
$to = test_extract 'Expand-7zipArchive' $test5_1 $true
$to | Should -Exist
$test5_1 | Should -Not -Exist
$test5_2 | Should -Not -Exist
$test5_3 | Should -Not -Exist
$test6_1 | Should -Exist
$test6_2 | Should -Exist
$test6_3 | Should -Exist
$to = test_extract 'Expand-7zipArchive' $test6_1 $true
$to | Should -Exist
$test6_1 | Should -Not -Exist
$test6_2 | Should -Not -Exist
$test6_3 | Should -Not -Exist
}
}
Context 'msi extraction' {
BeforeAll {
if ($env:CI) {
Mock Get-AppFilePath { $env:SCOOP_LESSMSI_PATH }
} elseif (!(installed lessmsi)) {
scoop install lessmsi
}
Copy-Item "$working_dir\MSITest.msi" "$working_dir\MSI Test.msi"
$test1 = "$working_dir\MSITest.msi"
$test2 = "$working_dir\MSI Test.msi"
$test3 = "$working_dir\MSITestNull.msi"
}
It 'extract normal MSI file using msiexec' {
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 normal MSI file with whitespace in path using msiexec' {
Mock get_config { $false }
$to = test_extract 'Expand-MsiArchive' $test2
$to | Should -Exist
"$to\MSITest\empty" | Should -Exist
(Get-ChildItem "$to\MSITest").Count | Should -Be 1
}
It 'extract normal MSI file using lessmsi' {
Mock get_config { $true }
$to = test_extract 'Expand-MsiArchive' $test1
$to | Should -Exist
}
It 'extract normal MSI file with whitespace in path using lessmsi' {
Mock get_config { $true }
$to = test_extract 'Expand-MsiArchive' $test2
$to | Should -Exist
}
It 'extract empty MSI file using lessmsi' {
Mock get_config { $true }
$to = test_extract 'Expand-MsiArchive' $test3
$to | Should -Exist
}
It 'works with "-Removal" switch ($removal param)' {
Mock get_config { $false }
$test1 | Should -Exist
test_extract 'Expand-MsiArchive' $test1 $true
$test1 | Should -Not -Exist
}
}
Context 'inno extraction' {
BeforeAll {
if ($env:CI) {
Mock Get-AppFilePath { $env:SCOOP_INNOUNP_PATH }
} elseif (!(installed innounp)) {
scoop install innounp
}
$test = "$working_dir\InnoTest.exe"
}
It 'extract Inno Setup file' {
$to = test_extract 'Expand-InnoArchive' $test
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'works with "-Removal" switch ($removal param)' {
$test | Should -Exist
test_extract 'Expand-InnoArchive' $test $true
$test | Should -Not -Exist
}
}
Context 'zip extraction' {
BeforeAll {
$test = "$working_dir\ZipTest.zip"
}
It 'extract compressed file' {
$to = test_extract 'Expand-ZipArchive' $test
$to | Should -Exist
"$to\empty" | Should -Exist
(Get-ChildItem $to).Count | Should -Be 1
}
It 'works with "-Removal" switch ($removal param)' {
$test | Should -Exist
test_extract 'Expand-ZipArchive' $test $true
$test | Should -Not -Exist
}
}
}