From 6c0778229cb3bc2c67f6ad9e4f34fc750426bdc8 Mon Sep 17 00:00:00 2001 From: Noah Sherwin Date: Sat, 21 Dec 2024 21:52:22 -0800 Subject: [PATCH] test(scoop-status): add minimal test suite Only one function is tested and only one of its results is tested. --- test/Scoop-Status.Tests.ps1 | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/Scoop-Status.Tests.ps1 diff --git a/test/Scoop-Status.Tests.ps1 b/test/Scoop-Status.Tests.ps1 new file mode 100644 index 0000000000..aebfa9325f --- /dev/null +++ b/test/Scoop-Status.Tests.ps1 @@ -0,0 +1,61 @@ +# copied from scoop-status.ps1 and modified +BeforeAll { + . "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest' 'parse_json' "install_info" + . "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' + . "$PSScriptRoot\..\lib\core.ps1" # 'versiondir' + Import-Module "$PSScriptRoot\..\lib\core.ps1" -Function 'versiondir' + + # check if scoop needs updating + $currentdir = versiondir 'scoop' 'current' + $needs_update = $false + $bucket_needs_update = $false + $script:network_failure = $false + $no_remotes = $args[0] -eq '-l' -or $args[0] -eq '--local' + if (!(Get-Command git -ErrorAction SilentlyContinue)) { $no_remotes = $true } + $list = @() + if (!(Get-FormatData ScoopStatus)) { + Update-FormatData "$PSScriptRoot\..\supporting\formats\ScoopTypes.Format.ps1xml" + } +} + +# script-level content +# todo +Describe -Skip 'Show status and check for new app versions' -Tag 'Scoop' { + # scoop-status.ps1 is not structured in a way that makes this easy to test + # todo: refactor scoop-status.ps1's loop bodies to functions for easier testing + It 'throws when Global or User appdir is empty or does not exist' -Skip { + + } +} + +Describe 'Test-UpdateStatus' -Tag 'Scoop' { + BeforeAll { + Import-Module "$PSScriptRoot/../libexec/scoop-status.ps1" -Function 'Test-UpdateStatus' + } + # todo + It -Skip 'should return $true if $commits is falsy' { + + } + # todo + It -Skip 'should return $false if $commits is truthy' { + + } + It 'should return $true if "$repopath\.git`" does not exist' { + function makeTmpDir { + [OutputType([System.IO.DirectoryInfo])] + Param () + + [string] $tmpDirPath = Join-Path $env:TEMP $(New-Guid) + + while (Test-Path $tmpDirPath) { + $tmpDirPath = Join-Path $env:TEMP $(New-Guid) + } + + [System.IO.DirectoryInfo] $TmpDirInfo = New-Item $tmpDirPath -ItemType Directory + return $TmpDirInfo + + } + [System.IO.DirectoryInfo] $emptyDir = makeTmpDir + Test-UpdateStatus $emptyDir.FullName | Should -Be $true + } +}