Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(versions): Refactor compare_versions -> Compare-Version #3333

Merged
merged 1 commit into from
Jul 31, 2019

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented Apr 18, 2019

fix #3329, fix #2981, fix #2720, fix ScoopInstaller/Extras#2106

Now force updating to manifest's version, despite installed version is greater or less than it.

@niheaven niheaven changed the base branch from master to develop April 25, 2019 09:53
@Ash258 Ash258 mentioned this pull request Apr 26, 2019
@r15ch13
Copy link
Member

r15ch13 commented May 6, 2019

More tests:

describe "versions" -Tag 'Scoop' {
    it 'compares versions with integer-string mismatch' {
        compare_versions '1.8.9' '1.8.5-1' | Should -Be 1
    }

    it 'handles plain string version comparison to int version' {
        compare_versions 'latest' '20150405' | Should -Be 1
    }

    it 'handles dashed version components' {
        compare_versions '7.0.4-9' '7.0.4-10' | Should -Be -1
        compare_versions '7.0.4' '7.0.4-9' | Should -Be -1
        compare_versions '7.0.4-9' '7.0.4-10' | Should -Be -1
    }

    it 'handle example comparisons' {
        compare_versions '1' '1.1' | Should -Be -1
        compare_versions '1.0' '1.1' | Should -Be -1
        compare_versions '1.1' '1.0' | Should -Be 1
        compare_versions '1.1' '1' | Should -Be 1
        compare_versions '1.1.1_8' '1.1.1' | Should -Be 1
        compare_versions '1.1.1b' '1.1.1a' | Should -Be 1
        compare_versions '1.1.1a' '1.1.1b' | Should -Be -1
        compare_versions '2019-01-01' '2019-01-02' | Should -Be -1
        compare_versions '2019-01-02' '2019-01-01' | Should -Be 1
        compare_versions '2018-01-01' '2019-01-01' | Should -Be -1
        compare_versions '2019-01-01' '2018-01-01' | Should -Be 1
    }

    it 'handles comparsion against en empty string' {
        compare_versions '7.0.4-9' '' | Should -Be 1
    }

    it 'handles equal versions' {
        compare_versions '12.0' '12.0' | Should -Be 0
        compare_versions '7.0.4-9' '7.0.4-9' | Should -Be 0
    }
}

By checking if $a and $b are equal at the top of compare_versions we can skip the comparison stuff.

    if($a -eq $b) {
        return 0
    }

@r15ch13
Copy link
Member

r15ch13 commented May 7, 2019

Related issue: ScoopInstaller/Extras#2106

Maybe we could remove the version comparison entirely like @se35710 mentioned.
If the installed version isn't the same as the from the Manifest then it's outdated.

Comparing versions that don't follow a schema like semver.org is pretty much useless anyway. But there are more normal versions then odd ones. See below (includes Main/Extras/Versions and outdated Java/PHP/NerdFonts buckets):

Normal version numbers:

X:\~projects\~powershell
λ (Get-ChildItem *\bucket\*.json -Recurse | % { (Get-Content $_ | ConvertFrom-Json).version } | ? { $_ -match "^[\d.]+$" }).Count
1181

Odd versions with other symbols then 0-9 and .

X:\~projects\~powershell
λ (Get-ChildItem *\bucket\*.json -Recurse | % { (Get-Content $_ | ConvertFrom-Json).version } | ? { $_ -notmatch "^[\d.]+$" }).Count
224

@niheaven niheaven changed the title versions.ps1: Fix version and compare_versions [WIP] versions.ps1: Refactor compare_versions -> Compare-Version May 8, 2019
@niheaven niheaven force-pushed the fix-versions branch 3 times, most recently from 30e88d2 to b82b884 Compare May 17, 2019 17:04
@niheaven niheaven changed the title [WIP] versions.ps1: Refactor compare_versions -> Compare-Version fix(versions): Refactor compare_versions -> Compare-Version May 20, 2019
@niheaven
Copy link
Member Author

@r15ch13 Please consider merge this PR, mupdf update from 1.16.0-rc2 to 1.16.0 but scoop cannot update it excepts with -f...

@r15ch13 r15ch13 merged commit 1508d2a into ScoopInstaller:develop Jul 31, 2019
@niheaven niheaven deleted the fix-versions branch August 1, 2019 08:50
niheaven added a commit to niheaven/scoop that referenced this pull request Aug 1, 2019
r15ch13 pushed a commit that referenced this pull request Aug 2, 2019
* fix(versions): Hotfix for #3333
@xfournet
Copy link

xfournet commented Aug 27, 2019

Could you add the following test ? (see shovel-org/Windows-JetBrains-Bucket#11)

    it 'handles unbalanced versions' {
        Compare-Version '2019.2.1-192.6262.58' '2019.2-192.5728.98' | Should -Be -1
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants