File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,13 +4,24 @@ if (-not (Get-Command Compare-Version -ErrorAction Ignore)) {
44 . " $PSScriptRoot \versions.ps1"
55}
66
7+ <#
8+ . SYNOPSIS
9+ Get the latest row from a set of Scoop database rows.
10+ . DESCRIPTION
11+ Compares the `version` property of each row semantically and returns the
12+ latest row. Returns `$null` when no rows are provided.
13+ #>
714function Get-LatestScoopDBRow {
815 param (
916 [Parameter (Mandatory )]
1017 [object []]
1118 $Rows
1219 )
1320
21+ if (-not $Rows -or $Rows.Count -eq 0 ) {
22+ return $null
23+ }
24+
1425 $latest = $Rows [0 ]
1526 foreach ($row in ($Rows | Select-Object - Skip 1 )) {
1627 if ((Compare-Version - ReferenceVersion $latest.version - DifferenceVersion $row.version ) -gt 0 ) {
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ Describe 'database version selection' -Tag 'Scoop' {
1515 (Get-LatestScoopDBRow - Rows $rows ).version | Should - Be ' 1.0.31'
1616 }
1717
18+ It ' returns null when no rows are provided' {
19+ Get-LatestScoopDBRow - Rows @ () | Should - Be $null
20+ }
21+
1822 It ' returns the latest semantic version per name and bucket' {
1923 $result = New-Object System.Data.DataTable
2024 [void ]$result.Columns.Add (' name' , [string ])
You can’t perform that action at this time.
0 commit comments